-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselection-list.test.ts
95 lines (78 loc) · 2.6 KB
/
selection-list.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
/* eslint-disable import/no-extraneous-dependencies */
import { expect, fixture, html } from '@open-wc/testing';
import { sendKeys, sendMouse } from '@web/test-runner-commands';
import { visualDiff } from '@web/test-runner-visual-regression';
import './selection-list.js';
import type { SelectionList, SelectItem } from './SelectionList.js';
const factor = window.process && process.env.CI ? 5 : 3;
function timeout(ms: number) {
return new Promise(res => {
setTimeout(res, ms * factor);
});
}
mocha.timeout(4000 * factor);
document.body.style.width = '400px';
const gseControls = Array.from(
new DOMParser()
.parseFromString(
`<SCL>
<GSEControl name="gse0" desc="gseControl0"/>
<GSEControl name="gse1" desc="gseControl1"/>
<GSEControl name="gse2" />
<GSEControl name="gse3" desc="gseControl3"/>
<GSEControl name="gse4" desc="gseControl4"/>
<GSEControl name="gse5" />
<GSEControl name="gse6" desc="gseControl6"/>
<GSEControl name="gse7" desc="gseControl7"/>
<GSEControl name="gse8" />
<GSEControl name="gse9" desc="gseControl9"/>
</SCL>`,
'application/xml'
)
.querySelectorAll('GSEControl')
);
const itemsList: SelectItem[] = gseControls.map(gseControl => ({
headline: gseControl.getAttribute('name')!,
supportingText: gseControl.getAttribute('desc') ?? undefined,
selected: !!gseControl.getAttribute('desc'),
}));
describe('Custom List component SelectionList', () => {
describe('Allows to preselect items', () => {
let list: SelectionList;
beforeEach(async () => {
list = await fixture(
html`<selection-list .items=${itemsList}></selection-list>`
);
document.body.prepend(list);
});
afterEach(() => {
if (list) list.remove();
});
it('looks like the last screenshot', async () => {
await timeout(200);
await visualDiff(list, `selection-list/pre-selection-list`);
});
});
describe('Can filter when filterable', () => {
let list: SelectionList;
beforeEach(async () => {
list = await fixture(
html`<selection-list filterable .items=${itemsList}></selection-list>`
);
document.body.prepend(list);
});
afterEach(() => {
if (list) list.remove();
});
it('looks like the last screenshot', async () => {
await timeout(200);
await visualDiff(list, `selection-list/filterable`);
});
it('looks like the last screenshot', async () => {
await sendMouse({ type: 'click', position: [20, 20] });
await sendKeys({ type: 'Control' });
await timeout(200);
await visualDiff(list, `selection-list/filtered`);
});
});
});