@spectrum-web-components/accordion 0.42.4 → 0.43.0
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.
- package/package.json +8 -8
- package/src/accordion-item.css.dev.js +1 -1
- package/src/accordion-item.css.dev.js.map +1 -1
- package/src/accordion-item.css.js +1 -1
- package/src/accordion-item.css.js.map +1 -1
- package/src/spectrum-accordion-item.css.dev.js +1 -1
- package/src/spectrum-accordion-item.css.dev.js.map +1 -1
- package/src/spectrum-accordion-item.css.js +1 -1
- package/src/spectrum-accordion-item.css.js.map +1 -1
- package/test/a11y-tree.test.js +24 -0
- package/test/a11y-tree.test.js.map +7 -0
- package/test/controlled.test.js +30 -0
- package/test/controlled.test.js.map +7 -0
- package/test/declarative.test.js +62 -0
- package/test/declarative.test.js.map +7 -0
- package/test/dev-mode.test.js +8 -0
- package/test/dev-mode.test.js.map +7 -0
- package/test/imperative.test.js +112 -0
- package/test/imperative.test.js.map +7 -0
- package/test/keyboard.test.js +199 -0
- package/test/keyboard.test.js.map +7 -0
- package/test/{accordion-memory.test.js → memory.test.js} +4 -2
- package/test/{accordion-memory.test.js.map → memory.test.js.map} +3 -3
- package/test/accordion-item.test.js +0 -144
- package/test/accordion-item.test.js.map +0 -7
- package/test/accordion.test.js +0 -271
- package/test/accordion.test.js.map +0 -7
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { elementUpdated, expect, fixture } from "@open-wc/testing";
|
|
3
|
+
import { Default } from "../stories/accordion.stories.js";
|
|
4
|
+
import { AccordionMarkup } from "../stories/index.js";
|
|
5
|
+
describe("Accordion - imperative interactions", () => {
|
|
6
|
+
it("manages item size", async () => {
|
|
7
|
+
const el = await fixture(
|
|
8
|
+
AccordionMarkup({
|
|
9
|
+
size: "l"
|
|
10
|
+
})
|
|
11
|
+
);
|
|
12
|
+
const item = el.querySelector("sp-accordion-item");
|
|
13
|
+
expect(el.size).to.equal("l");
|
|
14
|
+
expect(item.size).to.equal("l");
|
|
15
|
+
el.size = "s";
|
|
16
|
+
await elementUpdated(el);
|
|
17
|
+
await elementUpdated(item);
|
|
18
|
+
expect(el.size).to.equal("s");
|
|
19
|
+
expect(item.size).to.equal("s");
|
|
20
|
+
});
|
|
21
|
+
it("only allows one open item by default", async () => {
|
|
22
|
+
const el = await fixture(Default());
|
|
23
|
+
await elementUpdated(el);
|
|
24
|
+
const firstItem = el.querySelector(
|
|
25
|
+
"sp-accordion-item:nth-of-type(1)"
|
|
26
|
+
);
|
|
27
|
+
const secondItem = el.querySelector(
|
|
28
|
+
"sp-accordion-item:nth-of-type(2)"
|
|
29
|
+
);
|
|
30
|
+
const firstButton = firstItem.focusElement;
|
|
31
|
+
const secondButton = secondItem.focusElement;
|
|
32
|
+
firstButton.click();
|
|
33
|
+
await elementUpdated(el);
|
|
34
|
+
let openItems = el.querySelectorAll("sp-accordion-item[open]");
|
|
35
|
+
expect(openItems.length).to.equal(1);
|
|
36
|
+
secondButton.click();
|
|
37
|
+
await elementUpdated(el);
|
|
38
|
+
openItems = el.querySelectorAll("sp-accordion-item[open]");
|
|
39
|
+
expect(openItems.length).to.equal(1);
|
|
40
|
+
});
|
|
41
|
+
it("allows more than one open item when `[allow-multiple]`", async () => {
|
|
42
|
+
const el = await fixture(Default());
|
|
43
|
+
el.allowMultiple = true;
|
|
44
|
+
await elementUpdated(el);
|
|
45
|
+
const firstItem = el.querySelector(
|
|
46
|
+
"sp-accordion-item:nth-of-type(1)"
|
|
47
|
+
);
|
|
48
|
+
const secondItem = el.querySelector(
|
|
49
|
+
"sp-accordion-item:nth-of-type(2)"
|
|
50
|
+
);
|
|
51
|
+
const firstButton = firstItem.focusElement;
|
|
52
|
+
const secondButton = secondItem.focusElement;
|
|
53
|
+
firstButton.click();
|
|
54
|
+
await elementUpdated(el);
|
|
55
|
+
expect(firstItem.open).to.be.true;
|
|
56
|
+
expect(secondItem.open).to.be.false;
|
|
57
|
+
secondButton.click();
|
|
58
|
+
await elementUpdated(el);
|
|
59
|
+
expect(firstItem.open).to.be.true;
|
|
60
|
+
expect(secondItem.open).to.be.true;
|
|
61
|
+
});
|
|
62
|
+
it("ensures that the correct item is open and that items can be closed", async () => {
|
|
63
|
+
const el = await fixture(Default());
|
|
64
|
+
await elementUpdated(el);
|
|
65
|
+
const firstItem = el.querySelector(
|
|
66
|
+
"sp-accordion-item:nth-of-type(1)"
|
|
67
|
+
);
|
|
68
|
+
const secondItem = el.querySelector(
|
|
69
|
+
"sp-accordion-item:nth-of-type(2)"
|
|
70
|
+
);
|
|
71
|
+
const firstButton = firstItem.focusElement;
|
|
72
|
+
const secondButton = secondItem.focusElement;
|
|
73
|
+
firstButton.click();
|
|
74
|
+
await elementUpdated(el);
|
|
75
|
+
expect(firstItem.open).to.be.true;
|
|
76
|
+
expect(secondItem.open).to.be.false;
|
|
77
|
+
secondButton.click();
|
|
78
|
+
await elementUpdated(el);
|
|
79
|
+
expect(firstItem.open).to.be.false;
|
|
80
|
+
expect(secondItem.open).to.be.true;
|
|
81
|
+
secondButton.click();
|
|
82
|
+
await elementUpdated(el);
|
|
83
|
+
expect(firstItem.open).to.be.false;
|
|
84
|
+
expect(secondItem.open).to.be.false;
|
|
85
|
+
});
|
|
86
|
+
it("ensures that the correct item is open and that items can be closed when [allow-multiple]", async () => {
|
|
87
|
+
const el = await fixture(Default());
|
|
88
|
+
el.allowMultiple = true;
|
|
89
|
+
await elementUpdated(el);
|
|
90
|
+
const firstItem = el.querySelector(
|
|
91
|
+
"sp-accordion-item:nth-of-type(1)"
|
|
92
|
+
);
|
|
93
|
+
const secondItem = el.querySelector(
|
|
94
|
+
"sp-accordion-item:nth-of-type(2)"
|
|
95
|
+
);
|
|
96
|
+
const firstButton = firstItem.focusElement;
|
|
97
|
+
const secondButton = secondItem.focusElement;
|
|
98
|
+
firstButton.click();
|
|
99
|
+
await elementUpdated(el);
|
|
100
|
+
expect(firstItem.open).to.be.true;
|
|
101
|
+
expect(secondItem.open).to.be.false;
|
|
102
|
+
secondButton.click();
|
|
103
|
+
await elementUpdated(el);
|
|
104
|
+
expect(firstItem.open).to.be.true;
|
|
105
|
+
expect(secondItem.open).to.be.true;
|
|
106
|
+
secondButton.click();
|
|
107
|
+
await elementUpdated(el);
|
|
108
|
+
expect(firstItem.open).to.be.true;
|
|
109
|
+
expect(secondItem.open).to.be.false;
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=imperative.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["imperative.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\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 } from '@open-wc/testing';\n\nimport { Accordion, AccordionItem } from '@spectrum-web-components/accordion';\n\nimport { Default } from '../stories/accordion.stories.js';\nimport { AccordionMarkup } from '../stories/index.js';\n\ndescribe('Accordion - imperative interactions', () => {\n it('manages item size', async () => {\n const el = await fixture<Accordion>(\n AccordionMarkup({\n size: 'l',\n })\n );\n const item = el.querySelector('sp-accordion-item') as AccordionItem;\n expect(el.size).to.equal('l');\n expect(item.size).to.equal('l');\n\n el.size = 's';\n await elementUpdated(el);\n await elementUpdated(item);\n expect(el.size).to.equal('s');\n expect(item.size).to.equal('s');\n });\n it('only allows one open item by default', async () => {\n const el = await fixture<Accordion>(Default());\n await elementUpdated(el);\n const firstItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(1)'\n ) as AccordionItem;\n const secondItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(2)'\n ) as AccordionItem;\n\n const firstButton = firstItem.focusElement;\n const secondButton = secondItem.focusElement;\n\n firstButton.click();\n await elementUpdated(el);\n let openItems = el.querySelectorAll('sp-accordion-item[open]');\n expect(openItems.length).to.equal(1);\n\n secondButton.click();\n await elementUpdated(el);\n openItems = el.querySelectorAll('sp-accordion-item[open]');\n expect(openItems.length).to.equal(1);\n });\n it('allows more than one open item when `[allow-multiple]`', async () => {\n const el = await fixture<Accordion>(Default());\n el.allowMultiple = true;\n await elementUpdated(el);\n\n const firstItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(1)'\n ) as AccordionItem;\n const secondItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(2)'\n ) as AccordionItem;\n\n const firstButton = firstItem.focusElement;\n const secondButton = secondItem.focusElement;\n\n firstButton.click();\n await elementUpdated(el);\n\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.false;\n\n secondButton.click();\n await elementUpdated(el);\n\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.true;\n });\n it('ensures that the correct item is open and that items can be closed', async () => {\n const el = await fixture<Accordion>(Default());\n\n await elementUpdated(el);\n const firstItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(1)'\n ) as AccordionItem;\n const secondItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(2)'\n ) as AccordionItem;\n\n const firstButton = firstItem.focusElement;\n const secondButton = secondItem.focusElement;\n\n firstButton.click();\n await elementUpdated(el);\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.false;\n\n secondButton.click();\n await elementUpdated(el);\n expect(firstItem.open).to.be.false;\n expect(secondItem.open).to.be.true;\n\n secondButton.click();\n await elementUpdated(el);\n expect(firstItem.open).to.be.false;\n expect(secondItem.open).to.be.false;\n });\n it('ensures that the correct item is open and that items can be closed when [allow-multiple]', async () => {\n const el = await fixture<Accordion>(Default());\n el.allowMultiple = true;\n await elementUpdated(el);\n\n const firstItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(1)'\n ) as AccordionItem;\n const secondItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(2)'\n ) as AccordionItem;\n\n const firstButton = firstItem.focusElement;\n const secondButton = secondItem.focusElement;\n\n firstButton.click();\n await elementUpdated(el);\n\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.false;\n\n secondButton.click();\n await elementUpdated(el);\n\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.true;\n\n secondButton.click();\n await elementUpdated(el);\n\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.false;\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAWA,SAAS,gBAAgB,QAAQ,eAAe;AAIhD,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAEhC,SAAS,uCAAuC,MAAM;AAClD,KAAG,qBAAqB,YAAY;AAChC,UAAM,KAAK,MAAM;AAAA,MACb,gBAAgB;AAAA,QACZ,MAAM;AAAA,MACV,CAAC;AAAA,IACL;AACA,UAAM,OAAO,GAAG,cAAc,mBAAmB;AACjD,WAAO,GAAG,IAAI,EAAE,GAAG,MAAM,GAAG;AAC5B,WAAO,KAAK,IAAI,EAAE,GAAG,MAAM,GAAG;AAE9B,OAAG,OAAO;AACV,UAAM,eAAe,EAAE;AACvB,UAAM,eAAe,IAAI;AACzB,WAAO,GAAG,IAAI,EAAE,GAAG,MAAM,GAAG;AAC5B,WAAO,KAAK,IAAI,EAAE,GAAG,MAAM,GAAG;AAAA,EAClC,CAAC;AACD,KAAG,wCAAwC,YAAY;AACnD,UAAM,KAAK,MAAM,QAAmB,QAAQ,CAAC;AAC7C,UAAM,eAAe,EAAE;AACvB,UAAM,YAAY,GAAG;AAAA,MACjB;AAAA,IACJ;AACA,UAAM,aAAa,GAAG;AAAA,MAClB;AAAA,IACJ;AAEA,UAAM,cAAc,UAAU;AAC9B,UAAM,eAAe,WAAW;AAEhC,gBAAY,MAAM;AAClB,UAAM,eAAe,EAAE;AACvB,QAAI,YAAY,GAAG,iBAAiB,y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GAAG,GAAG;AAE9B,iBAAa,MAAM;AACnB,UAAM,eAAe,EAAE;AACvB,WAAO,UAAU,IAAI,EAAE,GAAG,GAAG;AAC7B,WAAO,WAAW,IAAI,EAAE,GAAG,GAAG;AAAA,EAClC,CAAC;AACD,KAAG,4FAA4F,YAAY;AACvG,UAAM,KAAK,MAAM,QAAmB,QAAQ,CAAC;AAC7C,OAAG,gBAAgB;AACnB,UAAM,eAAe,EAAE;AAEvB,UAAM,YAAY,GAAG;AAAA,MACjB;AAAA,IACJ;AACA,UAAM,aAAa,GAAG;AAAA,MAClB;AAAA,IACJ;AAEA,UAAM,cAAc,UAAU;AAC9B,UAAM,eAAe,WAAW;AAEhC,gBAAY,MAAM;AAClB,UAAM,eAAe,EAAE;AAEvB,WAAO,UAAU,IAAI,EAAE,GAAG,GAAG;AAC7B,WAAO,WAAW,IAAI,EAAE,GAAG,GAAG;AAE9B,iBAAa,MAAM;AACnB,UAAM,eAAe,EAAE;AAEvB,WAAO,UAAU,IAAI,EAAE,GAAG,GAAG;AAC7B,WAAO,WAAW,IAAI,EAAE,GAAG,GAAG;AAE9B,iBAAa,MAAM;AACnB,UAAM,eAAe,EAAE;AAEvB,WAAO,UAAU,IAAI,EAAE,GAAG,GAAG;AAC7B,WAAO,WAAW,IAAI,EAAE,GAAG,GAAG;AAAA,EAClC,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { html } from "@spectrum-web-components/base";
|
|
3
|
+
import { elementUpdated, expect, fixture } from "@open-wc/testing";
|
|
4
|
+
import { sendKeys } from "@web/test-runner-commands";
|
|
5
|
+
import { spy } from "sinon";
|
|
6
|
+
import { Accordion, AccordionItem } from "@spectrum-web-components/accordion";
|
|
7
|
+
import "@spectrum-web-components/accordion/sp-accordion.js";
|
|
8
|
+
import "@spectrum-web-components/accordion/sp-accordion-item.js";
|
|
9
|
+
describe("Accordion - keyboard", () => {
|
|
10
|
+
it("does not accept keyboard events when items are not present", async () => {
|
|
11
|
+
const errorSpy = spy();
|
|
12
|
+
const el = await fixture(html`
|
|
13
|
+
<sp-accordion>
|
|
14
|
+
<sp-accordion-item disabled label="Heading 2">
|
|
15
|
+
<div>Item 2</div>
|
|
16
|
+
</sp-accordion-item>
|
|
17
|
+
</sp-accordion>
|
|
18
|
+
`);
|
|
19
|
+
await elementUpdated(el);
|
|
20
|
+
const item = el.querySelector("sp-accordion-item");
|
|
21
|
+
window.addEventListener("error", () => errorSpy());
|
|
22
|
+
el.focus();
|
|
23
|
+
item.remove();
|
|
24
|
+
await elementUpdated(el);
|
|
25
|
+
el.dispatchEvent(
|
|
26
|
+
new KeyboardEvent("keydown", {
|
|
27
|
+
code: "ArrowDown"
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
expect(errorSpy.callCount).to.equal(0);
|
|
31
|
+
});
|
|
32
|
+
it("handles focus and keyboard input and ignores disabled items", async () => {
|
|
33
|
+
var _a;
|
|
34
|
+
const el = await fixture(html`
|
|
35
|
+
<sp-accordion allow-multiple>
|
|
36
|
+
<sp-accordion-item disabled label="Heading 1">
|
|
37
|
+
<div>Item 1</div>
|
|
38
|
+
</sp-accordion-item>
|
|
39
|
+
<sp-accordion-item label="Heading 2">
|
|
40
|
+
<div>Item 2</div>
|
|
41
|
+
</sp-accordion-item>
|
|
42
|
+
<sp-accordion-item label="Heading 3">
|
|
43
|
+
<div>Item 3</div>
|
|
44
|
+
</sp-accordion-item>
|
|
45
|
+
<sp-accordion-item label="Heading 4">
|
|
46
|
+
<div>Item 4</div>
|
|
47
|
+
</sp-accordion-item>
|
|
48
|
+
<sp-accordion-item label="Heading 5">
|
|
49
|
+
<div>Item 5</div>
|
|
50
|
+
</sp-accordion-item>
|
|
51
|
+
<sp-accordion-item disabled label="Heading 6">
|
|
52
|
+
<div>Item 6</div>
|
|
53
|
+
</sp-accordion-item>
|
|
54
|
+
</sp-accordion>
|
|
55
|
+
`);
|
|
56
|
+
await elementUpdated(el);
|
|
57
|
+
const secondItem = el.querySelector(
|
|
58
|
+
"sp-accordion-item:nth-of-type(2)"
|
|
59
|
+
);
|
|
60
|
+
const thirdItem = el.querySelector(
|
|
61
|
+
"sp-accordion-item:nth-of-type(3)"
|
|
62
|
+
);
|
|
63
|
+
const fourthItem = el.querySelector(
|
|
64
|
+
"sp-accordion-item:nth-of-type(4)"
|
|
65
|
+
);
|
|
66
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(
|
|
67
|
+
navigator.userAgent
|
|
68
|
+
);
|
|
69
|
+
const tab = isSafari ? "Alt+Tab" : "Tab";
|
|
70
|
+
const shiftTab = isSafari ? "Alt+Shift+Tab" : "Shift+Tab";
|
|
71
|
+
el.focus();
|
|
72
|
+
await elementUpdated(el);
|
|
73
|
+
expect(
|
|
74
|
+
document.activeElement === secondItem,
|
|
75
|
+
(_a = document.activeElement) == null ? void 0 : _a.localName
|
|
76
|
+
).to.be.true;
|
|
77
|
+
await sendKeys({
|
|
78
|
+
press: tab
|
|
79
|
+
});
|
|
80
|
+
expect(document.activeElement === thirdItem).to.be.true;
|
|
81
|
+
await sendKeys({
|
|
82
|
+
press: tab
|
|
83
|
+
});
|
|
84
|
+
expect(document.activeElement === fourthItem).to.be.true;
|
|
85
|
+
await sendKeys({
|
|
86
|
+
press: shiftTab
|
|
87
|
+
});
|
|
88
|
+
await sendKeys({
|
|
89
|
+
press: shiftTab
|
|
90
|
+
});
|
|
91
|
+
expect(document.activeElement === secondItem).to.be.true;
|
|
92
|
+
document.body.focus();
|
|
93
|
+
el.focus();
|
|
94
|
+
expect(document.activeElement === secondItem).to.be.true;
|
|
95
|
+
await sendKeys({
|
|
96
|
+
press: shiftTab
|
|
97
|
+
});
|
|
98
|
+
await elementUpdated(el);
|
|
99
|
+
const outsideFocused = document.activeElement;
|
|
100
|
+
expect(typeof outsideFocused).not.to.equal(AccordionItem);
|
|
101
|
+
expect(typeof outsideFocused).not.to.equal(Accordion);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("Accordion Item - keyboard", () => {
|
|
105
|
+
it("dispatches toggle event on enter key", async () => {
|
|
106
|
+
let open = false;
|
|
107
|
+
const onAccordionToggle = () => {
|
|
108
|
+
open = true;
|
|
109
|
+
};
|
|
110
|
+
const el = await fixture(html`
|
|
111
|
+
<sp-accordion-item
|
|
112
|
+
disabled
|
|
113
|
+
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
114
|
+
>
|
|
115
|
+
<div>Item 1</div>
|
|
116
|
+
</sp-accordion-item>
|
|
117
|
+
`);
|
|
118
|
+
await elementUpdated(el);
|
|
119
|
+
expect(open).to.be.false;
|
|
120
|
+
el.focus();
|
|
121
|
+
await sendKeys({
|
|
122
|
+
press: "Enter"
|
|
123
|
+
});
|
|
124
|
+
await elementUpdated(el);
|
|
125
|
+
expect(open).to.be.false;
|
|
126
|
+
el.disabled = false;
|
|
127
|
+
await elementUpdated(el);
|
|
128
|
+
el.focus();
|
|
129
|
+
await sendKeys({
|
|
130
|
+
press: "Enter"
|
|
131
|
+
});
|
|
132
|
+
await elementUpdated(el);
|
|
133
|
+
expect(open).to.be.true;
|
|
134
|
+
});
|
|
135
|
+
it("dispatches toggle event on space key", async () => {
|
|
136
|
+
let open = false;
|
|
137
|
+
const onAccordionToggle = () => {
|
|
138
|
+
open = true;
|
|
139
|
+
};
|
|
140
|
+
const el = await fixture(html`
|
|
141
|
+
<sp-accordion-item
|
|
142
|
+
disabled
|
|
143
|
+
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
144
|
+
>
|
|
145
|
+
<div>Item 1</div>
|
|
146
|
+
</sp-accordion-item>
|
|
147
|
+
`);
|
|
148
|
+
await elementUpdated(el);
|
|
149
|
+
expect(open).to.be.false;
|
|
150
|
+
el.focus();
|
|
151
|
+
await sendKeys({
|
|
152
|
+
press: "Space"
|
|
153
|
+
});
|
|
154
|
+
await elementUpdated(el);
|
|
155
|
+
expect(open).to.be.false;
|
|
156
|
+
el.disabled = false;
|
|
157
|
+
await elementUpdated(el);
|
|
158
|
+
el.focus();
|
|
159
|
+
await sendKeys({
|
|
160
|
+
press: "Space"
|
|
161
|
+
});
|
|
162
|
+
await elementUpdated(el);
|
|
163
|
+
expect(open).to.be.true;
|
|
164
|
+
});
|
|
165
|
+
it("does not dispatch toggle events on key events in Item content", async () => {
|
|
166
|
+
let closed = false;
|
|
167
|
+
const onAccordionToggle = () => {
|
|
168
|
+
closed = true;
|
|
169
|
+
};
|
|
170
|
+
const el = await fixture(html`
|
|
171
|
+
<sp-accordion-item
|
|
172
|
+
open
|
|
173
|
+
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
174
|
+
>
|
|
175
|
+
<div>
|
|
176
|
+
<button>Test Button</button>
|
|
177
|
+
</div>
|
|
178
|
+
</sp-accordion-item>
|
|
179
|
+
`);
|
|
180
|
+
const button = el.querySelector("button");
|
|
181
|
+
await elementUpdated(el);
|
|
182
|
+
expect(el.open).to.be.true;
|
|
183
|
+
expect(closed).to.be.false;
|
|
184
|
+
button.focus();
|
|
185
|
+
await sendKeys({
|
|
186
|
+
press: "Space"
|
|
187
|
+
});
|
|
188
|
+
await elementUpdated(el);
|
|
189
|
+
expect(closed).to.be.false;
|
|
190
|
+
await elementUpdated(el);
|
|
191
|
+
await sendKeys({
|
|
192
|
+
press: "Enter"
|
|
193
|
+
});
|
|
194
|
+
await elementUpdated(el);
|
|
195
|
+
expect(closed).to.be.false;
|
|
196
|
+
expect(el.open).to.be.true;
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
//# sourceMappingURL=keyboard.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["keyboard.test.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 { html } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture } from '@open-wc/testing';\nimport { sendKeys } from '@web/test-runner-commands';\nimport { spy } from 'sinon';\n\nimport { Accordion, AccordionItem } from '@spectrum-web-components/accordion';\nimport '@spectrum-web-components/accordion/sp-accordion.js';\nimport '@spectrum-web-components/accordion/sp-accordion-item.js';\n\ndescribe('Accordion - keyboard', () => {\n it('does not accept keyboard events when items are not present', async () => {\n const errorSpy = spy();\n const el = await fixture<Accordion>(html`\n <sp-accordion>\n <sp-accordion-item disabled label=\"Heading 2\">\n <div>Item 2</div>\n </sp-accordion-item>\n </sp-accordion>\n `);\n\n await elementUpdated(el);\n const item = el.querySelector('sp-accordion-item') as AccordionItem;\n window.addEventListener('error', () => errorSpy());\n\n el.focus();\n item.remove();\n await elementUpdated(el);\n el.dispatchEvent(\n new KeyboardEvent('keydown', {\n code: 'ArrowDown',\n })\n );\n\n expect(errorSpy.callCount).to.equal(0);\n });\n it('handles focus and keyboard input and ignores disabled items', async () => {\n const el = await fixture<Accordion>(html`\n <sp-accordion allow-multiple>\n <sp-accordion-item disabled label=\"Heading 1\">\n <div>Item 1</div>\n </sp-accordion-item>\n <sp-accordion-item label=\"Heading 2\">\n <div>Item 2</div>\n </sp-accordion-item>\n <sp-accordion-item label=\"Heading 3\">\n <div>Item 3</div>\n </sp-accordion-item>\n <sp-accordion-item label=\"Heading 4\">\n <div>Item 4</div>\n </sp-accordion-item>\n <sp-accordion-item label=\"Heading 5\">\n <div>Item 5</div>\n </sp-accordion-item>\n <sp-accordion-item disabled label=\"Heading 6\">\n <div>Item 6</div>\n </sp-accordion-item>\n </sp-accordion>\n `);\n\n await elementUpdated(el);\n\n const secondItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(2)'\n ) as AccordionItem;\n const thirdItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(3)'\n ) as AccordionItem;\n const fourthItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(4)'\n ) as AccordionItem;\n const isSafari = /^((?!chrome|android).)*safari/i.test(\n navigator.userAgent\n );\n const tab = isSafari ? 'Alt+Tab' : 'Tab';\n const shiftTab = isSafari ? 'Alt+Shift+Tab' : 'Shift+Tab';\n\n el.focus();\n\n await elementUpdated(el);\n expect(\n document.activeElement === secondItem,\n document.activeElement?.localName\n ).to.be.true;\n\n await sendKeys({\n press: tab,\n });\n\n expect(document.activeElement === thirdItem).to.be.true;\n\n await sendKeys({\n press: tab,\n });\n\n expect(document.activeElement === fourthItem).to.be.true;\n\n await sendKeys({\n press: shiftTab,\n });\n await sendKeys({\n press: shiftTab,\n });\n\n expect(document.activeElement === secondItem).to.be.true;\n\n document.body.focus();\n\n el.focus();\n expect(document.activeElement === secondItem).to.be.true;\n\n await sendKeys({\n press: shiftTab,\n });\n await elementUpdated(el);\n\n const outsideFocused = document.activeElement as HTMLElement;\n\n expect(typeof outsideFocused).not.to.equal(AccordionItem);\n expect(typeof outsideFocused).not.to.equal(Accordion);\n });\n});\n\ndescribe('Accordion Item - keyboard', () => {\n it('dispatches toggle event on enter key', async () => {\n let open = false;\n const onAccordionToggle = (): void => {\n open = true;\n };\n const el = await fixture<AccordionItem>(html`\n <sp-accordion-item\n disabled\n @sp-accordion-item-toggle=${onAccordionToggle}\n >\n <div>Item 1</div>\n </sp-accordion-item>\n `);\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.focus();\n await sendKeys({\n press: 'Enter',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.disabled = false;\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n press: 'Enter',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.true;\n });\n it('dispatches toggle event on space key', async () => {\n let open = false;\n const onAccordionToggle = (): void => {\n open = true;\n };\n const el = await fixture<AccordionItem>(html`\n <sp-accordion-item\n disabled\n @sp-accordion-item-toggle=${onAccordionToggle}\n >\n <div>Item 1</div>\n </sp-accordion-item>\n `);\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.focus();\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.disabled = false;\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.true;\n });\n it('does not dispatch toggle events on key events in Item content', async () => {\n let closed = false;\n const onAccordionToggle = (): void => {\n closed = true;\n };\n const el = await fixture<AccordionItem>(html`\n <sp-accordion-item\n open\n @sp-accordion-item-toggle=${onAccordionToggle}\n >\n <div>\n <button>Test Button</button>\n </div>\n </sp-accordion-item>\n `);\n\n const button = el.querySelector('button') as HTMLButtonElement;\n await elementUpdated(el);\n\n expect(el.open).to.be.true;\n expect(closed).to.be.false;\n\n button.focus();\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(closed).to.be.false;\n\n await elementUpdated(el);\n\n await sendKeys({\n press: 'Enter',\n });\n\n await elementUpdated(el);\n\n expect(closed).to.be.false;\n expect(el.open).to.be.true;\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,YAAY;AACrB,SAAS,gBAAgB,QAAQ,eAAe;AAChD,SAAS,gBAAgB;AACzB,SAAS,WAAW;AAEpB,SAAS,WAAW,qBAAqB;AACzC,OAAO;AACP,OAAO;AAEP,SAAS,wBAAwB,MAAM;AACnC,KAAG,8DAA8D,YAAY;AACzE,UAAM,WAAW,IAAI;AACrB,UAAM,KAAK,MAAM,QAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAMnC;AAED,UAAM,eAAe,EAAE;AACvB,UAAM,OAAO,GAAG,cAAc,mBAAmB;AACjD,WAAO,iBAAiB,SAAS,MAAM,SAAS,CAAC;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AEvB,WAAO,IAAI,EAAE,GAAG,GAAG;AAEnB,OAAG,WAAW;AACd,UAAM,eAAe,EAAE;AAEvB,OAAG,MAAM;AACT,UAAM,SAAS;AAAA,MACX,OAAO;AAAA,IACX,CAAC;AAED,UAAM,eAAe,EAAE;AAEvB,WAAO,IAAI,EAAE,GAAG,GAAG;AAAA,EACvB,CAAC;AACD,KAAG,iEAAiE,YAAY;AAC5E,QAAI,SAAS;AACb,UAAM,oBAAoB,MAAY;AAClC,eAAS;AAAA,IACb;AACA,UAAM,KAAK,MAAM,QAAuB;AAAA;AAAA;AAAA,4CAGJ,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAMpD;AAED,UAAM,SAAS,GAAG,cAAc,QAAQ;AACxC,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,IAAI,EAAE,GAAG,GAAG;AACtB,WAAO,MAAM,EAAE,GAAG,GAAG;AAErB,WAAO,MAAM;AACb,UAAM,SAAS;AAAA,MACX,OAAO;AAAA,IACX,CAAC;AAED,UAAM,eAAe,EAAE;AAEvB,WAAO,MAAM,EAAE,GAAG,GAAG;AAErB,UAAM,eAAe,EAAE;AAEvB,UAAM,SAAS;AAAA,MACX,OAAO;AAAA,IACX,CAAC;AAED,UAAM,eAAe,EAAE;AAEvB,WAAO,MAAM,EAAE,GAAG,GAAG;AACrB,WAAO,GAAG,IAAI,EAAE,GAAG,GAAG;AAAA,EAC1B,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Default } from "../stories/accordion.stories.js";
|
|
3
3
|
import { testForMemoryLeaks } from "../../../test/testing-helpers.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
describe("Accordion - memory usage", () => {
|
|
5
|
+
testForMemoryLeaks(Default());
|
|
6
|
+
});
|
|
7
|
+
//# sourceMappingURL=memory.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
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\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 { Default } from '../stories/accordion.stories.js';\nimport { testForMemoryLeaks } from '../../../test/testing-helpers.js';\n\
|
|
5
|
-
"mappings": ";AAYA,SAAS,eAAe;AACxB,SAAS,0BAA0B;AAEnC,
|
|
3
|
+
"sources": ["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\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 { Default } from '../stories/accordion.stories.js';\nimport { testForMemoryLeaks } from '../../../test/testing-helpers.js';\n\ndescribe('Accordion - memory usage', () => {\n testForMemoryLeaks(Default());\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,eAAe;AACxB,SAAS,0BAA0B;AAEnC,SAAS,4BAA4B,MAAM;AACvC,qBAAmB,QAAQ,CAAC;AAChC,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
3
|
-
import { spy } from "sinon";
|
|
4
|
-
import "@spectrum-web-components/accordion/sp-accordion-item.js";
|
|
5
|
-
import { sendKeys } from "@web/test-runner-commands";
|
|
6
|
-
describe("Accordion Item", () => {
|
|
7
|
-
it("can exist with no parent accessibly", async () => {
|
|
8
|
-
const el = await fixture(
|
|
9
|
-
html`
|
|
10
|
-
<sp-accordion-item label="item">
|
|
11
|
-
<div>Item 1</div>
|
|
12
|
-
</sp-accordion-item>
|
|
13
|
-
`
|
|
14
|
-
);
|
|
15
|
-
await elementUpdated(el);
|
|
16
|
-
await expect(el).to.be.accessible();
|
|
17
|
-
});
|
|
18
|
-
it("can be `[disabled]`", async () => {
|
|
19
|
-
const toggleSpy = spy();
|
|
20
|
-
const handleToggle = () => toggleSpy();
|
|
21
|
-
const el = await fixture(
|
|
22
|
-
html`
|
|
23
|
-
<sp-accordion-item
|
|
24
|
-
disabled
|
|
25
|
-
@sp-accordion-item-toggle=${handleToggle}
|
|
26
|
-
>
|
|
27
|
-
<div>Item 1</div>
|
|
28
|
-
</sp-accordion-item>
|
|
29
|
-
`
|
|
30
|
-
);
|
|
31
|
-
const root = el.shadowRoot;
|
|
32
|
-
const button = root.querySelector("#header");
|
|
33
|
-
await elementUpdated(el);
|
|
34
|
-
expect(toggleSpy.callCount).to.equal(0);
|
|
35
|
-
button.click();
|
|
36
|
-
await elementUpdated(el);
|
|
37
|
-
expect(toggleSpy.callCount).to.equal(0);
|
|
38
|
-
el.disabled = false;
|
|
39
|
-
await elementUpdated(el);
|
|
40
|
-
button.click();
|
|
41
|
-
await elementUpdated(el);
|
|
42
|
-
expect(toggleSpy.callCount).to.equal(1);
|
|
43
|
-
});
|
|
44
|
-
it("dispatches toggle event on enter key", async () => {
|
|
45
|
-
let open = false;
|
|
46
|
-
const onAccordionToggle = () => {
|
|
47
|
-
open = true;
|
|
48
|
-
};
|
|
49
|
-
const el = await fixture(
|
|
50
|
-
html`
|
|
51
|
-
<sp-accordion-item
|
|
52
|
-
disabled
|
|
53
|
-
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
54
|
-
>
|
|
55
|
-
<div>Item 1</div>
|
|
56
|
-
</sp-accordion-item>
|
|
57
|
-
`
|
|
58
|
-
);
|
|
59
|
-
await elementUpdated(el);
|
|
60
|
-
expect(open).to.be.false;
|
|
61
|
-
el.focus();
|
|
62
|
-
await sendKeys({
|
|
63
|
-
press: "Enter"
|
|
64
|
-
});
|
|
65
|
-
await elementUpdated(el);
|
|
66
|
-
expect(open).to.be.false;
|
|
67
|
-
el.disabled = false;
|
|
68
|
-
await elementUpdated(el);
|
|
69
|
-
el.focus();
|
|
70
|
-
await sendKeys({
|
|
71
|
-
press: "Enter"
|
|
72
|
-
});
|
|
73
|
-
await elementUpdated(el);
|
|
74
|
-
expect(open).to.be.true;
|
|
75
|
-
});
|
|
76
|
-
it("dispatches toggle event on space key", async () => {
|
|
77
|
-
let open = false;
|
|
78
|
-
const onAccordionToggle = () => {
|
|
79
|
-
open = true;
|
|
80
|
-
};
|
|
81
|
-
const el = await fixture(
|
|
82
|
-
html`
|
|
83
|
-
<sp-accordion-item
|
|
84
|
-
disabled
|
|
85
|
-
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
86
|
-
>
|
|
87
|
-
<div>Item 1</div>
|
|
88
|
-
</sp-accordion-item>
|
|
89
|
-
`
|
|
90
|
-
);
|
|
91
|
-
await elementUpdated(el);
|
|
92
|
-
expect(open).to.be.false;
|
|
93
|
-
el.focus();
|
|
94
|
-
await sendKeys({
|
|
95
|
-
press: "Space"
|
|
96
|
-
});
|
|
97
|
-
await elementUpdated(el);
|
|
98
|
-
expect(open).to.be.false;
|
|
99
|
-
el.disabled = false;
|
|
100
|
-
await elementUpdated(el);
|
|
101
|
-
el.focus();
|
|
102
|
-
await sendKeys({
|
|
103
|
-
press: "Space"
|
|
104
|
-
});
|
|
105
|
-
await elementUpdated(el);
|
|
106
|
-
expect(open).to.be.true;
|
|
107
|
-
});
|
|
108
|
-
it("does not dispatch toggle events on key events in Item content", async () => {
|
|
109
|
-
let closed = false;
|
|
110
|
-
const onAccordionToggle = () => {
|
|
111
|
-
closed = true;
|
|
112
|
-
};
|
|
113
|
-
const el = await fixture(
|
|
114
|
-
html`
|
|
115
|
-
<sp-accordion-item
|
|
116
|
-
open
|
|
117
|
-
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
118
|
-
>
|
|
119
|
-
<div>
|
|
120
|
-
<button>Test Button</button>
|
|
121
|
-
</div>
|
|
122
|
-
</sp-accordion-item>
|
|
123
|
-
`
|
|
124
|
-
);
|
|
125
|
-
const button = el.querySelector("button");
|
|
126
|
-
await elementUpdated(el);
|
|
127
|
-
expect(el.open).to.be.true;
|
|
128
|
-
expect(closed).to.be.false;
|
|
129
|
-
button.focus();
|
|
130
|
-
await sendKeys({
|
|
131
|
-
press: "Space"
|
|
132
|
-
});
|
|
133
|
-
await elementUpdated(el);
|
|
134
|
-
expect(closed).to.be.false;
|
|
135
|
-
await elementUpdated(el);
|
|
136
|
-
await sendKeys({
|
|
137
|
-
press: "Enter"
|
|
138
|
-
});
|
|
139
|
-
await elementUpdated(el);
|
|
140
|
-
expect(closed).to.be.false;
|
|
141
|
-
expect(el.open).to.be.true;
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
//# sourceMappingURL=accordion-item.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["accordion-item.test.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 { elementUpdated, expect, fixture, html } from '@open-wc/testing';\nimport { spy } from 'sinon';\n\nimport '@spectrum-web-components/accordion/sp-accordion-item.js';\nimport { AccordionItem } from '@spectrum-web-components/accordion/src/AccordionItem.js';\nimport { sendKeys } from '@web/test-runner-commands';\n\ndescribe('Accordion Item', () => {\n it('can exist with no parent accessibly', async () => {\n const el = await fixture<AccordionItem>(\n html`\n <sp-accordion-item label=\"item\">\n <div>Item 1</div>\n </sp-accordion-item>\n `\n );\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('can be `[disabled]`', async () => {\n const toggleSpy = spy();\n const handleToggle = (): void => toggleSpy();\n const el = await fixture<AccordionItem>(\n html`\n <sp-accordion-item\n disabled\n @sp-accordion-item-toggle=${handleToggle}\n >\n <div>Item 1</div>\n </sp-accordion-item>\n `\n );\n\n const root = el.shadowRoot as ShadowRoot;\n const button = root.querySelector('#header') as HTMLElement;\n\n await elementUpdated(el);\n\n expect(toggleSpy.callCount).to.equal(0);\n\n button.click();\n\n await elementUpdated(el);\n\n expect(toggleSpy.callCount).to.equal(0);\n\n el.disabled = false;\n await elementUpdated(el);\n\n button.click();\n\n await elementUpdated(el);\n\n expect(toggleSpy.callCount).to.equal(1);\n });\n\n it('dispatches toggle event on enter key', async () => {\n let open = false;\n const onAccordionToggle = (): void => {\n open = true;\n };\n const el = await fixture<AccordionItem>(\n html`\n <sp-accordion-item\n disabled\n @sp-accordion-item-toggle=${onAccordionToggle}\n >\n <div>Item 1</div>\n </sp-accordion-item>\n `\n );\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.focus();\n await sendKeys({\n press: 'Enter',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.disabled = false;\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n press: 'Enter',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.true;\n });\n\n it('dispatches toggle event on space key', async () => {\n let open = false;\n const onAccordionToggle = (): void => {\n open = true;\n };\n const el = await fixture<AccordionItem>(\n html`\n <sp-accordion-item\n disabled\n @sp-accordion-item-toggle=${onAccordionToggle}\n >\n <div>Item 1</div>\n </sp-accordion-item>\n `\n );\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.focus();\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.disabled = false;\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(open).to.be.true;\n });\n\n it('does not dispatch toggle events on key events in Item content', async () => {\n let closed = false;\n const onAccordionToggle = (): void => {\n closed = true;\n };\n const el = await fixture<AccordionItem>(\n html`\n <sp-accordion-item\n open\n @sp-accordion-item-toggle=${onAccordionToggle}\n >\n <div>\n <button>Test Button</button>\n </div>\n </sp-accordion-item>\n `\n );\n\n const button = el.querySelector('button') as HTMLButtonElement;\n await elementUpdated(el);\n\n expect(el.open).to.be.true;\n expect(closed).to.be.false;\n\n button.focus();\n await sendKeys({\n press: 'Space',\n });\n\n await elementUpdated(el);\n\n expect(closed).to.be.false;\n\n await elementUpdated(el);\n\n await sendKeys({\n press: 'Enter',\n });\n\n await elementUpdated(el);\n\n expect(closed).to.be.false;\n expect(el.open).to.be.true;\n });\n});\n"],
|
|
5
|
-
"mappings": ";AAYA,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AACtD,SAAS,WAAW;AAEpB,OAAO;AAEP,SAAS,gBAAgB;AAEzB,SAAS,kBAAkB,MAAM;AAC7B,KAAG,uCAAuC,YAAY;AAClD,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA;AAAA;AAAA,IAKJ;AAEA,UAAM,eAAe,EAAE;AAEvB,UAAM,OAAO,EAAE,EAAE,GAAG,GAAG,WAAW;AAAA,EACtC,CAAC;AACD,KAAG,uBAAuB,YAAY;AAClC,UAAM,YAAY,IAAI;AACtB,UAAM,eAAe,MAAY,UAAU;AAC3C,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;A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