-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscl-checkbox.test.ts
129 lines (101 loc) · 3.39 KB
/
scl-checkbox.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
/* 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 './scl-checkbox.js';
import type { SclCheckbox } from './SclCheckbox.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';
document.body.style.height = '400px';
describe('Custom SCL related TextField', () => {
describe('that is non-nullable', () => {
let sclSelect: SclCheckbox;
beforeEach(async () => {
sclSelect = await fixture(
html`<scl-checkbox
.value=${'true'}
label="label"
supportingText="supportingText"
></scl-checkbox>`
);
document.body.prepend(sclSelect);
});
afterEach(() => {
if (sclSelect) sclSelect.remove();
});
it('per default looks like the last screenshot', async () => {
await timeout(200);
await visualDiff(sclSelect, `non-nullable/valid value`);
});
it('when disabled looks like the latest screenshot', async () => {
sclSelect.disabled = true;
await timeout(200);
await visualDiff(sclSelect, `non-nullable/disabled`);
});
it('updates value', async () => {
await timeout(200);
sclSelect.value = 'false';
await timeout(200);
await visualDiff(sclSelect, `non-nullable/update value`);
});
});
describe('that is nullable', () => {
describe('with defaultValue set', () => {
let sclCheckbox: SclCheckbox;
beforeEach(async () => {
sclCheckbox = await fixture(
html`<scl-checkbox
nullable
label="label"
.value=${null}
defaultValue="true"
></scl-checkbox>`
);
document.body.prepend(sclCheckbox);
});
afterEach(() => {
if (sclCheckbox) sclCheckbox.remove();
});
it('with defaultValue set looks like the last screenshot', async () => {
await timeout(200);
await visualDiff(sclCheckbox, `nullable/indicated defaultValue`);
});
it('when disabled the component looks like the last screenshot', async () => {
sclCheckbox.disabled = true;
await timeout(200);
await visualDiff(sclCheckbox, `nullable/disabled`);
});
it('when clicked on the nullSwitch looks like the last screenshot', async () => {
await sendMouse({ type: 'click', position: [380, 20] }); // focus input
await timeout(200);
await visualDiff(sclCheckbox, `nullable/nullSwitch toggled`);
});
});
describe('with defaultValue not set', () => {
let sclCheckbox: SclCheckbox;
beforeEach(async () => {
sclCheckbox = await fixture(
html`<scl-checkbox
nullable
label="label"
.value=${null}
></scl-checkbox>`
);
document.body.prepend(sclCheckbox);
});
afterEach(() => {
if (sclCheckbox) sclCheckbox.remove();
});
it('with defaultValue set looks like the last screenshot', async () => {
await timeout(200);
await visualDiff(sclCheckbox, `nullable/indicates null value`);
});
});
});
});