@spectrum-web-components/accordion 0.6.7 → 0.6.8
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 +3 -3
- package/test/accordion-item.test.js +99 -0
- package/test/accordion-item.test.js.map +1 -0
- package/test/accordion.test-vrt.js +15 -0
- package/test/accordion.test-vrt.js.map +1 -0
- package/test/accordion.test.js +209 -0
- package/test/accordion.test.js.map +1 -0
- package/test/benchmark/basic-test.js +38 -0
- package/test/benchmark/basic-test.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/accordion",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@spectrum-web-components/icon": "^0.11.5",
|
|
51
51
|
"@spectrum-web-components/icons-ui": "^0.8.5",
|
|
52
52
|
"@spectrum-web-components/reactive-controllers": "^0.2.2",
|
|
53
|
-
"@spectrum-web-components/shared": "^0.13.
|
|
53
|
+
"@spectrum-web-components/shared": "^0.13.7",
|
|
54
54
|
"tslib": "^2.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"sideEffects": [
|
|
62
62
|
"./sp-*.js"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "dd76f9532fdea946880147cc7645f113b998c326"
|
|
65
65
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
|
13
|
+
import { spy } from 'sinon';
|
|
14
|
+
import '../sp-accordion-item.js';
|
|
15
|
+
import { enterEvent, spaceEvent } from '../../../test/testing-helpers.js';
|
|
16
|
+
describe('Accordion Item', () => {
|
|
17
|
+
it('can exist with no parent accessibly', async () => {
|
|
18
|
+
const el = await fixture(html `
|
|
19
|
+
<sp-accordion-item label="item">
|
|
20
|
+
<div>Item 1</div>
|
|
21
|
+
</sp-accordion-item>
|
|
22
|
+
`);
|
|
23
|
+
await elementUpdated(el);
|
|
24
|
+
await expect(el).to.be.accessible();
|
|
25
|
+
});
|
|
26
|
+
it('can be `[disabled]`', async () => {
|
|
27
|
+
const toggleSpy = spy();
|
|
28
|
+
const handleToggle = () => toggleSpy();
|
|
29
|
+
const el = await fixture(html `
|
|
30
|
+
<sp-accordion-item
|
|
31
|
+
disabled
|
|
32
|
+
@sp-accordion-item-toggle=${handleToggle}
|
|
33
|
+
>
|
|
34
|
+
<div>Item 1</div>
|
|
35
|
+
</sp-accordion-item>
|
|
36
|
+
`);
|
|
37
|
+
const root = el.shadowRoot;
|
|
38
|
+
const button = root.querySelector('#header');
|
|
39
|
+
await elementUpdated(el);
|
|
40
|
+
expect(toggleSpy.callCount).to.equal(0);
|
|
41
|
+
button.click();
|
|
42
|
+
await elementUpdated(el);
|
|
43
|
+
expect(toggleSpy.callCount).to.equal(0);
|
|
44
|
+
el.disabled = false;
|
|
45
|
+
await elementUpdated(el);
|
|
46
|
+
button.click();
|
|
47
|
+
await elementUpdated(el);
|
|
48
|
+
expect(toggleSpy.callCount).to.equal(1);
|
|
49
|
+
});
|
|
50
|
+
it('dispatches toggle event on enter key', async () => {
|
|
51
|
+
let open = false;
|
|
52
|
+
const onAccordionToggle = () => {
|
|
53
|
+
open = true;
|
|
54
|
+
};
|
|
55
|
+
const el = await fixture(html `
|
|
56
|
+
<sp-accordion-item
|
|
57
|
+
disabled
|
|
58
|
+
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
59
|
+
>
|
|
60
|
+
<div>Item 1</div>
|
|
61
|
+
</sp-accordion-item>
|
|
62
|
+
`);
|
|
63
|
+
await elementUpdated(el);
|
|
64
|
+
expect(open).to.be.false;
|
|
65
|
+
el.dispatchEvent(enterEvent());
|
|
66
|
+
await elementUpdated(el);
|
|
67
|
+
expect(open).to.be.false;
|
|
68
|
+
el.disabled = false;
|
|
69
|
+
await elementUpdated(el);
|
|
70
|
+
el.dispatchEvent(enterEvent());
|
|
71
|
+
await elementUpdated(el);
|
|
72
|
+
expect(open).to.be.true;
|
|
73
|
+
});
|
|
74
|
+
it('dispatches toggle event on space key', async () => {
|
|
75
|
+
let open = false;
|
|
76
|
+
const onAccordionToggle = () => {
|
|
77
|
+
open = true;
|
|
78
|
+
};
|
|
79
|
+
const el = await fixture(html `
|
|
80
|
+
<sp-accordion-item
|
|
81
|
+
disabled
|
|
82
|
+
@sp-accordion-item-toggle=${onAccordionToggle}
|
|
83
|
+
>
|
|
84
|
+
<div>Item 1</div>
|
|
85
|
+
</sp-accordion-item>
|
|
86
|
+
`);
|
|
87
|
+
await elementUpdated(el);
|
|
88
|
+
expect(open).to.be.false;
|
|
89
|
+
el.dispatchEvent(spaceEvent());
|
|
90
|
+
await elementUpdated(el);
|
|
91
|
+
expect(open).to.be.false;
|
|
92
|
+
el.disabled = false;
|
|
93
|
+
await elementUpdated(el);
|
|
94
|
+
el.dispatchEvent(spaceEvent());
|
|
95
|
+
await elementUpdated(el);
|
|
96
|
+
expect(open).to.be.true;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=accordion-item.test.js.map
|
|
@@ -0,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AE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QAClD,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,MAAM,iBAAiB,GAAG,GAAS,EAAE;YACjC,IAAI,GAAG,IAAI,CAAC;QAChB,CAAC,CAAC;QACF,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;;gDAGgC,iBAAiB;;;;aAIpD,CACJ,CAAC;QAEF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAEzB,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC;QAE/B,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAEzB,EAAE,CAAC,QAAQ,GAAG,KAAK,CAAC;QACpB,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC;QAE/B,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","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 '../sp-accordion-item.js';\nimport { AccordionItem } from '../src/AccordionItem';\nimport { enterEvent, spaceEvent } from '../../../test/testing-helpers.js';\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.dispatchEvent(enterEvent());\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.disabled = false;\n await elementUpdated(el);\n\n el.dispatchEvent(enterEvent());\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.dispatchEvent(spaceEvent());\n\n await elementUpdated(el);\n\n expect(open).to.be.false;\n\n el.disabled = false;\n await elementUpdated(el);\n\n el.dispatchEvent(spaceEvent());\n\n await elementUpdated(el);\n\n expect(open).to.be.true;\n });\n});\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import * as stories from '../stories/accordion.stories.js';
|
|
13
|
+
import { regressVisuals } from '../../../test/visual/test.js';
|
|
14
|
+
regressVisuals('AccordionStories', stories);
|
|
15
|
+
//# sourceMappingURL=accordion.test-vrt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accordion.test-vrt.js","sourceRoot":"","sources":["accordion.test-vrt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,cAAc,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC","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/accordion.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\n\nregressVisuals('AccordionStories', stories);\n"]}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
|
|
13
|
+
import '../sp-accordion.js';
|
|
14
|
+
import { Default } from '../stories/accordion.stories.js';
|
|
15
|
+
import { Accordion, AccordionItem } from '@spectrum-web-components/accordion';
|
|
16
|
+
import { arrowDownEvent, arrowUpEvent, shiftTabEvent, } from '../../../test/testing-helpers.js';
|
|
17
|
+
import { spy } from 'sinon';
|
|
18
|
+
describe('Accordion', () => {
|
|
19
|
+
it('renders with items accessibly', async () => {
|
|
20
|
+
const el = await fixture(Default());
|
|
21
|
+
await elementUpdated(el);
|
|
22
|
+
await expect(el).to.be.accessible();
|
|
23
|
+
});
|
|
24
|
+
it('does not accept focus when empty', async () => {
|
|
25
|
+
const el = await fixture(html `
|
|
26
|
+
<sp-accordion></sp-accordion>
|
|
27
|
+
`);
|
|
28
|
+
await elementUpdated(el);
|
|
29
|
+
expect(document.activeElement === el).to.be.false;
|
|
30
|
+
el.focus();
|
|
31
|
+
await elementUpdated(el);
|
|
32
|
+
expect(document.activeElement === el).to.be.false;
|
|
33
|
+
});
|
|
34
|
+
it('does not accept keyboard events when items are not present', async () => {
|
|
35
|
+
const errorSpy = spy();
|
|
36
|
+
const el = await fixture(html `
|
|
37
|
+
<sp-accordion>
|
|
38
|
+
<sp-accordion-item disabled label="Heading 2">
|
|
39
|
+
<div>Item 2</div>
|
|
40
|
+
</sp-accordion-item>
|
|
41
|
+
</sp-accordion>
|
|
42
|
+
`);
|
|
43
|
+
await elementUpdated(el);
|
|
44
|
+
const item = el.querySelector('sp-accordion-item');
|
|
45
|
+
window.addEventListener('error', () => errorSpy());
|
|
46
|
+
el.focus();
|
|
47
|
+
item.remove();
|
|
48
|
+
await elementUpdated(el);
|
|
49
|
+
el.dispatchEvent(new KeyboardEvent('keydown', {
|
|
50
|
+
code: 'ArrowDown',
|
|
51
|
+
}));
|
|
52
|
+
expect(errorSpy.callCount).to.equal(0);
|
|
53
|
+
});
|
|
54
|
+
it('does not accept focus when all children [disabled]', async () => {
|
|
55
|
+
const el = await fixture(html `
|
|
56
|
+
<sp-accordion>
|
|
57
|
+
<sp-accordion-item disabled label="Heading 1">
|
|
58
|
+
<div>Item 1</div>
|
|
59
|
+
</sp-accordion-item>
|
|
60
|
+
<sp-accordion-item disabled label="Heading 2">
|
|
61
|
+
<div>Item 2</div>
|
|
62
|
+
</sp-accordion-item>
|
|
63
|
+
</sp-accordion>
|
|
64
|
+
`);
|
|
65
|
+
await elementUpdated(el);
|
|
66
|
+
expect(document.activeElement === el).to.be.false;
|
|
67
|
+
el.focus();
|
|
68
|
+
await elementUpdated(el);
|
|
69
|
+
expect(document.activeElement === el).to.be.false;
|
|
70
|
+
});
|
|
71
|
+
it('only allows one open item by default', async () => {
|
|
72
|
+
const el = await fixture(Default());
|
|
73
|
+
await elementUpdated(el);
|
|
74
|
+
const firstItem = el.querySelector('sp-accordion-item:nth-of-type(1)');
|
|
75
|
+
const secondItem = el.querySelector('sp-accordion-item:nth-of-type(2)');
|
|
76
|
+
const firstButton = firstItem.focusElement;
|
|
77
|
+
const secondButton = secondItem.focusElement;
|
|
78
|
+
firstButton.click();
|
|
79
|
+
await elementUpdated(el);
|
|
80
|
+
let openItems = el.querySelectorAll('sp-accordion-item[open]');
|
|
81
|
+
expect(openItems.length).to.equal(1);
|
|
82
|
+
secondButton.click();
|
|
83
|
+
await elementUpdated(el);
|
|
84
|
+
openItems = el.querySelectorAll('sp-accordion-item[open]');
|
|
85
|
+
expect(openItems.length).to.equal(1);
|
|
86
|
+
});
|
|
87
|
+
it('can have `toggle` events canceled', async () => {
|
|
88
|
+
const el = await fixture(Default());
|
|
89
|
+
await elementUpdated(el);
|
|
90
|
+
const firstItem = el.querySelector('sp-accordion-item:nth-of-type(1)');
|
|
91
|
+
const secondItem = el.querySelector('sp-accordion-item:nth-of-type(2)');
|
|
92
|
+
const firstButton = firstItem.focusElement;
|
|
93
|
+
const secondButton = secondItem.focusElement;
|
|
94
|
+
firstButton.click();
|
|
95
|
+
await elementUpdated(el);
|
|
96
|
+
expect(firstItem.open).to.be.true;
|
|
97
|
+
expect(secondItem.open).to.be.false;
|
|
98
|
+
el.addEventListener('sp-accordion-item-toggle', (event) => event.preventDefault());
|
|
99
|
+
secondButton.click();
|
|
100
|
+
await elementUpdated(el);
|
|
101
|
+
expect(firstItem.open).to.be.true;
|
|
102
|
+
expect(secondItem.open).to.be.false;
|
|
103
|
+
});
|
|
104
|
+
it('allows more than one open item when `[allow-multiple]`', async () => {
|
|
105
|
+
const el = await fixture(Default());
|
|
106
|
+
el.allowMultiple = true;
|
|
107
|
+
await elementUpdated(el);
|
|
108
|
+
const firstItem = el.querySelector('sp-accordion-item:nth-of-type(1)');
|
|
109
|
+
const secondItem = el.querySelector('sp-accordion-item:nth-of-type(2)');
|
|
110
|
+
const firstButton = firstItem.focusElement;
|
|
111
|
+
const secondButton = secondItem.focusElement;
|
|
112
|
+
firstButton.click();
|
|
113
|
+
await elementUpdated(el);
|
|
114
|
+
expect(firstItem.open).to.be.true;
|
|
115
|
+
expect(secondItem.open).to.be.false;
|
|
116
|
+
secondButton.click();
|
|
117
|
+
await elementUpdated(el);
|
|
118
|
+
expect(firstItem.open).to.be.true;
|
|
119
|
+
expect(secondItem.open).to.be.true;
|
|
120
|
+
});
|
|
121
|
+
it('ensures that the correct item is open and that items can be closed', async () => {
|
|
122
|
+
const el = await fixture(Default());
|
|
123
|
+
await elementUpdated(el);
|
|
124
|
+
const firstItem = el.querySelector('sp-accordion-item:nth-of-type(1)');
|
|
125
|
+
const secondItem = el.querySelector('sp-accordion-item:nth-of-type(2)');
|
|
126
|
+
const firstButton = firstItem.focusElement;
|
|
127
|
+
const secondButton = secondItem.focusElement;
|
|
128
|
+
firstButton.click();
|
|
129
|
+
await elementUpdated(el);
|
|
130
|
+
expect(firstItem.open).to.be.true;
|
|
131
|
+
expect(secondItem.open).to.be.false;
|
|
132
|
+
secondButton.click();
|
|
133
|
+
await elementUpdated(el);
|
|
134
|
+
expect(firstItem.open).to.be.false;
|
|
135
|
+
expect(secondItem.open).to.be.true;
|
|
136
|
+
secondButton.click();
|
|
137
|
+
await elementUpdated(el);
|
|
138
|
+
expect(firstItem.open).to.be.false;
|
|
139
|
+
expect(secondItem.open).to.be.false;
|
|
140
|
+
});
|
|
141
|
+
it('ensures that the correct item is open and that items can be closed when [allow-multiple]', async () => {
|
|
142
|
+
const el = await fixture(Default());
|
|
143
|
+
el.allowMultiple = true;
|
|
144
|
+
await elementUpdated(el);
|
|
145
|
+
const firstItem = el.querySelector('sp-accordion-item:nth-of-type(1)');
|
|
146
|
+
const secondItem = el.querySelector('sp-accordion-item:nth-of-type(2)');
|
|
147
|
+
const firstButton = firstItem.focusElement;
|
|
148
|
+
const secondButton = secondItem.focusElement;
|
|
149
|
+
firstButton.click();
|
|
150
|
+
await elementUpdated(el);
|
|
151
|
+
expect(firstItem.open).to.be.true;
|
|
152
|
+
expect(secondItem.open).to.be.false;
|
|
153
|
+
secondButton.click();
|
|
154
|
+
await elementUpdated(el);
|
|
155
|
+
expect(firstItem.open).to.be.true;
|
|
156
|
+
expect(secondItem.open).to.be.true;
|
|
157
|
+
secondButton.click();
|
|
158
|
+
await elementUpdated(el);
|
|
159
|
+
expect(firstItem.open).to.be.true;
|
|
160
|
+
expect(secondItem.open).to.be.false;
|
|
161
|
+
});
|
|
162
|
+
it('handles focus and keyboard input and ignores disabled items', async () => {
|
|
163
|
+
const el = await fixture(html `
|
|
164
|
+
<sp-accordion allow-multiple>
|
|
165
|
+
<sp-accordion-item disabled label="Heading 1">
|
|
166
|
+
<div>Item 1</div>
|
|
167
|
+
</sp-accordion-item>
|
|
168
|
+
<sp-accordion-item label="Heading 2">
|
|
169
|
+
<div>Item 2</div>
|
|
170
|
+
</sp-accordion-item>
|
|
171
|
+
<sp-accordion-item label="Heading 3">
|
|
172
|
+
<div>Item 3</div>
|
|
173
|
+
</sp-accordion-item>
|
|
174
|
+
<sp-accordion-item label="Heading 4">
|
|
175
|
+
<div>Item 4</div>
|
|
176
|
+
</sp-accordion-item>
|
|
177
|
+
<sp-accordion-item label="Heading 5">
|
|
178
|
+
<div>Item 5</div>
|
|
179
|
+
</sp-accordion-item>
|
|
180
|
+
<sp-accordion-item disabled label="Heading 6">
|
|
181
|
+
<div>Item 6</div>
|
|
182
|
+
</sp-accordion-item>
|
|
183
|
+
</sp-accordion>
|
|
184
|
+
`);
|
|
185
|
+
await elementUpdated(el);
|
|
186
|
+
const secondItem = el.querySelector('sp-accordion-item:nth-of-type(2)');
|
|
187
|
+
const thirdToLastItem = el.querySelector('sp-accordion-item:nth-last-of-type(3)');
|
|
188
|
+
const secondToLastItem = el.querySelector('sp-accordion-item:nth-last-of-type(2)');
|
|
189
|
+
el.focus();
|
|
190
|
+
await elementUpdated(el);
|
|
191
|
+
expect(document.activeElement === secondItem).to.be.true;
|
|
192
|
+
el.dispatchEvent(arrowUpEvent());
|
|
193
|
+
el.dispatchEvent(arrowUpEvent());
|
|
194
|
+
expect(document.activeElement === thirdToLastItem).to.be.true;
|
|
195
|
+
el.dispatchEvent(arrowDownEvent());
|
|
196
|
+
expect(document.activeElement === secondToLastItem).to.be.true;
|
|
197
|
+
el.dispatchEvent(arrowDownEvent());
|
|
198
|
+
expect(document.activeElement === secondItem).to.be.true;
|
|
199
|
+
document.body.focus();
|
|
200
|
+
el.focus();
|
|
201
|
+
expect(document.activeElement === secondItem).to.be.true;
|
|
202
|
+
secondItem.dispatchEvent(shiftTabEvent());
|
|
203
|
+
await elementUpdated(el);
|
|
204
|
+
const outsideFocused = document.activeElement;
|
|
205
|
+
expect(typeof outsideFocused).not.to.equal(AccordionItem);
|
|
206
|
+
expect(typeof outsideFocused).not.to.equal(Accordion);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
//# sourceMappingURL=accordion.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accordion.test.js","sourceRoot":"","sources":["accordion.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACH,cAAc,EACd,YAAY,EACZ,aAAa,GAChB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,EAAE,GAAG,MAAM,OAAO,CAAY,OAAO,EAAE,CAAC,CAAC;QAE/C,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,CA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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';\n\nimport '../sp-accordion.js';\nimport { Default } from '../stories/accordion.stories.js';\nimport { Accordion, AccordionItem } from '@spectrum-web-components/accordion';\nimport {\n arrowDownEvent,\n arrowUpEvent,\n shiftTabEvent,\n} from '../../../test/testing-helpers.js';\nimport { spy } from 'sinon';\n\ndescribe('Accordion', () => {\n it('renders with items accessibly', async () => {\n const el = await fixture<Accordion>(Default());\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('does not accept focus when empty', async () => {\n const el = await fixture<Accordion>(\n html`\n <sp-accordion></sp-accordion>\n `\n );\n\n await elementUpdated(el);\n\n expect(document.activeElement === el).to.be.false;\n\n el.focus();\n await elementUpdated(el);\n\n expect(document.activeElement === el).to.be.false;\n });\n it('does not accept keyboard events when items are not present', async () => {\n const errorSpy = spy();\n const el = await fixture<Accordion>(\n 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\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('does not accept focus when all children [disabled]', async () => {\n const el = await fixture<Accordion>(\n html`\n <sp-accordion>\n <sp-accordion-item disabled label=\"Heading 1\">\n <div>Item 1</div>\n </sp-accordion-item>\n <sp-accordion-item disabled label=\"Heading 2\">\n <div>Item 2</div>\n </sp-accordion-item>\n </sp-accordion>\n `\n );\n\n await elementUpdated(el);\n\n expect(document.activeElement === el).to.be.false;\n\n el.focus();\n await elementUpdated(el);\n\n expect(document.activeElement === el).to.be.false;\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('can have `toggle` events canceled', 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 expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.false;\n\n el.addEventListener('sp-accordion-item-toggle', (event: Event) =>\n event.preventDefault()\n );\n\n secondButton.click();\n await elementUpdated(el);\n expect(firstItem.open).to.be.true;\n expect(secondItem.open).to.be.false;\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\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 it('handles focus and keyboard input and ignores disabled items', async () => {\n const el = await fixture<Accordion>(\n 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\n await elementUpdated(el);\n\n const secondItem = el.querySelector(\n 'sp-accordion-item:nth-of-type(2)'\n ) as AccordionItem;\n const thirdToLastItem = el.querySelector(\n 'sp-accordion-item:nth-last-of-type(3)'\n ) as AccordionItem;\n const secondToLastItem = el.querySelector(\n 'sp-accordion-item:nth-last-of-type(2)'\n ) as AccordionItem;\n\n el.focus();\n\n await elementUpdated(el);\n expect(document.activeElement === secondItem).to.be.true;\n\n el.dispatchEvent(arrowUpEvent());\n el.dispatchEvent(arrowUpEvent());\n\n expect(document.activeElement === thirdToLastItem).to.be.true;\n\n el.dispatchEvent(arrowDownEvent());\n\n expect(document.activeElement === secondToLastItem).to.be.true;\n\n el.dispatchEvent(arrowDownEvent());\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 secondItem.dispatchEvent(shiftTabEvent());\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"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import '@spectrum-web-components/accordion/sp-accordion.js';
|
|
13
|
+
import '@spectrum-web-components/accordion/sp-accordion-item.js';
|
|
14
|
+
import { html } from 'lit';
|
|
15
|
+
import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
|
|
16
|
+
measureFixtureCreation(html `
|
|
17
|
+
<sp-accordion>
|
|
18
|
+
<sp-accordion-item label="Heading 1">
|
|
19
|
+
<div>Item 1</div>
|
|
20
|
+
</sp-accordion-item>
|
|
21
|
+
<sp-accordion-item label="Heading 2">
|
|
22
|
+
<div>Item 2</div>
|
|
23
|
+
</sp-accordion-item>
|
|
24
|
+
<sp-accordion-item label="Heading 3">
|
|
25
|
+
<div>Item 3</div>
|
|
26
|
+
</sp-accordion-item>
|
|
27
|
+
<sp-accordion-item label="Heading 4">
|
|
28
|
+
<div>Item 4</div>
|
|
29
|
+
</sp-accordion-item>
|
|
30
|
+
<sp-accordion-item label="Heading 5">
|
|
31
|
+
<div>Item 5</div>
|
|
32
|
+
</sp-accordion-item>
|
|
33
|
+
<sp-accordion-item label="Heading 6">
|
|
34
|
+
<div>Item 6</div>
|
|
35
|
+
</sp-accordion-item>
|
|
36
|
+
</sp-accordion>
|
|
37
|
+
`);
|
|
38
|
+
//# sourceMappingURL=basic-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-test.js","sourceRoot":"","sources":["basic-test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,oDAAoD,CAAC;AAC5D,OAAO,yDAAyD,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,sBAAsB,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;;;;;;CAqB1B,CAAC,CAAC","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 '@spectrum-web-components/accordion/sp-accordion.js';\nimport '@spectrum-web-components/accordion/sp-accordion-item.js';\nimport { html } from 'lit';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-accordion>\n <sp-accordion-item 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 label=\"Heading 6\">\n <div>Item 6</div>\n </sp-accordion-item>\n </sp-accordion>\n`);\n"]}
|