-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcolor-picker.spec.ts
More file actions
100 lines (77 loc) · 2.73 KB
/
color-picker.spec.ts
File metadata and controls
100 lines (77 loc) · 2.73 KB
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
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
import { defineComponents } from '../common/definitions/defineComponents.js';
import { createFormAssociatedTestBed } from '../common/utils.spec.js';
import IgcColorPickerComponent from './color-picker.js';
async function createDefaultColorPicker() {
return await fixture<IgcColorPickerComponent>(
html`<igc-color-picker label="Choose a color"></igc-color-picker>`
);
}
describe('Color picker', () => {
before(() => defineComponents(IgcColorPickerComponent));
let picker: IgcColorPickerComponent;
describe('Default', () => {
beforeEach(async () => {
picker = await createDefaultColorPicker();
});
it('is initialized', () => {
expect(picker).to.exist;
});
it('is accessible (close state)', async () => {
await expect(picker).shadowDom.to.be.accessible();
await expect(picker).lightDom.to.be.accessible();
});
it('is accessible (open state)', async () => {
picker.open = true;
await elementUpdated(picker);
await expect(picker).shadowDom.to.be.accessible();
await expect(picker).lightDom.to.be.accessible();
});
});
describe('API', () => {
beforeEach(async () => {
picker = await createDefaultColorPicker();
});
it('`toggle()`', async () => {
await picker.toggle();
expect(picker.open).to.be.true;
await picker.toggle();
expect(picker.open).to.be.false;
});
});
describe('Form associated', () => {
const spec = createFormAssociatedTestBed<IgcColorPickerComponent>(
html`<igc-color-picker name="color-picker"></igc-color-picker>`
);
beforeEach(async () => {
await spec.setup(IgcColorPickerComponent.tagName);
});
it('is form associated', () => {
expect(spec.element.form).to.equal(spec.form);
});
it('is not associated on submit if no value', async () => {
expect(spec.submit()?.get(spec.element.name)).to.be.null;
});
it('is associated on submit', () => {
spec.setProperties({ value: '#bada55' });
spec.assertSubmitHasValue('#bada55');
});
it('is correctly reset on form reset', () => {
spec.setProperties({ value: '#bada55' });
spec.reset();
expect(spec.element.value).to.equal('#000000');
});
it('reflects disabled ancestor state', () => {
spec.setAncestorDisabledState(true);
expect(spec.element.disabled).to.be.true;
spec.setAncestorDisabledState(false);
expect(spec.element.disabled).to.be.false;
});
it('fulfils custom constraint', () => {
spec.element.setCustomValidity('invalid');
spec.assertSubmitFails();
spec.element.setCustomValidity('');
spec.assertSubmitPasses();
});
});
});