@spectrum-web-components/swatch 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["swatch-group.test-vrt.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/swatch-group.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('SwatchGroupStories', stories as unknown as TestsType);\n"],
5
+ "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,sBAAsB,OAA+B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,377 @@
1
+ "use strict";
2
+ import { elementUpdated, expect, fixture, nextFrame } from "@open-wc/testing";
3
+ import { sendKeys } from "@web/test-runner-commands";
4
+ import "@spectrum-web-components/swatch/sp-swatch.js";
5
+ import { Default } from "../stories/swatch-group.stories.js";
6
+ import { spy, stub } from "sinon";
7
+ import { html } from "@spectrum-web-components/base";
8
+ import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
9
+ describe("Swatch Group", () => {
10
+ let el;
11
+ beforeEach(async () => {
12
+ el = await fixture(Default(Default.args));
13
+ await elementUpdated(el);
14
+ });
15
+ testForLitDevWarnings(
16
+ async () => await fixture(Default(Default.args))
17
+ );
18
+ it("loads default swatch accessibly", async () => {
19
+ await expect(el).to.be.accessible();
20
+ });
21
+ it("forwards `border` to children", async () => {
22
+ el.border = "light";
23
+ await elementUpdated(el);
24
+ [...el.children].forEach((child) => {
25
+ expect(child.border).to.equal("light");
26
+ });
27
+ });
28
+ it("forwards `rounding` to children", async () => {
29
+ el.rounding = "full";
30
+ await elementUpdated(el);
31
+ [...el.children].forEach((child) => {
32
+ expect(child.rounding).to.equal("full");
33
+ });
34
+ });
35
+ it("forwards `size` to children", async () => {
36
+ el.size = "xs";
37
+ await elementUpdated(el);
38
+ [...el.children].forEach((child) => {
39
+ expect(child.size).to.equal("xs");
40
+ });
41
+ });
42
+ it("forwards `shape` to children", async () => {
43
+ el.shape = "rectangle";
44
+ await elementUpdated(el);
45
+ [...el.children].forEach((child) => {
46
+ expect(child.shape).to.equal("rectangle");
47
+ });
48
+ });
49
+ it("unsets forwarding", async () => {
50
+ el.border = "light";
51
+ el.rounding = "full";
52
+ el.size = "xs";
53
+ el.shape = "rectangle";
54
+ await elementUpdated(el);
55
+ [...el.children].forEach((child) => {
56
+ expect(child.border).to.not.be.undefined;
57
+ expect(child.rounding).to.not.be.undefined;
58
+ expect(child.size).to.not.equal("m");
59
+ expect(child.shape).to.not.be.undefined;
60
+ });
61
+ el.border = void 0;
62
+ el.rounding = void 0;
63
+ el.removeAttribute("size");
64
+ el.shape = void 0;
65
+ await elementUpdated(el);
66
+ [...el.children].forEach((child) => {
67
+ expect(child.border).to.equal(void 0);
68
+ expect(child.rounding).to.equal(void 0);
69
+ expect(child.size).to.equal("m");
70
+ expect(child.shape).to.equal(void 0);
71
+ });
72
+ });
73
+ it("does not dispatch `change` events without `selects` attribute", async () => {
74
+ const selectedChild = el.querySelector(
75
+ ":scope > sp-swatch:nth-child(4)"
76
+ );
77
+ const changeSpy = spy();
78
+ el.addEventListener("change", () => changeSpy());
79
+ expect(el.selected).to.deep.equal([]);
80
+ selectedChild.click();
81
+ expect(changeSpy.called).to.be.false;
82
+ expect(el.selected).to.deep.equal([]);
83
+ });
84
+ it('dispatches `change` events as [selects="single"]', async () => {
85
+ el.selects = "single";
86
+ const selectedChild = el.querySelector(
87
+ ":scope > sp-swatch:nth-child(4)"
88
+ );
89
+ const changeSpy = spy();
90
+ el.addEventListener("change", () => changeSpy());
91
+ expect(el.selected).to.deep.equal([]);
92
+ expect(selectedChild.selected).to.be.false;
93
+ selectedChild.click();
94
+ expect(changeSpy.calledOnce).to.be.true;
95
+ expect(el.selected).to.deep.equal([selectedChild.value]);
96
+ expect(selectedChild.selected).to.be.true;
97
+ selectedChild.click();
98
+ expect(changeSpy.calledOnce).to.be.true;
99
+ expect(el.selected).to.deep.equal([selectedChild.value]);
100
+ expect(selectedChild.selected).to.be.true;
101
+ });
102
+ it("can have `change` events prevented", async () => {
103
+ el.selects = "single";
104
+ const selectedChild = el.querySelector(
105
+ ":scope > sp-swatch:nth-child(4)"
106
+ );
107
+ el.addEventListener("change", (event) => event.preventDefault());
108
+ expect(el.selected).to.deep.equal([]);
109
+ expect(selectedChild.selected).to.be.false;
110
+ selectedChild.click();
111
+ expect(el.selected).to.deep.equal([]);
112
+ expect(selectedChild.selected).to.be.false;
113
+ });
114
+ it('dispatches `change` events as [selects="multiple"]', async () => {
115
+ el.selects = "multiple";
116
+ const selectedChild0 = el.querySelector(
117
+ ":scope > sp-swatch:nth-child(1)"
118
+ );
119
+ const selectedChild1 = el.querySelector(
120
+ ":scope > sp-swatch:nth-child(4)"
121
+ );
122
+ const selectedChild2 = el.querySelector(
123
+ ":scope > sp-swatch:nth-child(6)"
124
+ );
125
+ await elementUpdated(selectedChild0);
126
+ const changeSpy = spy();
127
+ el.addEventListener("change", () => changeSpy());
128
+ expect(el.selected).to.deep.equal([]);
129
+ selectedChild0.click();
130
+ selectedChild1.click();
131
+ selectedChild2.click();
132
+ expect(changeSpy.callCount).to.equal(3);
133
+ expect(el.selected).to.deep.equal([
134
+ selectedChild0.value,
135
+ selectedChild1.value,
136
+ selectedChild2.value
137
+ ]);
138
+ });
139
+ it("filters `selected` when a selected Swatch is removed from the DOM", async () => {
140
+ el.selects = "multiple";
141
+ const selectedChild0 = el.querySelector(
142
+ ":scope > sp-swatch:nth-child(1)"
143
+ );
144
+ const selectedChild1 = el.querySelector(
145
+ ":scope > sp-swatch:nth-child(4)"
146
+ );
147
+ const selectedChild2 = el.querySelector(
148
+ ":scope > sp-swatch:nth-child(6)"
149
+ );
150
+ await elementUpdated(selectedChild0);
151
+ expect(el.selected).to.deep.equal([]);
152
+ selectedChild0.click();
153
+ selectedChild1.click();
154
+ selectedChild2.click();
155
+ expect(el.selected).to.deep.equal([
156
+ selectedChild0.value,
157
+ selectedChild1.value,
158
+ selectedChild2.value
159
+ ]);
160
+ selectedChild0.remove();
161
+ await elementUpdated(el);
162
+ expect(el.selected).to.deep.equal([
163
+ selectedChild1.value,
164
+ selectedChild2.value
165
+ ]);
166
+ selectedChild2.remove();
167
+ await elementUpdated(el);
168
+ expect(el.selected).to.deep.equal([selectedChild1.value]);
169
+ selectedChild1.remove();
170
+ await elementUpdated(el);
171
+ expect(el.selected).to.deep.equal([]);
172
+ });
173
+ it("maintains a single tab stop", async () => {
174
+ const inputBefore = document.createElement("input");
175
+ const inputAfter = document.createElement("input");
176
+ el.insertAdjacentElement("beforebegin", inputBefore);
177
+ el.insertAdjacentElement("afterend", inputAfter);
178
+ inputBefore.focus();
179
+ expect(document.activeElement === el.children[0]).to.be.false;
180
+ await sendKeys({
181
+ press: "Tab"
182
+ });
183
+ expect(document.activeElement === el.children[0]).to.be.true;
184
+ await sendKeys({
185
+ press: "Tab"
186
+ });
187
+ expect(document.activeElement === el.children[0]).to.be.false;
188
+ await sendKeys({
189
+ press: "Shift+Tab"
190
+ });
191
+ expect(document.activeElement === el.children[0]).to.be.true;
192
+ });
193
+ it("makes the first selected child the single tab stop", async () => {
194
+ const selectedChild = el.querySelector(
195
+ ":scope > sp-swatch:nth-child(4)"
196
+ );
197
+ expect(selectedChild.selected).to.be.false;
198
+ const inputBefore = document.createElement("input");
199
+ const inputAfter = document.createElement("input");
200
+ el.insertAdjacentElement("beforebegin", inputBefore);
201
+ el.insertAdjacentElement("afterend", inputAfter);
202
+ inputBefore.focus();
203
+ el.selects = "single";
204
+ el.selected = [selectedChild.value];
205
+ await elementUpdated(el);
206
+ await nextFrame();
207
+ await nextFrame();
208
+ expect(selectedChild.selected).to.be.true;
209
+ expect(document.activeElement === selectedChild).to.be.false;
210
+ await sendKeys({
211
+ press: "Tab"
212
+ });
213
+ expect(document.activeElement === selectedChild).to.be.true;
214
+ await sendKeys({
215
+ press: "Tab"
216
+ });
217
+ expect(document.activeElement === selectedChild).to.be.false;
218
+ await sendKeys({
219
+ press: "Shift+Tab"
220
+ });
221
+ expect(document.activeElement === selectedChild).to.be.true;
222
+ });
223
+ it("focus()es to the first Swatch", async () => {
224
+ el.focus();
225
+ expect(document.activeElement === el.children[0]).to.be.true;
226
+ });
227
+ it("focus()es to the first selected Swatch", async () => {
228
+ const selectedChild = el.querySelector(
229
+ ":scope > sp-swatch:nth-child(4)"
230
+ );
231
+ expect(selectedChild.selected).to.be.false;
232
+ el.selects = "single";
233
+ el.selected = [selectedChild.value];
234
+ await elementUpdated(el);
235
+ await nextFrame();
236
+ expect(selectedChild.selected).to.be.true;
237
+ el.focus();
238
+ expect(document.activeElement === selectedChild).to.be.true;
239
+ });
240
+ });
241
+ describe("Swatch Group - DOM selected", () => {
242
+ describe("dev mode", () => {
243
+ let consoleWarnStub;
244
+ before(() => {
245
+ window.__swc.verbose = true;
246
+ consoleWarnStub = stub(console, "warn");
247
+ });
248
+ afterEach(() => {
249
+ consoleWarnStub.resetHistory();
250
+ });
251
+ after(() => {
252
+ window.__swc.verbose = false;
253
+ consoleWarnStub.restore();
254
+ });
255
+ it('warns in Dev Mode when mixed-value attribute is added in sp-swatch when parent sp-swatch-group is not having selects="multiple"', async () => {
256
+ const el = await fixture(
257
+ html`
258
+ <sp-swatch-group selects="single">
259
+ <sp-swatch mixed-value></sp-swatch>
260
+ </sp-swatch-group>
261
+ `
262
+ );
263
+ await elementUpdated(el);
264
+ await nextFrame();
265
+ await nextFrame();
266
+ expect(consoleWarnStub.called).to.be.true;
267
+ const spyCall = consoleWarnStub.getCall(0);
268
+ expect(
269
+ spyCall.args.at(0).includes(
270
+ '<sp-swatch> elements can only leverage the "mixed-value" attribute when their <sp-swatch-group> parent element is also leveraging "selects="multiple"'
271
+ ),
272
+ "confirm warning message"
273
+ ).to.be.true;
274
+ expect(spyCall.args.at(-1), "confirm `data` shape").to.deep.equal({
275
+ data: {
276
+ localName: "sp-swatch-group",
277
+ type: "accessibility",
278
+ level: "default"
279
+ }
280
+ });
281
+ });
282
+ });
283
+ it("accepts selection from DOM", async () => {
284
+ const el = await fixture(html`
285
+ <sp-swatch-group selects="multiple">
286
+ <sp-swatch value="color-0" color="red"></sp-swatch>
287
+ <sp-swatch value="color-1" color="green" selected></sp-swatch>
288
+ <sp-swatch value="color-2" color="blue"></sp-swatch>
289
+ <sp-swatch value="color-3" color="yellow" selected></sp-swatch>
290
+ </sp-swatch-group>
291
+ `);
292
+ await elementUpdated(el);
293
+ expect(el.selected).to.deep.equal(["color-1", "color-3"]);
294
+ });
295
+ it("merges `selected` and selection from DOM", async function() {
296
+ const el = await fixture(html`
297
+ <sp-swatch-group selects="multiple" .selected=${["color-1"]}>
298
+ <sp-swatch value="color-0" color="red"></sp-swatch>
299
+ <sp-swatch value="color-1" color="green"></sp-swatch>
300
+ <sp-swatch value="color-2" color="blue"></sp-swatch>
301
+ <sp-swatch value="color-3" color="yellow" selected></sp-swatch>
302
+ </sp-swatch-group>
303
+ `);
304
+ await elementUpdated(el);
305
+ await nextFrame();
306
+ await nextFrame();
307
+ expect(el.selected).to.deep.equal(["color-1", "color-3"]);
308
+ });
309
+ it("lazily accepts selection from DOM", async function() {
310
+ const el = await fixture(html`
311
+ <sp-swatch-group selects="multiple">
312
+ <sp-swatch value="color-0" color="red"></sp-swatch>
313
+ <sp-swatch value="color-1" color="green"></sp-swatch>
314
+ <sp-swatch value="color-2" color="blue"></sp-swatch>
315
+ <sp-swatch value="color-3" color="yellow" selected></sp-swatch>
316
+ </sp-swatch-group>
317
+ `);
318
+ await elementUpdated(el);
319
+ await nextFrame();
320
+ await nextFrame();
321
+ const color1 = el.querySelector('[value="color-1"]');
322
+ expect(el.selected).to.deep.equal(["color-3"]);
323
+ color1.selected = true;
324
+ await elementUpdated(el);
325
+ await nextFrame();
326
+ await nextFrame();
327
+ expect(el.selected).to.deep.equal(["color-3", "color-1"]);
328
+ });
329
+ it("clears previously selected children when updating `selected`", async () => {
330
+ const el = await fixture(html`
331
+ <sp-swatch-group selects="single" .selected=${["color-1"]}>
332
+ <sp-swatch value="color-0" color="red"></sp-swatch>
333
+ <sp-swatch value="color-1" color="green"></sp-swatch>
334
+ <sp-swatch value="color-2" color="blue"></sp-swatch>
335
+ </sp-swatch-group>
336
+ `);
337
+ await elementUpdated(el);
338
+ expect(el.selected).to.deep.equal(["color-1"]);
339
+ el.selected = ["color-2"];
340
+ await elementUpdated(el);
341
+ expect(el.selected).to.deep.equal(["color-2"]);
342
+ });
343
+ });
344
+ describe("Swatch Group - slotted", () => {
345
+ it('manages [selects="single"] selection through multiple slots', async () => {
346
+ const test = await fixture(
347
+ html`
348
+ <div>
349
+ <sp-swatch value="First">First</sp-swatch>
350
+ <sp-swatch value="Second">Second</sp-swatch>
351
+ <sp-swatch value="Third" selected>Third</sp-swatch>
352
+ </div>
353
+ `
354
+ );
355
+ const firstItem = test.querySelector("sp-swatch");
356
+ const thirdItem = test.querySelector("sp-swatch[selected]");
357
+ const shadowRoot = test.attachShadow({ mode: "open" });
358
+ shadowRoot.innerHTML = `
359
+ <sp-swatch-group label="Selects Single Group" selects="single">
360
+ <slot></slot>
361
+ </sp-swatch-group>
362
+ `;
363
+ const el = shadowRoot.querySelector("sp-swatch-group");
364
+ await elementUpdated(el);
365
+ await nextFrame();
366
+ await nextFrame();
367
+ expect(el.selected, '"Third" selected').to.deep.equal(["Third"]);
368
+ expect(firstItem.selected).to.be.false;
369
+ expect(thirdItem.selected).to.be.true;
370
+ firstItem.click();
371
+ await elementUpdated(el);
372
+ expect(el.selected, '"First" selected').to.deep.equal(["First"]);
373
+ expect(firstItem.selected).to.be.true;
374
+ expect(thirdItem.selected).to.be.false;
375
+ });
376
+ });
377
+ //# sourceMappingURL=swatch-group.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["swatch-group.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { elementUpdated, expect, fixture, nextFrame } from '@open-wc/testing';\nimport { sendKeys } from '@web/test-runner-commands';\n\nimport '@spectrum-web-components/swatch/sp-swatch.js';\nimport { Swatch, SwatchGroup } from '../';\nimport { Default } from '../stories/swatch-group.stories.js';\nimport { spy, stub } from 'sinon';\nimport { html } from '@spectrum-web-components/base';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\n\ndescribe('Swatch Group', () => {\n let el: SwatchGroup;\n beforeEach(async () => {\n el = await fixture<SwatchGroup>(Default(Default.args));\n\n await elementUpdated(el);\n });\n testForLitDevWarnings(\n async () => await fixture<SwatchGroup>(Default(Default.args))\n );\n it('loads default swatch accessibly', async () => {\n await expect(el).to.be.accessible();\n });\n it('forwards `border` to children', async () => {\n el.border = 'light';\n await elementUpdated(el);\n\n ([...el.children] as Swatch[]).forEach((child) => {\n expect(child.border).to.equal('light');\n });\n });\n it('forwards `rounding` to children', async () => {\n el.rounding = 'full';\n await elementUpdated(el);\n\n ([...el.children] as Swatch[]).forEach((child) => {\n expect(child.rounding).to.equal('full');\n });\n });\n it('forwards `size` to children', async () => {\n el.size = 'xs';\n await elementUpdated(el);\n\n ([...el.children] as Swatch[]).forEach((child) => {\n expect(child.size).to.equal('xs');\n });\n });\n it('forwards `shape` to children', async () => {\n el.shape = 'rectangle';\n await elementUpdated(el);\n\n ([...el.children] as Swatch[]).forEach((child) => {\n expect(child.shape).to.equal('rectangle');\n });\n });\n it('unsets forwarding', async () => {\n el.border = 'light';\n el.rounding = 'full';\n el.size = 'xs';\n el.shape = 'rectangle';\n await elementUpdated(el);\n\n ([...el.children] as Swatch[]).forEach((child) => {\n expect(child.border).to.not.be.undefined;\n expect(child.rounding).to.not.be.undefined;\n expect(child.size).to.not.equal('m');\n expect(child.shape).to.not.be.undefined;\n });\n\n el.border = undefined;\n el.rounding = undefined;\n el.removeAttribute('size');\n el.shape = undefined;\n await elementUpdated(el);\n\n ([...el.children] as Swatch[]).forEach((child) => {\n expect(child.border).to.equal(undefined);\n expect(child.rounding).to.equal(undefined);\n expect(child.size).to.equal('m');\n expect(child.shape).to.equal(undefined);\n });\n });\n it('does not dispatch `change` events without `selects` attribute', async () => {\n const selectedChild = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n\n const changeSpy = spy();\n\n el.addEventListener('change', () => changeSpy());\n\n expect(el.selected).to.deep.equal([]);\n\n selectedChild.click();\n\n expect(changeSpy.called).to.be.false;\n expect(el.selected).to.deep.equal([]);\n });\n it('dispatches `change` events as [selects=\"single\"]', async () => {\n el.selects = 'single';\n const selectedChild = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n\n const changeSpy = spy();\n\n el.addEventListener('change', () => changeSpy());\n\n expect(el.selected).to.deep.equal([]);\n expect(selectedChild.selected).to.be.false;\n\n selectedChild.click();\n\n expect(changeSpy.calledOnce).to.be.true;\n expect(el.selected).to.deep.equal([selectedChild.value]);\n expect(selectedChild.selected).to.be.true;\n\n selectedChild.click();\n\n expect(changeSpy.calledOnce).to.be.true;\n expect(el.selected).to.deep.equal([selectedChild.value]);\n expect(selectedChild.selected).to.be.true;\n });\n it('can have `change` events prevented', async () => {\n el.selects = 'single';\n const selectedChild = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n\n el.addEventListener('change', (event: Event) => event.preventDefault());\n\n expect(el.selected).to.deep.equal([]);\n expect(selectedChild.selected).to.be.false;\n\n selectedChild.click();\n\n expect(el.selected).to.deep.equal([]);\n expect(selectedChild.selected).to.be.false;\n });\n it('dispatches `change` events as [selects=\"multiple\"]', async () => {\n el.selects = 'multiple';\n const selectedChild0 = el.querySelector(\n ':scope > sp-swatch:nth-child(1)'\n ) as Swatch;\n const selectedChild1 = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n const selectedChild2 = el.querySelector(\n ':scope > sp-swatch:nth-child(6)'\n ) as Swatch;\n\n await elementUpdated(selectedChild0);\n\n const changeSpy = spy();\n\n el.addEventListener('change', () => changeSpy());\n\n expect(el.selected).to.deep.equal([]);\n\n selectedChild0.click();\n selectedChild1.click();\n selectedChild2.click();\n\n expect(changeSpy.callCount).to.equal(3);\n expect(el.selected).to.deep.equal([\n selectedChild0.value,\n selectedChild1.value,\n selectedChild2.value,\n ]);\n });\n it('filters `selected` when a selected Swatch is removed from the DOM', async () => {\n el.selects = 'multiple';\n const selectedChild0 = el.querySelector(\n ':scope > sp-swatch:nth-child(1)'\n ) as Swatch;\n const selectedChild1 = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n const selectedChild2 = el.querySelector(\n ':scope > sp-swatch:nth-child(6)'\n ) as Swatch;\n\n await elementUpdated(selectedChild0);\n\n expect(el.selected).to.deep.equal([]);\n\n selectedChild0.click();\n selectedChild1.click();\n selectedChild2.click();\n\n expect(el.selected).to.deep.equal([\n selectedChild0.value,\n selectedChild1.value,\n selectedChild2.value,\n ]);\n\n selectedChild0.remove();\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([\n selectedChild1.value,\n selectedChild2.value,\n ]);\n\n selectedChild2.remove();\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([selectedChild1.value]);\n\n selectedChild1.remove();\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal([]);\n });\n it('maintains a single tab stop', async () => {\n const inputBefore = document.createElement('input');\n const inputAfter = document.createElement('input');\n el.insertAdjacentElement('beforebegin', inputBefore);\n el.insertAdjacentElement('afterend', inputAfter);\n inputBefore.focus();\n expect(document.activeElement === el.children[0]).to.be.false;\n await sendKeys({\n press: 'Tab',\n });\n expect(document.activeElement === el.children[0]).to.be.true;\n await sendKeys({\n press: 'Tab',\n });\n expect(document.activeElement === el.children[0]).to.be.false;\n await sendKeys({\n press: 'Shift+Tab',\n });\n expect(document.activeElement === el.children[0]).to.be.true;\n });\n it('makes the first selected child the single tab stop', async () => {\n const selectedChild = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n expect(selectedChild.selected).to.be.false;\n\n const inputBefore = document.createElement('input');\n const inputAfter = document.createElement('input');\n el.insertAdjacentElement('beforebegin', inputBefore);\n el.insertAdjacentElement('afterend', inputAfter);\n inputBefore.focus();\n el.selects = 'single';\n el.selected = [selectedChild.value];\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n\n expect(selectedChild.selected).to.be.true;\n\n expect(document.activeElement === selectedChild).to.be.false;\n await sendKeys({\n press: 'Tab',\n });\n expect(document.activeElement === selectedChild).to.be.true;\n await sendKeys({\n press: 'Tab',\n });\n expect(document.activeElement === selectedChild).to.be.false;\n await sendKeys({\n press: 'Shift+Tab',\n });\n expect(document.activeElement === selectedChild).to.be.true;\n });\n it('focus()es to the first Swatch', async () => {\n el.focus();\n expect(document.activeElement === el.children[0]).to.be.true;\n });\n it('focus()es to the first selected Swatch', async () => {\n const selectedChild = el.querySelector(\n ':scope > sp-swatch:nth-child(4)'\n ) as Swatch;\n expect(selectedChild.selected).to.be.false;\n el.selects = 'single';\n el.selected = [selectedChild.value];\n await elementUpdated(el);\n await nextFrame();\n\n expect(selectedChild.selected).to.be.true;\n el.focus();\n expect(document.activeElement === selectedChild).to.be.true;\n });\n});\n\ndescribe('Swatch Group - DOM selected', () => {\n describe('dev mode', () => {\n let consoleWarnStub!: ReturnType<typeof stub>;\n before(() => {\n window.__swc.verbose = true;\n consoleWarnStub = stub(console, 'warn');\n });\n afterEach(() => {\n consoleWarnStub.resetHistory();\n });\n after(() => {\n window.__swc.verbose = false;\n consoleWarnStub.restore();\n });\n\n it('warns in Dev Mode when mixed-value attribute is added in sp-swatch when parent sp-swatch-group is not having selects=\"multiple\"', async () => {\n const el = await fixture<SwatchGroup>(\n html`\n <sp-swatch-group selects=\"single\">\n <sp-swatch mixed-value></sp-swatch>\n </sp-swatch-group>\n `\n );\n\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n\n expect(consoleWarnStub.called).to.be.true;\n const spyCall = consoleWarnStub.getCall(0);\n\n expect(\n (spyCall.args.at(0) as string).includes(\n '<sp-swatch> elements can only leverage the \"mixed-value\" attribute when their <sp-swatch-group> parent element is also leveraging \"selects=\"multiple\"'\n ),\n 'confirm warning message'\n ).to.be.true;\n\n expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({\n data: {\n localName: 'sp-swatch-group',\n type: 'accessibility',\n level: 'default',\n },\n });\n });\n });\n it('accepts selection from DOM', async () => {\n const el = await fixture<SwatchGroup>(html`\n <sp-swatch-group selects=\"multiple\">\n <sp-swatch value=\"color-0\" color=\"red\"></sp-swatch>\n <sp-swatch value=\"color-1\" color=\"green\" selected></sp-swatch>\n <sp-swatch value=\"color-2\" color=\"blue\"></sp-swatch>\n <sp-swatch value=\"color-3\" color=\"yellow\" selected></sp-swatch>\n </sp-swatch-group>\n `);\n\n await elementUpdated(el);\n\n expect(el.selected).to.deep.equal(['color-1', 'color-3']);\n });\n it('merges `selected` and selection from DOM', async function () {\n const el = await fixture<SwatchGroup>(html`\n <sp-swatch-group selects=\"multiple\" .selected=${['color-1']}>\n <sp-swatch value=\"color-0\" color=\"red\"></sp-swatch>\n <sp-swatch value=\"color-1\" color=\"green\"></sp-swatch>\n <sp-swatch value=\"color-2\" color=\"blue\"></sp-swatch>\n <sp-swatch value=\"color-3\" color=\"yellow\" selected></sp-swatch>\n </sp-swatch-group>\n `);\n\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n\n expect(el.selected).to.deep.equal(['color-1', 'color-3']);\n });\n it('lazily accepts selection from DOM', async function () {\n const el = await fixture<SwatchGroup>(html`\n <sp-swatch-group selects=\"multiple\">\n <sp-swatch value=\"color-0\" color=\"red\"></sp-swatch>\n <sp-swatch value=\"color-1\" color=\"green\"></sp-swatch>\n <sp-swatch value=\"color-2\" color=\"blue\"></sp-swatch>\n <sp-swatch value=\"color-3\" color=\"yellow\" selected></sp-swatch>\n </sp-swatch-group>\n `);\n\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n const color1 = el.querySelector('[value=\"color-1\"]') as Swatch;\n\n expect(el.selected).to.deep.equal(['color-3']);\n\n color1.selected = true;\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n\n expect(el.selected).to.deep.equal(['color-3', 'color-1']);\n });\n it('clears previously selected children when updating `selected`', async () => {\n const el = await fixture<SwatchGroup>(html`\n <sp-swatch-group selects=\"single\" .selected=${['color-1']}>\n <sp-swatch value=\"color-0\" color=\"red\"></sp-swatch>\n <sp-swatch value=\"color-1\" color=\"green\"></sp-swatch>\n <sp-swatch value=\"color-2\" color=\"blue\"></sp-swatch>\n </sp-swatch-group>\n `);\n await elementUpdated(el);\n expect(el.selected).to.deep.equal(['color-1']);\n el.selected = ['color-2'];\n await elementUpdated(el);\n expect(el.selected).to.deep.equal(['color-2']);\n });\n});\n\ndescribe('Swatch Group - slotted', () => {\n it('manages [selects=\"single\"] selection through multiple slots', async () => {\n const test = await fixture<HTMLDivElement>(\n html`\n <div>\n <sp-swatch value=\"First\">First</sp-swatch>\n <sp-swatch value=\"Second\">Second</sp-swatch>\n <sp-swatch value=\"Third\" selected>Third</sp-swatch>\n </div>\n `\n );\n\n const firstItem = test.querySelector('sp-swatch') as Swatch;\n const thirdItem = test.querySelector('sp-swatch[selected]') as Swatch;\n\n const shadowRoot = test.attachShadow({ mode: 'open' });\n shadowRoot.innerHTML = `\n <sp-swatch-group label=\"Selects Single Group\" selects=\"single\">\n <slot></slot>\n </sp-swatch-group>\n `;\n\n const el = shadowRoot.querySelector('sp-swatch-group') as SwatchGroup;\n await elementUpdated(el);\n // Await test slot change time.\n await nextFrame();\n await nextFrame();\n\n expect(el.selected, '\"Third\" selected').to.deep.equal(['Third']);\n expect(firstItem.selected).to.be.false;\n expect(thirdItem.selected).to.be.true;\n\n firstItem.click();\n await elementUpdated(el);\n\n expect(el.selected, '\"First\" selected').to.deep.equal(['First']);\n expect(firstItem.selected).to.be.true;\n expect(thirdItem.selected).to.be.false;\n });\n});\n"],
5
+ "mappings": ";AAWA,SAAS,gBAAgB,QAAQ,SAAS,iBAAiB;AAC3D,SAAS,gBAAgB;AAEzB,OAAO;AAEP,SAAS,eAAe;AACxB,SAAS,KAAK,YAAY;AAC1B,SAAS,YAAY;AACrB,SAAS,6BAA6B;AAEtC,SAAS,gBAAgB,MAAM;AAC3B,MAAI;AACJ,aAAW,YAAY;AACnB,SAAK,MAAM,QAAqB,QAAQ,QAAQ,IAAI,CAAC;AAErD,UAAM,eAAe,EAAE;AAAA,EAC3B,CAAC;AACD;AAAA,IACI,YAAY,MAAM,QAAqB,QAAQ,QAAQ,IAAI,CAAC;AAAA,EAChE;AACA,KAAG,mCAAmC,YAAY;AAC9C,UAAM,OAAO,EAAE,EAAE,GAAG,GAAG,WAAW;AAAA,EACtC,CAAC;AACD,KAAG,iCAAiC,YAAY;AAC5C,OAAG,SAAS;AACZ,UAAM,eAAe,EAAE;AAEvB,IAAC,CAAC,GAAG,GAAG,QAAQ,EAAe,QAAQ,CAAC,UAAU;AAC9C,aAAO,MAAM,MAAM,EAAE,GAAG,MAAM,OAAO;AAAA,IACzC,CAAC;AAAA,EACL,CAAC;AACD,KAAG,mCAAmC,YAAY;AAC9C,O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;AACrD,eAAW,YAAY;AAAA;AAAA;AAAA;AAAA;AAMvB,UAAM,KAAK,WAAW,cAAc,iBAAiB;AACrD,UAAM,eAAe,EAAE;AAEvB,UAAM,UAAU;AAChB,UAAM,UAAU;AAEhB,WAAO,GAAG,UAAU,kBAAkB,EAAE,GAAG,KAAK,MAAM,CAAC,OAAO,CAAC;AAC/D,WAAO,UAAU,QAAQ,EAAE,GAAG,GAAG;AACjC,WAAO,UAAU,QAAQ,EAAE,GAAG,GAAG;AAEjC,cAAU,MAAM;AAChB,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,UAAU,kBAAkB,EAAE,GAAG,KAAK,MAAM,CAAC,OAAO,CAAC;AAC/D,WAAO,UAAU,QAAQ,EAAE,GAAG,GAAG;AACjC,WAAO,UAAU,QAAQ,EAAE,GAAG,GAAG;AAAA,EACrC,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ import { html } from "@open-wc/testing";
3
+ import "@spectrum-web-components/swatch/sp-swatch.js";
4
+ import { testForMemoryLeaks } from "../../../test/testing-helpers.js";
5
+ testForMemoryLeaks(html`
6
+ <sp-swatch></sp-swatch>
7
+ `);
8
+ //# sourceMappingURL=swatch-memory.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["swatch-memory.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2023 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html } from '@open-wc/testing';\nimport '@spectrum-web-components/swatch/sp-swatch.js';\nimport { testForMemoryLeaks } from '../../../test/testing-helpers.js';\n\ntestForMemoryLeaks(html`\n <sp-swatch></sp-swatch>\n`);\n"],
5
+ "mappings": ";AAWA,SAAS,YAAY;AACrB,OAAO;AACP,SAAS,0BAA0B;AAEnC,mBAAmB;AAAA;AAAA,CAElB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ import * as stories from "../stories/swatch-sizes.stories.js";
3
+ import { regressVisuals } from "../../../test/visual/test.js";
4
+ regressVisuals("SwatchSizesStories", stories);
5
+ //# sourceMappingURL=swatch-sizes.test-vrt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["swatch-sizes.test-vrt.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/swatch-sizes.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('SwatchSizesStories', stories as unknown as TestsType);\n"],
5
+ "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,sBAAsB,OAA+B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ import * as stories from "../stories/swatch.stories.js";
3
+ import { regressVisuals } from "../../../test/visual/test.js";
4
+ regressVisuals("SwatchStories", stories);
5
+ //# sourceMappingURL=swatch.test-vrt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["swatch.test-vrt.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/swatch.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('SwatchStories', stories as unknown as TestsType);\n"],
5
+ "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,iBAAiB,OAA+B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
3
+ import { spy } from "sinon";
4
+ import { sendKeys } from "@web/test-runner-commands";
5
+ import "@spectrum-web-components/swatch/sp-swatch.js";
6
+ import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
7
+ describe("Swatch", () => {
8
+ let el;
9
+ beforeEach(async () => {
10
+ el = await fixture(html`
11
+ <sp-swatch color="red" label="Red"></sp-swatch>
12
+ `);
13
+ await elementUpdated(el);
14
+ });
15
+ testForLitDevWarnings(
16
+ async () => await fixture(html`
17
+ <sp-swatch color="red" label="Red"></sp-swatch>
18
+ `)
19
+ );
20
+ it(`loads default swatch accessibly`, async () => {
21
+ await expect(el).to.be.accessible();
22
+ });
23
+ it("loads [mixed-value] swatch accessibly", async () => {
24
+ el.mixedValue = true;
25
+ await expect(el).to.be.accessible();
26
+ expect(el.getAttribute("aria-label")).to.equal("Red");
27
+ el.removeAttribute("label");
28
+ await elementUpdated(el);
29
+ expect(el.getAttribute("aria-label")).to.equal("red");
30
+ el.removeAttribute("color");
31
+ await elementUpdated(el);
32
+ expect(el.getAttribute("aria-label")).to.equal("Mixed");
33
+ });
34
+ it("loads [nothing] swatch accessibly", async () => {
35
+ el.nothing = true;
36
+ el.removeAttribute("color");
37
+ el.label = "Transparent";
38
+ await expect(el).to.be.accessible();
39
+ expect(el.getAttribute("aria-label")).to.equal("Transparent");
40
+ });
41
+ ["xs", "s", "m", "l"].map((size) => {
42
+ it(`loads [mixed-value] swatch accessibly as [size=${size}]`, async () => {
43
+ el.mixedValue = true;
44
+ el.removeAttribute("color");
45
+ el.label = "Mixed Value";
46
+ el.size = size;
47
+ await expect(el).to.be.accessible();
48
+ expect(el.getAttribute("aria-label")).to.equal("Mixed Value");
49
+ });
50
+ });
51
+ it("toggles on `click`", async () => {
52
+ expect(el.selected).to.be.false;
53
+ el.click();
54
+ expect(el.selected).to.be.true;
55
+ await expect(el).to.be.accessible();
56
+ });
57
+ it('toggles on `click` as [role="checkbox"]', async () => {
58
+ el.role = "checkbox";
59
+ await elementUpdated(el);
60
+ expect(el.selected).to.be.false;
61
+ await expect(el).to.be.accessible();
62
+ el.click();
63
+ expect(el.selected).to.be.true;
64
+ await expect(el).to.be.accessible();
65
+ });
66
+ it("toggles on `Space`", async () => {
67
+ expect(el.selected).to.be.false;
68
+ el.focus();
69
+ await sendKeys({
70
+ press: "Space"
71
+ });
72
+ expect(el.selected).to.be.true;
73
+ });
74
+ it("toggles on `Enter`", async () => {
75
+ expect(el.selected).to.be.false;
76
+ el.focus();
77
+ await sendKeys({
78
+ press: "Enter"
79
+ });
80
+ expect(el.selected).to.be.true;
81
+ await sendKeys({
82
+ press: "NumpadEnter"
83
+ });
84
+ expect(el.selected).to.be.false;
85
+ });
86
+ it("dispatches `change`", async () => {
87
+ const changeSpy = spy();
88
+ el.addEventListener("change", () => changeSpy());
89
+ el.click();
90
+ expect(changeSpy.calledOnce).to.be.true;
91
+ });
92
+ it("does not dispatch `change` when [disabled]", async () => {
93
+ const changeSpy = spy();
94
+ el.addEventListener("change", () => changeSpy());
95
+ el.disabled = true;
96
+ await elementUpdated(el);
97
+ el.click();
98
+ expect(changeSpy.calledOnce).to.be.false;
99
+ });
100
+ it("does not dispatch `change` when [mixed-value]", async () => {
101
+ const changeSpy = spy();
102
+ el.addEventListener("change", () => changeSpy());
103
+ el.mixedValue = true;
104
+ await elementUpdated(el);
105
+ el.click();
106
+ expect(changeSpy.calledOnce).to.be.false;
107
+ });
108
+ it("can have `change` prevented", async () => {
109
+ el.addEventListener("change", (event) => {
110
+ event.preventDefault();
111
+ });
112
+ expect(el.selected).to.false;
113
+ el.click();
114
+ expect(el.selected).to.false;
115
+ });
116
+ it("is in the tab order", async () => {
117
+ const inputBefore = document.createElement("input");
118
+ const inputAfter = document.createElement("input");
119
+ el.insertAdjacentElement("beforebegin", inputBefore);
120
+ el.insertAdjacentElement("afterend", inputAfter);
121
+ inputBefore.focus();
122
+ expect(document.activeElement === el).to.be.false;
123
+ await sendKeys({
124
+ press: "Tab"
125
+ });
126
+ expect(document.activeElement === el).to.be.true;
127
+ await sendKeys({
128
+ press: "Tab"
129
+ });
130
+ expect(document.activeElement === el).to.be.false;
131
+ await sendKeys({
132
+ press: "Shift+Tab"
133
+ });
134
+ expect(document.activeElement === el).to.be.true;
135
+ });
136
+ it("is not in the tab order when [disabled]", async () => {
137
+ const inputBefore = document.createElement("input");
138
+ const inputAfter = document.createElement("input");
139
+ el.insertAdjacentElement("beforebegin", inputBefore);
140
+ el.insertAdjacentElement("afterend", inputAfter);
141
+ inputBefore.focus();
142
+ el.disabled = true;
143
+ await elementUpdated(el);
144
+ expect(document.activeElement === el).to.be.false;
145
+ await sendKeys({
146
+ press: "Tab"
147
+ });
148
+ expect(document.activeElement === el).to.be.false;
149
+ await sendKeys({
150
+ press: "Shift+Tab"
151
+ });
152
+ expect(document.activeElement === el).to.be.false;
153
+ });
154
+ });
155
+ //# sourceMappingURL=swatch.test.js.map