summaryrefslogtreecommitdiffstats
path: root/devtools/client/accessibility/test/node/components/audit-progress-overlay.test.js
blob: 797bbce1a1c12b4dc077756945601c9c27d66c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

const { mount } = require("enzyme");

const {
  createFactory,
} = require("resource://devtools/client/shared/vendor/react.js");
const Provider = createFactory(
  require("resource://devtools/client/shared/vendor/react-redux.js").Provider
);
const {
  setupStore,
} = require("resource://devtools/client/accessibility/test/node/helpers.js");

const {
  accessibility: { AUDIT_TYPE },
} = require("resource://devtools/shared/constants.js");
const {
  AUDIT_PROGRESS,
} = require("resource://devtools/client/accessibility/constants.js");

const ConnectedAuditProgressOverlayClass = require("resource://devtools/client/accessibility/components/AuditProgressOverlay.js");
const AuditProgressOverlayClass =
  ConnectedAuditProgressOverlayClass.WrappedComponent;
const AuditProgressOverlay = createFactory(ConnectedAuditProgressOverlayClass);

function testTextProgressBar(store, expectedText) {
  const wrapper = mount(Provider({ store }, AuditProgressOverlay()));
  expect(wrapper.html()).toMatchSnapshot();

  const overlay = wrapper.find(AuditProgressOverlayClass);
  expect(overlay.children().length).toBe(1);

  const overlayText = overlay.childAt(0);
  expect(overlayText.type()).toBe("span");
  expect(overlayText.prop("id")).toBe("audit-progress-container");
  expect(overlayText.prop("role")).toBe("progressbar");
  expect(overlayText.prop("aria-valuetext")).toBe(expectedText);
  expect(overlayText.text()).toBe(expectedText);
}

function testProgress(wrapper, percentage) {
  const progress = wrapper.find("progress");
  expect(progress.prop("max")).toBe(100);
  expect(progress.prop("value")).toBe(percentage);
  expect(progress.hasClass("audit-progress-progressbar")).toBe(true);
  expect(progress.prop("aria-labelledby")).toBe("audit-progress-container");
}

describe("AuditProgressOverlay component:", () => {
  it("render not auditing", () => {
    const store = setupStore();
    const wrapper = mount(Provider({ store }, AuditProgressOverlay()));
    expect(wrapper.html()).toMatchSnapshot();
    expect(wrapper.isEmptyRender()).toBe(true);
  });

  it("render auditing initializing", () => {
    const store = setupStore({
      preloadedState: { audit: { auditing: [AUDIT_TYPE.CONTRAST] } },
    });

    testTextProgressBar(store, "Initializing…");
  });

  it("render auditing progress", () => {
    const store = setupStore({
      preloadedState: {
        audit: {
          auditing: [AUDIT_TYPE.CONTRAST],
          progress: { total: 5, percentage: 0 },
        },
      },
    });

    const wrapper = mount(Provider({ store }, AuditProgressOverlay()));
    expect(wrapper.html()).toMatchSnapshot();

    const overlay = wrapper.find(AuditProgressOverlayClass);
    expect(overlay.children().length).toBe(1);

    const overlayContainer = overlay.childAt(0);
    expect(overlayContainer.type()).toBe("span");
    expect(overlayContainer.prop("id")).toBe("audit-progress-container");
    expect(overlayContainer.children().length).toBe(1);

    expect(overlayContainer.text()).toBe("Checking 5 nodes");
    expect(overlayContainer.childAt(0).type()).toBe("progress");

    testProgress(wrapper, 0);

    store.dispatch({
      type: AUDIT_PROGRESS,
      progress: { total: 5, percentage: 50 },
    });
    wrapper.update();

    expect(wrapper.html()).toMatchSnapshot();
    testProgress(wrapper, 50);

    store.dispatch({
      type: AUDIT_PROGRESS,
      progress: { total: 5, percentage: 75 },
    });
    wrapper.update();

    expect(wrapper.html()).toMatchSnapshot();
    testProgress(wrapper, 75);
  });

  it("render auditing finishing up", () => {
    const store = setupStore({
      preloadedState: {
        audit: {
          auditing: [AUDIT_TYPE.CONTRAST],
          progress: { total: 5, percentage: 100 },
        },
      },
    });

    testTextProgressBar(store, "Finishing up…");
  });
});