-
Notifications
You must be signed in to change notification settings - Fork 192
/
progress-bar.test.ts
176 lines (146 loc) · 5.91 KB
/
progress-bar.test.ts
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
import '@spectrum-web-components/progress-bar/sp-progress-bar.js';
import { ProgressBar } from '@spectrum-web-components/progress-bar';
import { stub } from 'sinon';
import { testForLitDevWarnings } from '../../../test/testing-helpers.js';
import { createLanguageContext } from '../../../tools/reactive-controllers/test/helpers.js';
describe('ProgressBar', () => {
testForLitDevWarnings(
async () =>
await fixture<ProgressBar>(
html`
<sp-progress-bar label="Loading"></sp-progress-bar>
`
)
);
it('loads default progress-bar accessibly', async () => {
const el = await fixture<ProgressBar>(
html`
<sp-progress-bar label="Loading"></sp-progress-bar>
`
);
await elementUpdated(el);
expect(el).to.not.be.undefined;
await expect(el).to.be.accessible();
});
it('accepts label from `slot`', async () => {
const el = await fixture<ProgressBar>(html`
<sp-progress-bar role="progressbar">
Label From Slot
</sp-progress-bar>
`);
await elementUpdated(el);
expect(el.getAttribute('label')).to.equal('Label From Slot');
});
it('accepts a changing progress', async () => {
const el = await fixture<ProgressBar>(html`
<sp-progress-bar label="Changing value"></sp-progress-bar>
`);
await elementUpdated(el);
expect(el.hasAttribute('aria-valuenow')).to.be.true;
expect(el.getAttribute('aria-valuenow')).to.equal('0');
el.progress = 50;
await elementUpdated(el);
expect(el.hasAttribute('aria-valuenow')).to.be.true;
expect(el.getAttribute('aria-valuenow')).to.equal('50');
el.progress = 100;
await elementUpdated(el);
expect(el.hasAttribute('aria-valuenow')).to.be.true;
expect(el.getAttribute('aria-valuenow')).to.equal('100');
});
it('loads - [indeterminate]', async () => {
const el = await fixture<ProgressBar>(html`
<sp-progress-bar indeterminate label="Loading"></sp-progress-bar>
`);
await elementUpdated(el);
expect(el).to.not.be.undefined;
await expect(el).to.be.accessible();
});
it('accepts user `role`', async () => {
const el = await fixture<ProgressBar>(html`
<sp-progress-bar
role="progressbar"
label="With user role"
></sp-progress-bar>
`);
await elementUpdated(el);
expect(el.getAttribute('role')).to.equal('progressbar');
});
it('returns to indeterminate', async () => {
const el = await fixture<ProgressBar>(html`
<sp-progress-bar
progress="50"
label="Sometimes indeterminate"
></sp-progress-bar>
`);
await elementUpdated(el);
expect(el.hasAttribute('aria-valuenow')).to.be.true;
expect(el.getAttribute('aria-valuenow')).to.equal('50');
el.indeterminate = true;
await elementUpdated(el);
expect(el.hasAttribute('aria-valuenow')).to.be.false;
});
it('warns in Dev Mode when accessible attributes are not leveraged', async () => {
const consoleWarnStub = stub(console, 'warn');
const el = await fixture<ProgressBar>(html`
<sp-progress-bar progress="50"></sp-progress-bar>
`);
await elementUpdated(el);
expect(consoleWarnStub.called).to.be.true;
const spyCall = consoleWarnStub.getCall(0);
expect(
spyCall.args.at(0).includes('accessible'),
'confirm accessibility-centric message'
).to.be.true;
expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({
data: {
localName: 'sp-progress-bar',
type: 'accessibility',
level: 'default',
},
});
consoleWarnStub.restore();
});
it('resolves a language (en-US)', async () => {
const [languageContext] = createLanguageContext('en-US');
const test = await fixture(html`
<div @sp-language-context=${languageContext}>
<sp-progress-bar
label="Changing Value"
progress="45"
></sp-progress-bar>
</div>
`);
const el = test.querySelector('sp-progress-bar') as ProgressBar;
const percentage = el.shadowRoot.querySelector(
'.percentage'
) as HTMLElement;
expect(percentage.textContent?.search('%')).to.not.equal(-1);
});
it('resolves a language (ar-sa)', async () => {
const [languageContext] = createLanguageContext('ar-sa');
const test = await fixture(html`
<div @sp-language-context=${languageContext}>
<sp-progress-bar
label="Changing Value"
progress="45"
></sp-progress-bar>
</div>
`);
const el = test.querySelector('sp-progress-bar') as ProgressBar;
const percentage = el.shadowRoot.querySelector(
'.percentage'
) as HTMLElement;
expect(percentage.textContent?.search('٪')).to.not.equal(-1);
});
});