@spectrum-web-components/overlay 0.15.2 → 0.15.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.
- package/custom-elements.json +3 -3
- package/package.json +5 -5
- package/src/ActiveOverlay.d.ts +1 -1
- package/src/ActiveOverlay.js +10 -3
- package/src/ActiveOverlay.js.map +1 -1
- package/src/overlay-stack.js +3 -3
- package/src/overlay-stack.js.map +1 -1
- package/src/overlay-trigger.css.js +1 -1
- package/src/overlay-trigger.css.js.map +1 -1
- package/test/benchmark/basic-test.js +25 -0
- package/test/benchmark/basic-test.js.map +1 -0
- package/test/overlay-lifecycle.test.js +162 -0
- package/test/overlay-lifecycle.test.js.map +1 -0
- package/test/overlay-timer.test.js +129 -0
- package/test/overlay-timer.test.js.map +1 -0
- package/test/overlay-trigger-click.test.js +76 -0
- package/test/overlay-trigger-click.test.js.map +1 -0
- package/test/overlay-trigger-extended.test.js +215 -0
- package/test/overlay-trigger-extended.test.js.map +1 -0
- package/test/overlay-trigger-hover-click.test.js +96 -0
- package/test/overlay-trigger-hover-click.test.js.map +1 -0
- package/test/overlay-trigger-hover.test.js +112 -0
- package/test/overlay-trigger-hover.test.js.map +1 -0
- package/test/overlay-trigger-longpress.test.js +335 -0
- package/test/overlay-trigger-longpress.test.js.map +1 -0
- package/test/overlay-trigger-sync.test.js +555 -0
- package/test/overlay-trigger-sync.test.js.map +1 -0
- package/test/overlay-trigger.test.js +555 -0
- package/test/overlay-trigger.test.js.map +1 -0
- package/test/overlay.test-vrt.js +15 -0
- package/test/overlay.test-vrt.js.map +1 -0
- package/test/overlay.test.js +549 -0
- package/test/overlay.test.js.map +1 -0
|
@@ -0,0 +1,162 @@
|
|
|
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, oneEvent, waitUntil, } from '@open-wc/testing';
|
|
13
|
+
import '@spectrum-web-components/tooltip/sp-tooltip.js';
|
|
14
|
+
import '@spectrum-web-components/action-button/sp-action-button.js';
|
|
15
|
+
import '@spectrum-web-components/overlay/overlay-trigger.js';
|
|
16
|
+
import { a11ySnapshot, findAccessibilityNode } from '@web/test-runner-commands';
|
|
17
|
+
describe('Overlay Trigger - Lifecycle Methods', () => {
|
|
18
|
+
it('calls the overlay lifecycle (willOpen/Close)', async () => {
|
|
19
|
+
const el = await fixture(html `
|
|
20
|
+
<overlay-trigger placement="right-start">
|
|
21
|
+
<sp-action-button slot="trigger">
|
|
22
|
+
Button with Tooltip
|
|
23
|
+
</sp-action-button>
|
|
24
|
+
<sp-tooltip slot="hover-content">
|
|
25
|
+
Described by this content on focus/hover. 1
|
|
26
|
+
</sp-tooltip>
|
|
27
|
+
</overlay-trigger>
|
|
28
|
+
`);
|
|
29
|
+
await elementUpdated(el);
|
|
30
|
+
expect(el.open).to.be.undefined;
|
|
31
|
+
expect(el.childNodes.length).to.equal(5);
|
|
32
|
+
const trigger = el.querySelector('[slot="trigger"]');
|
|
33
|
+
let snapshot = (await a11ySnapshot({}));
|
|
34
|
+
expect(findAccessibilityNode(snapshot, (node) => node.name === 'Button with Tooltip' &&
|
|
35
|
+
typeof node.description === 'undefined'), '`name`ed with no `description`');
|
|
36
|
+
const opened = oneEvent(el, 'sp-opened');
|
|
37
|
+
trigger.dispatchEvent(new FocusEvent('focusin', { bubbles: true, composed: true }));
|
|
38
|
+
await opened;
|
|
39
|
+
expect(el.open).to.equal('hover');
|
|
40
|
+
snapshot = (await a11ySnapshot({}));
|
|
41
|
+
expect(el.childNodes.length).to.equal(6);
|
|
42
|
+
expect(findAccessibilityNode(snapshot, (node) => node.name === 'Button with Tooltip' &&
|
|
43
|
+
node.description ===
|
|
44
|
+
'Described by this content on focus/hover.'), '`name`ed with `description`');
|
|
45
|
+
const closed = oneEvent(el, 'sp-closed');
|
|
46
|
+
trigger.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
47
|
+
await closed;
|
|
48
|
+
await elementUpdated(el);
|
|
49
|
+
await waitUntil(() => el.open === null);
|
|
50
|
+
expect(el.childNodes.length).to.equal(5);
|
|
51
|
+
});
|
|
52
|
+
it('calls the overlay lifecycle (willOpen/openCanceled)', async () => {
|
|
53
|
+
const el = await fixture(html `
|
|
54
|
+
<overlay-trigger placement="right-start">
|
|
55
|
+
<sp-action-button slot="trigger">
|
|
56
|
+
Button with Tooltip
|
|
57
|
+
</sp-action-button>
|
|
58
|
+
<sp-tooltip slot="hover-content" delayed>
|
|
59
|
+
Described by this content on focus/hover. 2
|
|
60
|
+
</sp-tooltip>
|
|
61
|
+
</overlay-trigger>
|
|
62
|
+
`);
|
|
63
|
+
await elementUpdated(el);
|
|
64
|
+
expect(el.open).to.be.undefined;
|
|
65
|
+
expect(el.childNodes.length, 'always').to.equal(5);
|
|
66
|
+
const trigger = el.querySelector('[slot="trigger"]');
|
|
67
|
+
trigger.dispatchEvent(new FocusEvent('focusin', { bubbles: true, composed: true }));
|
|
68
|
+
await elementUpdated(el);
|
|
69
|
+
trigger.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
70
|
+
await elementUpdated(el);
|
|
71
|
+
await waitUntil(() => {
|
|
72
|
+
return el.open === null;
|
|
73
|
+
}, 'open');
|
|
74
|
+
await elementUpdated(el);
|
|
75
|
+
await waitUntil(() => {
|
|
76
|
+
return el.childNodes.length === 5;
|
|
77
|
+
}, 'children');
|
|
78
|
+
});
|
|
79
|
+
it('gardens `aria-describedby` in its target', async () => {
|
|
80
|
+
const el = await fixture(html `
|
|
81
|
+
<overlay-trigger placement="right-start">
|
|
82
|
+
<sp-action-button slot="trigger" aria-describedby="descriptor">
|
|
83
|
+
Button with Tooltip
|
|
84
|
+
</sp-action-button>
|
|
85
|
+
<sp-tooltip slot="hover-content" delayed>
|
|
86
|
+
Described by this content on focus/hover. 2
|
|
87
|
+
</sp-tooltip>
|
|
88
|
+
</overlay-trigger>
|
|
89
|
+
<div id="descriptor">I'm a description!</div>
|
|
90
|
+
`);
|
|
91
|
+
const trigger = el.querySelector('[slot="trigger"]');
|
|
92
|
+
const tooltip = el.querySelector('sp-tooltip');
|
|
93
|
+
await elementUpdated(el);
|
|
94
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal('descriptor');
|
|
95
|
+
expect(el.open).to.be.undefined;
|
|
96
|
+
expect(el.childNodes.length, 'always').to.equal(5);
|
|
97
|
+
const opened = oneEvent(el, 'sp-opened');
|
|
98
|
+
trigger.dispatchEvent(new FocusEvent('focusin', { bubbles: true, composed: true }));
|
|
99
|
+
await opened;
|
|
100
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal(`descriptor ${tooltip._tooltipId}`);
|
|
101
|
+
const closed = oneEvent(el, 'sp-closed');
|
|
102
|
+
trigger.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
103
|
+
await closed;
|
|
104
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal('descriptor');
|
|
105
|
+
});
|
|
106
|
+
it('adds and removes `aria-describedby` attribute', async () => {
|
|
107
|
+
const el = await fixture(html `
|
|
108
|
+
<overlay-trigger placement="right-start">
|
|
109
|
+
<sp-action-button slot="trigger">
|
|
110
|
+
Button with Tooltip
|
|
111
|
+
</sp-action-button>
|
|
112
|
+
<sp-tooltip slot="hover-content" delayed>
|
|
113
|
+
Described by this content on focus/hover. 2
|
|
114
|
+
</sp-tooltip>
|
|
115
|
+
</overlay-trigger>
|
|
116
|
+
`);
|
|
117
|
+
const trigger = el.querySelector('[slot="trigger"]');
|
|
118
|
+
const tooltip = el.querySelector('sp-tooltip');
|
|
119
|
+
await elementUpdated(el);
|
|
120
|
+
expect(trigger.hasAttribute('aria-describedby')).to.be.false;
|
|
121
|
+
expect(el.open).to.be.undefined;
|
|
122
|
+
expect(el.childNodes.length, 'always').to.equal(5);
|
|
123
|
+
const opened = oneEvent(el, 'sp-opened');
|
|
124
|
+
trigger.dispatchEvent(new FocusEvent('focusin', { bubbles: true, composed: true }));
|
|
125
|
+
await opened;
|
|
126
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal(`${tooltip._tooltipId}`);
|
|
127
|
+
const closed = oneEvent(el, 'sp-closed');
|
|
128
|
+
trigger.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
129
|
+
await closed;
|
|
130
|
+
expect(trigger.hasAttribute('aria-describedby')).to.be.false;
|
|
131
|
+
});
|
|
132
|
+
it('does not duplicate `aria-describedby` attribute', async () => {
|
|
133
|
+
const el = await fixture(html `
|
|
134
|
+
<overlay-trigger placement="right-start">
|
|
135
|
+
<sp-action-button slot="trigger">
|
|
136
|
+
Button with Tooltip
|
|
137
|
+
</sp-action-button>
|
|
138
|
+
<sp-tooltip slot="hover-content" delayed>
|
|
139
|
+
Described by this content on focus/hover. 2
|
|
140
|
+
</sp-tooltip>
|
|
141
|
+
</overlay-trigger>
|
|
142
|
+
`);
|
|
143
|
+
const trigger = el.querySelector('[slot="trigger"]');
|
|
144
|
+
const tooltip = el.querySelector('sp-tooltip');
|
|
145
|
+
const tooltipId = tooltip
|
|
146
|
+
._tooltipId;
|
|
147
|
+
trigger.setAttribute('aria-describedby', tooltipId);
|
|
148
|
+
await elementUpdated(el);
|
|
149
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal(tooltipId);
|
|
150
|
+
expect(el.open).to.be.undefined;
|
|
151
|
+
expect(el.childNodes.length, 'always').to.equal(5);
|
|
152
|
+
const opened = oneEvent(el, 'sp-opened');
|
|
153
|
+
trigger.dispatchEvent(new FocusEvent('focusin', { bubbles: true, composed: true }));
|
|
154
|
+
await opened;
|
|
155
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal(tooltipId);
|
|
156
|
+
const closed = oneEvent(el, 'sp-closed');
|
|
157
|
+
trigger.dispatchEvent(new FocusEvent('focusout', { bubbles: true, composed: true }));
|
|
158
|
+
await closed;
|
|
159
|
+
expect(trigger.getAttribute('aria-describedby')).to.equal(tooltipId);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=overlay-lifecycle.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-lifecycle.test.js","sourceRoot":"","sources":["overlay-lifecycle.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EACH,cAAc,EACd,MAAM,EACN,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,SAAS,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,gDAAgD,CAAC;AACxD,OAAO,4DAA4D,CAAC;AAEpE,OAAO,qDAAqD,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGhF,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;IACjD,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,EAAE,GAAG,MAAM,OAAO,CAAiB,IAAI,CAAA;;;;;;;;;SAS5C,CAAC,CAAC;QAEH,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;QAChC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,kBAAkB,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,CAAC;QAEb,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAErE,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QACzC,OAAO,CAAC,aAAa,CACjB,IAAI,UAAU,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAChE,CAAC;QACF,MAAM,MAAM,CAAC;QAEb,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACzE,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*/\nimport {\n elementUpdated,\n expect,\n fixture,\n html,\n oneEvent,\n waitUntil,\n} from '@open-wc/testing';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport { OverlayTrigger } from '..';\nimport '@spectrum-web-components/overlay/overlay-trigger.js';\nimport { a11ySnapshot, findAccessibilityNode } from '@web/test-runner-commands';\nimport { Tooltip } from '@spectrum-web-components/tooltip';\n\ndescribe('Overlay Trigger - Lifecycle Methods', () => {\n it('calls the overlay lifecycle (willOpen/Close)', async () => {\n const el = await fixture<OverlayTrigger>(html`\n <overlay-trigger placement=\"right-start\">\n <sp-action-button slot=\"trigger\">\n Button with Tooltip\n </sp-action-button>\n <sp-tooltip slot=\"hover-content\">\n Described by this content on focus/hover. 1\n </sp-tooltip>\n </overlay-trigger>\n `);\n\n await elementUpdated(el);\n\n expect(el.open).to.be.undefined;\n expect(el.childNodes.length).to.equal(5);\n const trigger = el.querySelector('[slot=\"trigger\"]') as HTMLElement;\n type DescribedNode = {\n name: string;\n description: string;\n };\n let snapshot = (await a11ySnapshot({})) as unknown as DescribedNode & {\n children: DescribedNode[];\n };\n expect(\n findAccessibilityNode<DescribedNode>(\n snapshot,\n (node) =>\n node.name === 'Button with Tooltip' &&\n typeof node.description === 'undefined'\n ),\n '`name`ed with no `description`'\n );\n const opened = oneEvent(el, 'sp-opened');\n trigger.dispatchEvent(\n new FocusEvent('focusin', { bubbles: true, composed: true })\n );\n await opened;\n\n expect(el.open).to.equal('hover');\n snapshot = (await a11ySnapshot({})) as unknown as DescribedNode & {\n children: DescribedNode[];\n };\n\n expect(el.childNodes.length).to.equal(6);\n expect(\n findAccessibilityNode<DescribedNode>(\n snapshot,\n (node) =>\n node.name === 'Button with Tooltip' &&\n node.description ===\n 'Described by this content on focus/hover.'\n ),\n '`name`ed with `description`'\n );\n\n const closed = oneEvent(el, 'sp-closed');\n trigger.dispatchEvent(\n new FocusEvent('focusout', { bubbles: true, composed: true })\n );\n await closed;\n await elementUpdated(el);\n\n await waitUntil(() => el.open === null);\n expect(el.childNodes.length).to.equal(5);\n });\n it('calls the overlay lifecycle (willOpen/openCanceled)', async () => {\n const el = await fixture<OverlayTrigger>(html`\n <overlay-trigger placement=\"right-start\">\n <sp-action-button slot=\"trigger\">\n Button with Tooltip\n </sp-action-button>\n <sp-tooltip slot=\"hover-content\" delayed>\n Described by this content on focus/hover. 2\n </sp-tooltip>\n </overlay-trigger>\n `);\n\n await elementUpdated(el);\n\n expect(el.open).to.be.undefined;\n expect(el.childNodes.length, 'always').to.equal(5);\n const trigger = el.querySelector('[slot=\"trigger\"]') as HTMLElement;\n trigger.dispatchEvent(\n new FocusEvent('focusin', { bubbles: true, composed: true })\n );\n await elementUpdated(el);\n trigger.dispatchEvent(\n new FocusEvent('focusout', { bubbles: true, composed: true })\n );\n await elementUpdated(el);\n\n await waitUntil(() => {\n return el.open === null;\n }, 'open');\n await elementUpdated(el);\n await waitUntil(() => {\n return el.childNodes.length === 5;\n }, 'children');\n });\n it('gardens `aria-describedby` in its target', async () => {\n const el = await fixture<OverlayTrigger>(html`\n <overlay-trigger placement=\"right-start\">\n <sp-action-button slot=\"trigger\" aria-describedby=\"descriptor\">\n Button with Tooltip\n </sp-action-button>\n <sp-tooltip slot=\"hover-content\" delayed>\n Described by this content on focus/hover. 2\n </sp-tooltip>\n </overlay-trigger>\n <div id=\"descriptor\">I'm a description!</div>\n `);\n\n const trigger = el.querySelector('[slot=\"trigger\"]') as HTMLElement;\n const tooltip = el.querySelector('sp-tooltip') as Tooltip;\n\n await elementUpdated(el);\n\n expect(trigger.getAttribute('aria-describedby')).to.equal('descriptor');\n expect(el.open).to.be.undefined;\n expect(el.childNodes.length, 'always').to.equal(5);\n\n const opened = oneEvent(el, 'sp-opened');\n trigger.dispatchEvent(\n new FocusEvent('focusin', { bubbles: true, composed: true })\n );\n await opened;\n\n expect(trigger.getAttribute('aria-describedby')).to.equal(\n `descriptor ${\n (tooltip as unknown as { _tooltipId: string })._tooltipId\n }`\n );\n\n const closed = oneEvent(el, 'sp-closed');\n trigger.dispatchEvent(\n new FocusEvent('focusout', { bubbles: true, composed: true })\n );\n await closed;\n\n expect(trigger.getAttribute('aria-describedby')).to.equal('descriptor');\n });\n it('adds and removes `aria-describedby` attribute', async () => {\n const el = await fixture<OverlayTrigger>(html`\n <overlay-trigger placement=\"right-start\">\n <sp-action-button slot=\"trigger\">\n Button with Tooltip\n </sp-action-button>\n <sp-tooltip slot=\"hover-content\" delayed>\n Described by this content on focus/hover. 2\n </sp-tooltip>\n </overlay-trigger>\n `);\n\n const trigger = el.querySelector('[slot=\"trigger\"]') as HTMLElement;\n const tooltip = el.querySelector('sp-tooltip') as Tooltip;\n\n await elementUpdated(el);\n\n expect(trigger.hasAttribute('aria-describedby')).to.be.false;\n expect(el.open).to.be.undefined;\n expect(el.childNodes.length, 'always').to.equal(5);\n\n const opened = oneEvent(el, 'sp-opened');\n trigger.dispatchEvent(\n new FocusEvent('focusin', { bubbles: true, composed: true })\n );\n await opened;\n\n expect(trigger.getAttribute('aria-describedby')).to.equal(\n `${(tooltip as unknown as { _tooltipId: string })._tooltipId}`\n );\n\n const closed = oneEvent(el, 'sp-closed');\n trigger.dispatchEvent(\n new FocusEvent('focusout', { bubbles: true, composed: true })\n );\n await closed;\n\n expect(trigger.hasAttribute('aria-describedby')).to.be.false;\n });\n it('does not duplicate `aria-describedby` attribute', async () => {\n const el = await fixture<OverlayTrigger>(html`\n <overlay-trigger placement=\"right-start\">\n <sp-action-button slot=\"trigger\">\n Button with Tooltip\n </sp-action-button>\n <sp-tooltip slot=\"hover-content\" delayed>\n Described by this content on focus/hover. 2\n </sp-tooltip>\n </overlay-trigger>\n `);\n\n const trigger = el.querySelector('[slot=\"trigger\"]') as HTMLElement;\n const tooltip = el.querySelector('sp-tooltip') as Tooltip;\n const tooltipId = (tooltip as unknown as { _tooltipId: string })\n ._tooltipId;\n trigger.setAttribute('aria-describedby', tooltipId);\n\n await elementUpdated(el);\n\n expect(trigger.getAttribute('aria-describedby')).to.equal(tooltipId);\n expect(el.open).to.be.undefined;\n expect(el.childNodes.length, 'always').to.equal(5);\n\n const opened = oneEvent(el, 'sp-opened');\n trigger.dispatchEvent(\n new FocusEvent('focusin', { bubbles: true, composed: true })\n );\n await opened;\n\n expect(trigger.getAttribute('aria-describedby')).to.equal(tooltipId);\n\n const closed = oneEvent(el, 'sp-closed');\n trigger.dispatchEvent(\n new FocusEvent('focusout', { bubbles: true, composed: true })\n );\n await closed;\n\n expect(trigger.getAttribute('aria-describedby')).to.equal(tooltipId);\n });\n});\n"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 { useFakeTimers } from 'sinon';
|
|
13
|
+
import { OverlayTimer } from '../src/overlay-timer.js';
|
|
14
|
+
import { expect } from '@open-wc/testing';
|
|
15
|
+
describe('Overlays timer', () => {
|
|
16
|
+
let clock;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
clock = useFakeTimers();
|
|
19
|
+
});
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
clock.restore();
|
|
22
|
+
});
|
|
23
|
+
it('should resolve after warmup', async () => {
|
|
24
|
+
const timer = new OverlayTimer({
|
|
25
|
+
warmUpDelay: 500,
|
|
26
|
+
coolDownDelay: 500,
|
|
27
|
+
});
|
|
28
|
+
const element = document.createElement('div');
|
|
29
|
+
const promise = timer.openTimer(element);
|
|
30
|
+
clock.next();
|
|
31
|
+
expect(clock.now).to.equal(500);
|
|
32
|
+
const cancelled = await promise;
|
|
33
|
+
expect(cancelled).to.be.false;
|
|
34
|
+
});
|
|
35
|
+
it('should resolve true when cancelled', async () => {
|
|
36
|
+
const timer = new OverlayTimer({
|
|
37
|
+
warmUpDelay: 500,
|
|
38
|
+
coolDownDelay: 500,
|
|
39
|
+
});
|
|
40
|
+
const element = document.createElement('div');
|
|
41
|
+
const promise = timer.openTimer(element);
|
|
42
|
+
clock.tick(10);
|
|
43
|
+
timer.close(element);
|
|
44
|
+
clock.next();
|
|
45
|
+
const cancelled = await promise;
|
|
46
|
+
expect(cancelled).to.be.true;
|
|
47
|
+
});
|
|
48
|
+
it('should resolve cancelled when opening new overlay', async () => {
|
|
49
|
+
const timer = new OverlayTimer({
|
|
50
|
+
warmUpDelay: 500,
|
|
51
|
+
coolDownDelay: 500,
|
|
52
|
+
});
|
|
53
|
+
const element1 = document.createElement('div');
|
|
54
|
+
const element2 = document.createElement('div');
|
|
55
|
+
const promise1 = timer.openTimer(element1);
|
|
56
|
+
clock.tick(10);
|
|
57
|
+
const promise2 = timer.openTimer(element2);
|
|
58
|
+
clock.tick(10);
|
|
59
|
+
let cancelled = await promise1;
|
|
60
|
+
expect(cancelled).to.be.true;
|
|
61
|
+
clock.next();
|
|
62
|
+
cancelled = await promise2;
|
|
63
|
+
expect(cancelled).to.be.false;
|
|
64
|
+
expect(clock.now).to.equal(510);
|
|
65
|
+
});
|
|
66
|
+
it('should cooldown after closing overlay', async () => {
|
|
67
|
+
const timer = new OverlayTimer({
|
|
68
|
+
warmUpDelay: 500,
|
|
69
|
+
coolDownDelay: 500,
|
|
70
|
+
});
|
|
71
|
+
const element = document.createElement('div');
|
|
72
|
+
let promise = timer.openTimer(element);
|
|
73
|
+
clock.next();
|
|
74
|
+
timer.close(element);
|
|
75
|
+
clock.next();
|
|
76
|
+
expect(clock.now).to.equal(1000);
|
|
77
|
+
promise = timer.openTimer(element);
|
|
78
|
+
clock.next();
|
|
79
|
+
const cancelled = await promise;
|
|
80
|
+
expect(cancelled).to.be.false;
|
|
81
|
+
expect(clock.now).to.equal(1500);
|
|
82
|
+
});
|
|
83
|
+
it('should open overlay quickly when hot', async () => {
|
|
84
|
+
const timer = new OverlayTimer({
|
|
85
|
+
warmUpDelay: 500,
|
|
86
|
+
coolDownDelay: 500,
|
|
87
|
+
});
|
|
88
|
+
const element = document.createElement('div');
|
|
89
|
+
let promise = timer.openTimer(element);
|
|
90
|
+
clock.next();
|
|
91
|
+
timer.close(element);
|
|
92
|
+
clock.tick(1);
|
|
93
|
+
promise = timer.openTimer(element);
|
|
94
|
+
clock.next();
|
|
95
|
+
const cancelled = await promise;
|
|
96
|
+
expect(cancelled).to.be.false;
|
|
97
|
+
expect(clock.now).to.equal(501);
|
|
98
|
+
});
|
|
99
|
+
it('should cooldown after opening and closing overlay multiple times', async () => {
|
|
100
|
+
const timer = new OverlayTimer({
|
|
101
|
+
warmUpDelay: 500,
|
|
102
|
+
coolDownDelay: 500,
|
|
103
|
+
});
|
|
104
|
+
const element = document.createElement('div');
|
|
105
|
+
let promise = timer.openTimer(element);
|
|
106
|
+
clock.next();
|
|
107
|
+
expect(clock.now).to.equal(500);
|
|
108
|
+
timer.close(element);
|
|
109
|
+
clock.tick(1);
|
|
110
|
+
for (let i = 0; i < 10; i++) {
|
|
111
|
+
const element = document.createElement('div');
|
|
112
|
+
promise = timer.openTimer(element);
|
|
113
|
+
clock.next();
|
|
114
|
+
const cancelled = await promise;
|
|
115
|
+
expect(cancelled).to.be.false;
|
|
116
|
+
timer.close(element);
|
|
117
|
+
clock.tick(1);
|
|
118
|
+
}
|
|
119
|
+
// Wait for cooldown
|
|
120
|
+
clock.next();
|
|
121
|
+
expect(clock.now).to.equal(1010);
|
|
122
|
+
promise = timer.openTimer(element);
|
|
123
|
+
clock.next();
|
|
124
|
+
const cancelled = await promise;
|
|
125
|
+
expect(cancelled).to.be.false;
|
|
126
|
+
expect(clock.now).to.equal(1510);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
//# sourceMappingURL=overlay-timer.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-timer.test.js","sourceRoot":"","sources":["overlay-timer.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAmB,aAAa,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,IAAI,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AAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACnC,KAAK,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC;QAChC,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,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 { SinonFakeTimers, useFakeTimers } from 'sinon';\nimport { OverlayTimer } from '../src/overlay-timer.js';\nimport { expect } from '@open-wc/testing';\n\ndescribe('Overlays timer', () => {\n let clock: SinonFakeTimers;\n\n beforeEach(() => {\n clock = useFakeTimers();\n });\n\n afterEach(() => {\n clock.restore();\n });\n\n it('should resolve after warmup', async () => {\n const timer = new OverlayTimer({\n warmUpDelay: 500,\n coolDownDelay: 500,\n });\n const element = document.createElement('div');\n const promise = timer.openTimer(element);\n clock.next();\n expect(clock.now).to.equal(500);\n const cancelled = await promise;\n expect(cancelled).to.be.false;\n });\n\n it('should resolve true when cancelled', async () => {\n const timer = new OverlayTimer({\n warmUpDelay: 500,\n coolDownDelay: 500,\n });\n const element = document.createElement('div');\n const promise = timer.openTimer(element);\n clock.tick(10);\n timer.close(element);\n clock.next();\n const cancelled = await promise;\n expect(cancelled).to.be.true;\n });\n\n it('should resolve cancelled when opening new overlay', async () => {\n const timer = new OverlayTimer({\n warmUpDelay: 500,\n coolDownDelay: 500,\n });\n const element1 = document.createElement('div');\n const element2 = document.createElement('div');\n const promise1 = timer.openTimer(element1);\n clock.tick(10);\n const promise2 = timer.openTimer(element2);\n clock.tick(10);\n let cancelled = await promise1;\n expect(cancelled).to.be.true;\n clock.next();\n cancelled = await promise2;\n expect(cancelled).to.be.false;\n expect(clock.now).to.equal(510);\n });\n\n it('should cooldown after closing overlay', async () => {\n const timer = new OverlayTimer({\n warmUpDelay: 500,\n coolDownDelay: 500,\n });\n const element = document.createElement('div');\n let promise = timer.openTimer(element);\n clock.next();\n timer.close(element);\n clock.next();\n expect(clock.now).to.equal(1000);\n promise = timer.openTimer(element);\n clock.next();\n const cancelled = await promise;\n expect(cancelled).to.be.false;\n expect(clock.now).to.equal(1500);\n });\n\n it('should open overlay quickly when hot', async () => {\n const timer = new OverlayTimer({\n warmUpDelay: 500,\n coolDownDelay: 500,\n });\n const element = document.createElement('div');\n let promise = timer.openTimer(element);\n clock.next();\n timer.close(element);\n clock.tick(1);\n promise = timer.openTimer(element);\n clock.next();\n const cancelled = await promise;\n expect(cancelled).to.be.false;\n expect(clock.now).to.equal(501);\n });\n\n it('should cooldown after opening and closing overlay multiple times', async () => {\n const timer = new OverlayTimer({\n warmUpDelay: 500,\n coolDownDelay: 500,\n });\n const element = document.createElement('div');\n let promise = timer.openTimer(element);\n clock.next();\n expect(clock.now).to.equal(500);\n timer.close(element);\n clock.tick(1);\n\n for (let i = 0; i < 10; i++) {\n const element = document.createElement('div');\n promise = timer.openTimer(element);\n clock.next();\n const cancelled = await promise;\n expect(cancelled).to.be.false;\n timer.close(element);\n clock.tick(1);\n }\n\n // Wait for cooldown\n clock.next();\n expect(clock.now).to.equal(1010);\n promise = timer.openTimer(element);\n clock.next();\n const cancelled = await promise;\n expect(cancelled).to.be.false;\n expect(clock.now).to.equal(1510);\n });\n});\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
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, waitUntil, } from '@open-wc/testing';
|
|
13
|
+
import '@spectrum-web-components/popover/sp-popover.js';
|
|
14
|
+
import '@spectrum-web-components/action-button/sp-action-button.js';
|
|
15
|
+
import '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';
|
|
16
|
+
import '@spectrum-web-components/popover/sp-popover.js';
|
|
17
|
+
import '@spectrum-web-components/overlay/overlay-trigger.js';
|
|
18
|
+
import { spy } from 'sinon';
|
|
19
|
+
describe('Overlay Trigger - Click', () => {
|
|
20
|
+
it('displays `click` declaratively', async () => {
|
|
21
|
+
const openedSpy = spy();
|
|
22
|
+
const closedSpy = spy();
|
|
23
|
+
const el = await fixture((() => html `
|
|
24
|
+
<overlay-trigger
|
|
25
|
+
placement="right-start"
|
|
26
|
+
open="click"
|
|
27
|
+
@sp-opened=${() => openedSpy()}
|
|
28
|
+
@sp-closed=${() => closedSpy()}
|
|
29
|
+
>
|
|
30
|
+
<sp-action-button slot="trigger">
|
|
31
|
+
<sp-icon-magnify slot="icon"></sp-icon-magnify>
|
|
32
|
+
</sp-action-button>
|
|
33
|
+
<sp-popover slot="click-content" tip></sp-popover>
|
|
34
|
+
</overlay-trigger>
|
|
35
|
+
`)());
|
|
36
|
+
await elementUpdated(el);
|
|
37
|
+
await waitUntil(() => openedSpy.calledOnce, 'click content projected to overlay', { timeout: 2000 });
|
|
38
|
+
el.removeAttribute('open');
|
|
39
|
+
await elementUpdated(el);
|
|
40
|
+
await waitUntil(() => closedSpy.calledOnce, 'click content returned', {
|
|
41
|
+
timeout: 2000,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('opens a second time', async () => {
|
|
45
|
+
const openedSpy = spy();
|
|
46
|
+
const closedSpy = spy();
|
|
47
|
+
const el = await fixture(html `
|
|
48
|
+
<overlay-trigger
|
|
49
|
+
placement="right-start"
|
|
50
|
+
type="modal"
|
|
51
|
+
open="click"
|
|
52
|
+
@sp-opened=${() => openedSpy()}
|
|
53
|
+
@sp-closed=${() => closedSpy()}
|
|
54
|
+
>
|
|
55
|
+
<sp-action-button slot="trigger">
|
|
56
|
+
<sp-icon-magnify slot="icon"></sp-icon-magnify>
|
|
57
|
+
</sp-action-button>
|
|
58
|
+
<sp-popover slot="click-content" tip></sp-popover>
|
|
59
|
+
</overlay-trigger>
|
|
60
|
+
`);
|
|
61
|
+
await elementUpdated(el);
|
|
62
|
+
const trigger = el.querySelector('[slot=trigger]');
|
|
63
|
+
await waitUntil(() => openedSpy.calledOnce, 'click content projected to overlay', { timeout: 2000 });
|
|
64
|
+
expect(el.open).to.equal('click');
|
|
65
|
+
el.removeAttribute('open');
|
|
66
|
+
await elementUpdated(el);
|
|
67
|
+
await waitUntil(() => closedSpy.calledOnce, 'click content returned', {
|
|
68
|
+
timeout: 2000,
|
|
69
|
+
});
|
|
70
|
+
expect(el.open).to.be.null;
|
|
71
|
+
trigger.click();
|
|
72
|
+
await waitUntil(() => openedSpy.callCount === 2, 'click content projected to overlay, again', { timeout: 2000 });
|
|
73
|
+
expect(el.open).to.equal('click');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=overlay-trigger-click.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-trigger-click.test.js","sourceRoot":"","sources":["overlay-trigger-click.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE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B,IAAI,CAAA;;;;;6BAKxB,GAAG,EAAE,CAAC,SAAS,EAAE;6BACjB,GAAG,EAAE,CAAC,SAAS,EAAE;;;;;;;SAOrC,CAAC,CAAC;QACH,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QACzB,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAiB,CAAC;QAEnE,MAAM,SAAS,CACX,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,EAC1B,oCAAoC,EACpC,EAAE,OAAO,EAAE,IAAI,EAAE,CACpB,CAAC;QACF,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAElC,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3B,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,wBAAwB,EAAE;YAClE,OAAO,EAAE,IAAI;SAChB,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QAE3B,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,SAAS,CACX,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS,KAAK,CAAC,EAC/B,2CAA2C,EAC3C,EAAE,OAAO,EAAE,IAAI,EAAE,CACpB,CAAC;QACF,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtC,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*/\nimport {\n elementUpdated,\n expect,\n fixture,\n html,\n waitUntil,\n} from '@open-wc/testing';\nimport '@spectrum-web-components/popover/sp-popover.js';\nimport '@spectrum-web-components/action-button/sp-action-button.js';\nimport '@spectrum-web-components/icons-workflow/icons/sp-icon-magnify.js';\nimport '@spectrum-web-components/popover/sp-popover.js';\nimport { OverlayTrigger } from '..';\nimport '@spectrum-web-components/overlay/overlay-trigger.js';\nimport { spy } from 'sinon';\nimport { ActionButton } from '@spectrum-web-components/action-button';\n\ndescribe('Overlay Trigger - Click', () => {\n it('displays `click` declaratively', async () => {\n const openedSpy = spy();\n const closedSpy = spy();\n const el = await fixture<OverlayTrigger>(\n (() => html`\n <overlay-trigger\n placement=\"right-start\"\n open=\"click\"\n @sp-opened=${() => openedSpy()}\n @sp-closed=${() => closedSpy()}\n >\n <sp-action-button slot=\"trigger\">\n <sp-icon-magnify slot=\"icon\"></sp-icon-magnify>\n </sp-action-button>\n <sp-popover slot=\"click-content\" tip></sp-popover>\n </overlay-trigger>\n `)()\n );\n await elementUpdated(el);\n\n await waitUntil(\n () => openedSpy.calledOnce,\n 'click content projected to overlay',\n { timeout: 2000 }\n );\n\n el.removeAttribute('open');\n await elementUpdated(el);\n\n await waitUntil(() => closedSpy.calledOnce, 'click content returned', {\n timeout: 2000,\n });\n });\n it('opens a second time', async () => {\n const openedSpy = spy();\n const closedSpy = spy();\n const el = await fixture<OverlayTrigger>(html`\n <overlay-trigger\n placement=\"right-start\"\n type=\"modal\"\n open=\"click\"\n @sp-opened=${() => openedSpy()}\n @sp-closed=${() => closedSpy()}\n >\n <sp-action-button slot=\"trigger\">\n <sp-icon-magnify slot=\"icon\"></sp-icon-magnify>\n </sp-action-button>\n <sp-popover slot=\"click-content\" tip></sp-popover>\n </overlay-trigger>\n `);\n await elementUpdated(el);\n const trigger = el.querySelector('[slot=trigger]') as ActionButton;\n\n await waitUntil(\n () => openedSpy.calledOnce,\n 'click content projected to overlay',\n { timeout: 2000 }\n );\n expect(el.open).to.equal('click');\n\n el.removeAttribute('open');\n await elementUpdated(el);\n\n await waitUntil(() => closedSpy.calledOnce, 'click content returned', {\n timeout: 2000,\n });\n\n expect(el.open).to.be.null;\n\n trigger.click();\n await waitUntil(\n () => openedSpy.callCount === 2,\n 'click content projected to overlay, again',\n { timeout: 2000 }\n );\n expect(el.open).to.equal('click');\n });\n});\n"]}
|
|
@@ -0,0 +1,215 @@
|
|
|
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, nextFrame, oneEvent, waitUntil, } from '@open-wc/testing';
|
|
13
|
+
import '../overlay-trigger.js';
|
|
14
|
+
import '@spectrum-web-components/button/sp-button.js';
|
|
15
|
+
import '@spectrum-web-components/popover/sp-popover.js';
|
|
16
|
+
import '@spectrum-web-components/textfield/sp-textfield.js';
|
|
17
|
+
import { sendMouse } from '../../../test/plugins/browser.js';
|
|
18
|
+
const initTest = async (styles = html ``) => {
|
|
19
|
+
const test = await fixture(html `
|
|
20
|
+
<div class="container">
|
|
21
|
+
<style>
|
|
22
|
+
.container {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
}
|
|
27
|
+
</style>
|
|
28
|
+
${styles}
|
|
29
|
+
<overlay-trigger type="modal" id="trigger" placement="top">
|
|
30
|
+
<sp-button
|
|
31
|
+
id="outer-button"
|
|
32
|
+
variant="primary"
|
|
33
|
+
slot="trigger"
|
|
34
|
+
>
|
|
35
|
+
Show Popover
|
|
36
|
+
</sp-button>
|
|
37
|
+
<sp-popover
|
|
38
|
+
id="outer-popover"
|
|
39
|
+
dialog
|
|
40
|
+
slot="click-content"
|
|
41
|
+
direction="bottom"
|
|
42
|
+
tip
|
|
43
|
+
open
|
|
44
|
+
tabindex="0"
|
|
45
|
+
placement="top"
|
|
46
|
+
>
|
|
47
|
+
This is the overlay content.
|
|
48
|
+
</sp-popover>
|
|
49
|
+
</overlay-trigger>
|
|
50
|
+
</div>
|
|
51
|
+
`);
|
|
52
|
+
return {
|
|
53
|
+
overlayTrigger: test.querySelector('overlay-trigger'),
|
|
54
|
+
button: test.querySelector('sp-button'),
|
|
55
|
+
popover: test.querySelector('sp-popover'),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
describe('Overlay Trigger - extended', () => {
|
|
59
|
+
let overlayTrigger;
|
|
60
|
+
let button;
|
|
61
|
+
let popover;
|
|
62
|
+
afterEach(async () => {
|
|
63
|
+
if (overlayTrigger.open) {
|
|
64
|
+
const closed = oneEvent(overlayTrigger, 'sp-closed');
|
|
65
|
+
overlayTrigger.open = undefined;
|
|
66
|
+
await closed;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
it('manages `placement` on open', async () => {
|
|
70
|
+
({ overlayTrigger, button, popover } = await initTest());
|
|
71
|
+
expect(popover.placement).to.equal('top');
|
|
72
|
+
const open = oneEvent(overlayTrigger, 'sp-opened');
|
|
73
|
+
button.click();
|
|
74
|
+
await open;
|
|
75
|
+
expect(popover.placement).to.equal('bottom');
|
|
76
|
+
const close = oneEvent(overlayTrigger, 'sp-closed');
|
|
77
|
+
overlayTrigger.open = undefined;
|
|
78
|
+
await close;
|
|
79
|
+
expect(popover.placement).to.equal('top');
|
|
80
|
+
});
|
|
81
|
+
it('manages `placement` on scroll', async () => {
|
|
82
|
+
({ overlayTrigger, button, popover } = await initTest(html `
|
|
83
|
+
<style>
|
|
84
|
+
sp-button {
|
|
85
|
+
margin: 100vh 0;
|
|
86
|
+
transform: translateY(-100%);
|
|
87
|
+
}
|
|
88
|
+
</style>
|
|
89
|
+
`));
|
|
90
|
+
expect(popover.placement).to.equal('top');
|
|
91
|
+
const open = oneEvent(overlayTrigger, 'sp-opened');
|
|
92
|
+
button.click();
|
|
93
|
+
await open;
|
|
94
|
+
expect(popover.placement).to.equal('top');
|
|
95
|
+
const { scrollHeight } = document.documentElement;
|
|
96
|
+
document.documentElement.scrollTop = scrollHeight / 2;
|
|
97
|
+
// one frame for scroll to trigger
|
|
98
|
+
await nextFrame();
|
|
99
|
+
// one frame for the UI to update
|
|
100
|
+
await nextFrame();
|
|
101
|
+
// _then_ we test...
|
|
102
|
+
expect(popover.placement).to.equal('bottom');
|
|
103
|
+
});
|
|
104
|
+
it('occludes content behind the overlay', async () => {
|
|
105
|
+
({ overlayTrigger, button, popover } = await initTest());
|
|
106
|
+
const textfield = document.createElement('sp-textfield');
|
|
107
|
+
document.body.append(textfield);
|
|
108
|
+
const boundingRect = textfield.getBoundingClientRect();
|
|
109
|
+
expect(document.activeElement).to.not.equal(textfield);
|
|
110
|
+
await sendMouse({
|
|
111
|
+
steps: [
|
|
112
|
+
{
|
|
113
|
+
type: 'click',
|
|
114
|
+
position: [
|
|
115
|
+
boundingRect.left + boundingRect.width / 2,
|
|
116
|
+
boundingRect.top + boundingRect.height / 2,
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
expect(document.activeElement).to.equal(textfield);
|
|
122
|
+
expect(popover.placement).to.equal('top');
|
|
123
|
+
const open = oneEvent(overlayTrigger, 'sp-opened');
|
|
124
|
+
button.click();
|
|
125
|
+
await open;
|
|
126
|
+
expect(overlayTrigger.open).to.equal('click');
|
|
127
|
+
expect(popover.placement).to.equal('bottom');
|
|
128
|
+
const close = oneEvent(overlayTrigger, 'sp-closed');
|
|
129
|
+
await sendMouse({
|
|
130
|
+
steps: [
|
|
131
|
+
{
|
|
132
|
+
type: 'click',
|
|
133
|
+
position: [
|
|
134
|
+
boundingRect.left + boundingRect.width / 2,
|
|
135
|
+
boundingRect.top + boundingRect.height / 2,
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
await close;
|
|
141
|
+
expect(overlayTrigger.open).to.be.null;
|
|
142
|
+
expect(document.activeElement).to.not.equal(textfield);
|
|
143
|
+
await sendMouse({
|
|
144
|
+
steps: [
|
|
145
|
+
{
|
|
146
|
+
type: 'click',
|
|
147
|
+
position: [
|
|
148
|
+
boundingRect.left + boundingRect.width / 2,
|
|
149
|
+
boundingRect.top + boundingRect.height / 2,
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
expect(document.activeElement).to.equal(textfield);
|
|
155
|
+
textfield.remove();
|
|
156
|
+
});
|
|
157
|
+
it('occludes wheel interactions behind the overlay', async () => {
|
|
158
|
+
({ overlayTrigger, button, popover } = await initTest());
|
|
159
|
+
const scrollingArea = document.createElement('div');
|
|
160
|
+
Object.assign(scrollingArea.style, {
|
|
161
|
+
width: '100px',
|
|
162
|
+
height: '100px',
|
|
163
|
+
overflow: 'auto',
|
|
164
|
+
});
|
|
165
|
+
const content = Array(100).fill('This is content within my box that will scroll.');
|
|
166
|
+
scrollingArea.textContent = content.join(' ');
|
|
167
|
+
document.body.append(scrollingArea);
|
|
168
|
+
await nextFrame();
|
|
169
|
+
const boundingRect = scrollingArea.getBoundingClientRect();
|
|
170
|
+
expect(scrollingArea.scrollTop).to.equal(0);
|
|
171
|
+
const distance = 1;
|
|
172
|
+
await sendMouse({
|
|
173
|
+
steps: [
|
|
174
|
+
{
|
|
175
|
+
type: 'move',
|
|
176
|
+
position: [
|
|
177
|
+
boundingRect.left + boundingRect.width / 2,
|
|
178
|
+
boundingRect.top + boundingRect.height / 2,
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
await sendMouse({
|
|
184
|
+
steps: [
|
|
185
|
+
{
|
|
186
|
+
type: 'wheel',
|
|
187
|
+
position: [0, distance],
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
// wait for scroll to complete
|
|
192
|
+
await waitUntil(() => scrollingArea.scrollTop === distance, `scroll went to ${distance}`);
|
|
193
|
+
expect(scrollingArea.scrollTop).to.equal(distance);
|
|
194
|
+
expect(popover.placement).to.equal('top');
|
|
195
|
+
const open = oneEvent(overlayTrigger, 'sp-opened');
|
|
196
|
+
button.click();
|
|
197
|
+
await open;
|
|
198
|
+
const activeOverlay = document.querySelector('active-overlay');
|
|
199
|
+
await elementUpdated(activeOverlay);
|
|
200
|
+
expect(overlayTrigger.open).to.equal('click');
|
|
201
|
+
expect(popover.placement).to.equal('bottom');
|
|
202
|
+
expect(scrollingArea.scrollTop).to.equal(distance);
|
|
203
|
+
await sendMouse({
|
|
204
|
+
steps: [
|
|
205
|
+
{
|
|
206
|
+
type: 'wheel',
|
|
207
|
+
position: [0, -distance],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
expect(scrollingArea.scrollTop, `scrollTop should be ${distance}.`).to.equal(distance);
|
|
212
|
+
scrollingArea.remove();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
//# sourceMappingURL=overlay-trigger-extended.test.js.map
|