-
Notifications
You must be signed in to change notification settings - Fork 346
/
checkbox_test.ts
67 lines (53 loc) · 2 KB
/
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
import 'jasmine';
import {Checkbox} from '@material/mwc-checkbox';
import {LitElement} from 'lit';
import {LitCheckbox} from './checkbox';
describe('checkbox test', () => {
let checkbox: LitCheckbox;
beforeEach(async () => {
// Set up.
checkbox = new LitCheckbox();
document.body.appendChild(checkbox);
await checkbox.updateComplete;
});
afterEach(() => {
document.body.removeChild(checkbox);
});
it('can be instantiated', () => {
expect(checkbox instanceof HTMLElement).toBeTrue();
expect(checkbox instanceof LitElement).toBeTrue();
});
it('comprises a div with an MWC Checkbox and a span as children', () => {
expect(checkbox.renderRoot.children.length).toEqual(1);
const [innerDiv] = checkbox.renderRoot.children;
expect(innerDiv instanceof HTMLDivElement).toBeTrue();
expect((innerDiv as HTMLDivElement).className).toEqual(' wrapper ');
expect(innerDiv.children.length).toEqual(2);
const [mwcCheckbox, label] = innerDiv.children;
expect(mwcCheckbox instanceof Checkbox).toBeTrue();
expect(label instanceof HTMLSpanElement).toBeTrue();
expect((label as HTMLSpanElement).className).toEqual('checkbox-label');
});
it('toggles checked state when the box is clicked', async () => {
expect(checkbox.checked).toBeFalse();
const mwcCheckbox =
checkbox.renderRoot.querySelector<Checkbox>('lit-mwc-checkbox-internal')!;
mwcCheckbox.click();
await checkbox.updateComplete;
expect(checkbox.checked).toBeTrue();
mwcCheckbox.click();
await checkbox.updateComplete;
expect(checkbox.checked).toBeFalse();
});
it('toggles checked state when the label is clicked', async () => {
expect(checkbox.checked).toBeFalse();
const label =
checkbox.renderRoot.querySelector<HTMLSpanElement>('span.checkbox-label')!;
label.click();
await checkbox.updateComplete;
expect(checkbox.checked).toBeTrue();
label.click();
await checkbox.updateComplete;
expect(checkbox.checked).toBeFalse();
});
});