Skip to content

Commit e9f0112

Browse files
committed
feat: Added color picker component
1 parent 238c177 commit e9f0112

File tree

13 files changed

+2307
-0
lines changed

13 files changed

+2307
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
2+
3+
import { defineComponents } from '../common/definitions/defineComponents.js';
4+
import { createFormAssociatedTestBed } from '../common/utils.spec.js';
5+
import IgcColorPickerComponent from './color-picker.js';
6+
7+
async function createDefaultColorPicker() {
8+
return await fixture<IgcColorPickerComponent>(
9+
html`<igc-color-picker label="Choose a color"></igc-color-picker>`
10+
);
11+
}
12+
13+
describe('Color picker', () => {
14+
before(() => defineComponents(IgcColorPickerComponent));
15+
16+
let picker: IgcColorPickerComponent;
17+
18+
describe('Default', () => {
19+
beforeEach(async () => {
20+
picker = await createDefaultColorPicker();
21+
});
22+
23+
it('is initialized', () => {
24+
expect(picker).to.exist;
25+
});
26+
27+
it('is accessible (close state)', async () => {
28+
await expect(picker).shadowDom.to.be.accessible();
29+
await expect(picker).lightDom.to.be.accessible();
30+
});
31+
32+
it('is accessible (open state)', async () => {
33+
picker.open = true;
34+
await elementUpdated(picker);
35+
36+
await expect(picker).shadowDom.to.be.accessible();
37+
await expect(picker).lightDom.to.be.accessible();
38+
});
39+
});
40+
41+
describe('API', () => {
42+
beforeEach(async () => {
43+
picker = await createDefaultColorPicker();
44+
});
45+
46+
it('`toggle()`', async () => {
47+
await picker.toggle();
48+
expect(picker.open).to.be.true;
49+
50+
await picker.toggle();
51+
expect(picker.open).to.be.false;
52+
});
53+
});
54+
55+
describe('Form associated', () => {
56+
const spec = createFormAssociatedTestBed<IgcColorPickerComponent>(
57+
html`<igc-color-picker name="color-picker"></igc-color-picker>`
58+
);
59+
60+
beforeEach(async () => {
61+
await spec.setup(IgcColorPickerComponent.tagName);
62+
});
63+
64+
it('is form associated', () => {
65+
expect(spec.element.form).to.equal(spec.form);
66+
});
67+
68+
it('is not associated on submit if no value', async () => {
69+
expect(spec.submit()?.get(spec.element.name)).to.be.null;
70+
});
71+
72+
it('is associated on submit', () => {
73+
spec.setProperties({ value: '#bada55' });
74+
spec.assertSubmitHasValue('#bada55');
75+
});
76+
77+
it('is correctly reset on form reset', () => {
78+
spec.setProperties({ value: '#bada55' });
79+
80+
spec.reset();
81+
expect(spec.element.value).to.equal('#000000');
82+
});
83+
84+
it('reflects disabled ancestor state', () => {
85+
spec.setAncestorDisabledState(true);
86+
expect(spec.element.disabled).to.be.true;
87+
88+
spec.setAncestorDisabledState(false);
89+
expect(spec.element.disabled).to.be.false;
90+
});
91+
92+
it('fulfils custom constraint', () => {
93+
spec.element.setCustomValidity('invalid');
94+
spec.assertSubmitFails();
95+
96+
spec.element.setCustomValidity('');
97+
spec.assertSubmitPasses();
98+
});
99+
});
100+
});

0 commit comments

Comments
 (0)