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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/* 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 FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
const LocalizationProvider = createFactory(FluentReact.LocalizationProvider);
const ConnectedAuditProgressOverlayClass = require("resource://devtools/client/accessibility/components/AuditProgressOverlay.js");
const AuditProgressOverlayClass =
ConnectedAuditProgressOverlayClass.WrappedComponent;
const AuditProgressOverlay = createFactory(ConnectedAuditProgressOverlayClass);
function testTextProgressBar(store, expectedLocalizedStringId) {
const wrapper = mount(
Provider(
{ store },
LocalizationProvider({ bundles: [] }, AuditProgressOverlay())
)
);
expect(wrapper.html()).toMatchSnapshot();
const overlay = wrapper.find(AuditProgressOverlayClass);
expect(overlay.children().length).toBe(1);
const localized = overlay.childAt(0);
expect(localized.prop("id")).toBe(expectedLocalizedStringId);
expect(localized.prop("attrs")["aria-valuetext"]).toBe(true);
const overlayText = localized.childAt(0);
expect(overlayText.type()).toBe("span");
expect(overlayText.prop("id")).toBe("audit-progress-container");
expect(overlayText.prop("role")).toBe("progressbar");
}
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 },
LocalizationProvider({ bundles: [] }, 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, "accessibility-progress-initializing");
});
it("render auditing progress", () => {
const store = setupStore({
preloadedState: {
audit: {
auditing: [AUDIT_TYPE.CONTRAST],
progress: { total: 5, percentage: 0 },
},
},
});
const wrapper = mount(
Provider(
{ store },
LocalizationProvider({ bundles: [] }, 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(2);
const localized = overlayContainer.childAt(0);
expect(localized.prop("id")).toBe("accessibility-progress-progressbar");
expect(localized.prop("$nodeCount")).toBe(5);
expect(overlayContainer.childAt(1).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, "accessibility-progress-finishing");
});
});
|