@spectrum-web-components/toast 0.10.6 → 0.10.7
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/toast",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@spectrum-web-components/base": "^0.5.4",
|
|
48
|
-
"@spectrum-web-components/button": "^0.17.
|
|
48
|
+
"@spectrum-web-components/button": "^0.17.2",
|
|
49
49
|
"@spectrum-web-components/icon": "^0.11.5",
|
|
50
50
|
"@spectrum-web-components/icons-workflow": "^0.8.5",
|
|
51
51
|
"tslib": "^2.0.0"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"sideEffects": [
|
|
59
59
|
"./sp-*.js"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "dd76f9532fdea946880147cc7645f113b998c326"
|
|
62
62
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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/toast/sp-toast.js';
|
|
13
|
+
import { html } from 'lit';
|
|
14
|
+
import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
|
|
15
|
+
measureFixtureCreation(html `
|
|
16
|
+
<sp-toast>Tip me!</sp-toast>
|
|
17
|
+
`);
|
|
18
|
+
//# sourceMappingURL=test-basic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-basic.js","sourceRoot":"","sources":["test-basic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,4CAA4C,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,sBAAsB,CAAC,IAAI,CAAA;;CAE1B,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/toast/sp-toast.js';\nimport { html } from 'lit';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-toast>Tip me!</sp-toast>\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/toast.stories.js';
|
|
13
|
+
import { regressVisuals } from '../../../test/visual/test.js';
|
|
14
|
+
regressVisuals('ToastStories', stories);
|
|
15
|
+
//# sourceMappingURL=toast.test-vrt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.test-vrt.js","sourceRoot":"","sources":["toast.test-vrt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,KAAK,OAAO,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,cAAc,CAAC,cAAc,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/toast.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\n\nregressVisuals('ToastStories', stories);\n"]}
|
|
@@ -0,0 +1,201 @@
|
|
|
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 '../sp-toast.js';
|
|
13
|
+
import { toastVariants } from '../';
|
|
14
|
+
import { elementUpdated, expect, fixture, html, nextFrame, waitUntil, } from '@open-wc/testing';
|
|
15
|
+
import { waitForPredicate } from '../../../test/testing-helpers.js';
|
|
16
|
+
import { spy } from 'sinon';
|
|
17
|
+
describe('Toast', () => {
|
|
18
|
+
it('loads', async () => {
|
|
19
|
+
const el = await fixture(html `
|
|
20
|
+
<sp-toast open>Help text.</sp-toast>
|
|
21
|
+
`);
|
|
22
|
+
await elementUpdated(el);
|
|
23
|
+
await expect(el).to.be.accessible();
|
|
24
|
+
});
|
|
25
|
+
toastVariants.map((variant) => {
|
|
26
|
+
it(`loads - [variant="${variant}"]`, async () => {
|
|
27
|
+
const el = await fixture(html `
|
|
28
|
+
<sp-toast variant=${variant} open>
|
|
29
|
+
This toast is of the \`${variant}\` variant.
|
|
30
|
+
</sp-toast>
|
|
31
|
+
`);
|
|
32
|
+
await elementUpdated(el);
|
|
33
|
+
await expect(el).to.be.accessible();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('loads - timeout', async () => {
|
|
37
|
+
const el = await fixture(html `
|
|
38
|
+
<sp-toast timeout="100">Help text.</sp-toast>
|
|
39
|
+
`);
|
|
40
|
+
await elementUpdated(el);
|
|
41
|
+
expect(el.open).to.be.false;
|
|
42
|
+
el._timeout = 100;
|
|
43
|
+
el.open = true;
|
|
44
|
+
await elementUpdated(el);
|
|
45
|
+
await waitForPredicate(() => el.open === false);
|
|
46
|
+
expect(el.open).to.be.false;
|
|
47
|
+
});
|
|
48
|
+
it('`timeout` updates `countdownStart`', async () => {
|
|
49
|
+
const el = await fixture(html `
|
|
50
|
+
<sp-toast timeout="100">Help text.</sp-toast>
|
|
51
|
+
`);
|
|
52
|
+
await elementUpdated(el);
|
|
53
|
+
expect(el.open).to.be.false;
|
|
54
|
+
const testableEl = el;
|
|
55
|
+
testableEl._timeout = 100;
|
|
56
|
+
el.open = true;
|
|
57
|
+
await elementUpdated(el);
|
|
58
|
+
const firstStart = testableEl.countdownStart;
|
|
59
|
+
await nextFrame();
|
|
60
|
+
await nextFrame();
|
|
61
|
+
await nextFrame();
|
|
62
|
+
el.timeout = 400;
|
|
63
|
+
await elementUpdated(el);
|
|
64
|
+
const secondStart = testableEl.countdownStart;
|
|
65
|
+
expect(secondStart).to.not.equal(firstStart);
|
|
66
|
+
await nextFrame();
|
|
67
|
+
await nextFrame();
|
|
68
|
+
el.timeout = 0;
|
|
69
|
+
await elementUpdated(el);
|
|
70
|
+
const thirdStart = testableEl.countdownStart;
|
|
71
|
+
expect(thirdStart).to.equal(0);
|
|
72
|
+
});
|
|
73
|
+
it('stops timeout on `focusin`', async () => {
|
|
74
|
+
const el = await fixture(html `
|
|
75
|
+
<sp-toast timeout="100">Help text.</sp-toast>
|
|
76
|
+
`);
|
|
77
|
+
await elementUpdated(el);
|
|
78
|
+
const testableEl = el;
|
|
79
|
+
expect(el.open, 'not open to start').to.be.false;
|
|
80
|
+
el.open = true;
|
|
81
|
+
await elementUpdated(el);
|
|
82
|
+
await nextFrame();
|
|
83
|
+
expect(testableEl.countdownStart, 'initially not 0').to.not.equal(0);
|
|
84
|
+
testableEl._timeout = 100;
|
|
85
|
+
el.dispatchEvent(new FocusEvent('focusin'));
|
|
86
|
+
await elementUpdated(el);
|
|
87
|
+
expect(testableEl.countdownStart, '0 after focusin').to.equal(0);
|
|
88
|
+
el.dispatchEvent(new FocusEvent('focusout'));
|
|
89
|
+
await elementUpdated(el);
|
|
90
|
+
await nextFrame();
|
|
91
|
+
expect(testableEl.countdownStart, 'not 0 after focusout').to.not.equal(0);
|
|
92
|
+
await waitUntil(() => el.open === false, 'closes');
|
|
93
|
+
expect(el.open, 'not open to end').to.be.false;
|
|
94
|
+
});
|
|
95
|
+
it('closes', async () => {
|
|
96
|
+
const el = await fixture(html `
|
|
97
|
+
<sp-toast open>Help text.</sp-toast>
|
|
98
|
+
`);
|
|
99
|
+
await elementUpdated(el);
|
|
100
|
+
expect(el.open).to.be.true;
|
|
101
|
+
const renderRoot = el.shadowRoot ? el.shadowRoot : el;
|
|
102
|
+
const closeButton = renderRoot.querySelector('sp-close-button');
|
|
103
|
+
closeButton.click();
|
|
104
|
+
await elementUpdated(el);
|
|
105
|
+
expect(el.open).to.be.false;
|
|
106
|
+
});
|
|
107
|
+
it('`close` can be prevented', async () => {
|
|
108
|
+
const handleClose = (event) => event.preventDefault();
|
|
109
|
+
const el = await fixture(html `
|
|
110
|
+
<sp-toast open timeout="100" @close=${handleClose}>
|
|
111
|
+
Help text.
|
|
112
|
+
</sp-toast>
|
|
113
|
+
`);
|
|
114
|
+
await elementUpdated(el);
|
|
115
|
+
expect(el.open).to.be.true;
|
|
116
|
+
const renderRoot = el.shadowRoot ? el.shadowRoot : el;
|
|
117
|
+
const closeButton = renderRoot.querySelector('sp-close-button');
|
|
118
|
+
closeButton.click();
|
|
119
|
+
await elementUpdated(el);
|
|
120
|
+
expect(el.open).to.be.true;
|
|
121
|
+
});
|
|
122
|
+
it('can be a controlled element', async () => {
|
|
123
|
+
const closeSpy = spy();
|
|
124
|
+
const handleClose = (event) => {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
closeSpy();
|
|
127
|
+
};
|
|
128
|
+
const el = await fixture(html `
|
|
129
|
+
<sp-toast open timeout="100" @close=${handleClose}>
|
|
130
|
+
Help text.
|
|
131
|
+
</sp-toast>
|
|
132
|
+
`);
|
|
133
|
+
await elementUpdated(el);
|
|
134
|
+
expect(el.open).to.be.true;
|
|
135
|
+
expect(closeSpy.callCount).to.equal(0);
|
|
136
|
+
const renderRoot = el.shadowRoot ? el.shadowRoot : el;
|
|
137
|
+
const closeButton = renderRoot.querySelector('sp-close-button');
|
|
138
|
+
closeButton.click();
|
|
139
|
+
await elementUpdated(el);
|
|
140
|
+
expect(el.open).to.be.true;
|
|
141
|
+
expect(closeSpy.callCount).to.equal(1);
|
|
142
|
+
el.open = false;
|
|
143
|
+
await elementUpdated(el);
|
|
144
|
+
expect(el.open).to.be.false;
|
|
145
|
+
expect(closeSpy.callCount).to.equal(1);
|
|
146
|
+
});
|
|
147
|
+
it('validates variants', async () => {
|
|
148
|
+
const el = await fixture(html `
|
|
149
|
+
<sp-toast variant="invalid" open>
|
|
150
|
+
This toast validates variants.
|
|
151
|
+
</sp-toast>
|
|
152
|
+
`);
|
|
153
|
+
await elementUpdated(el);
|
|
154
|
+
expect(el.variant).to.equal('');
|
|
155
|
+
el.variant = toastVariants[0];
|
|
156
|
+
await elementUpdated(el);
|
|
157
|
+
expect(el.variant).to.equal(toastVariants[0]);
|
|
158
|
+
el.variant = toastVariants[0];
|
|
159
|
+
await elementUpdated(el);
|
|
160
|
+
expect(el.variant).to.equal(toastVariants[0]);
|
|
161
|
+
});
|
|
162
|
+
it('maintains [variant] when disconnected/connected', async () => {
|
|
163
|
+
const el = await fixture(html `
|
|
164
|
+
<sp-toast variant="positive" open>
|
|
165
|
+
This toast maintains variants.
|
|
166
|
+
</sp-toast>
|
|
167
|
+
`);
|
|
168
|
+
await elementUpdated(el);
|
|
169
|
+
expect(el.variant).to.equal('positive');
|
|
170
|
+
const parent = el.parentElement;
|
|
171
|
+
el.remove();
|
|
172
|
+
expect(el.variant).to.equal('positive');
|
|
173
|
+
parent.append(el);
|
|
174
|
+
expect(el.variant).to.equal('positive');
|
|
175
|
+
});
|
|
176
|
+
it('reopens', async () => {
|
|
177
|
+
const closeSpy = spy();
|
|
178
|
+
const el = await fixture(html `
|
|
179
|
+
<sp-toast
|
|
180
|
+
variant="positive"
|
|
181
|
+
open
|
|
182
|
+
@close=${() => {
|
|
183
|
+
closeSpy();
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
This toast maintains variants.
|
|
187
|
+
</sp-toast>
|
|
188
|
+
`);
|
|
189
|
+
await elementUpdated(el);
|
|
190
|
+
expect(el.open).to.be.true;
|
|
191
|
+
const closeButton = el.shadowRoot.querySelector('sp-close-button');
|
|
192
|
+
closeButton.click();
|
|
193
|
+
await elementUpdated(el);
|
|
194
|
+
expect(el.open).to.be.false;
|
|
195
|
+
el.open = true;
|
|
196
|
+
await elementUpdated(el);
|
|
197
|
+
expect(el.open).to.be.true;
|
|
198
|
+
expect(closeSpy.callCount).to.equal(1);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=toast.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.test.js","sourceRoot":"","sources":["toast.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAS,aAAa,EAAE,MAAM,KAAK,CAAC;AAC3C,OAAO,EACH,cAAc,EACd,MAAM,EACN,OAAO,EACP,IAAI,EACJ,SAAS,EACT,SAAS,GACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAO5B,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACnB,EAAE,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE;QACnB,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QAEF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC,CAAC,CAAC;IACH,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1B,EAAE,CAAC,qBAAqB,OAAO,IAAI,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;wCACoB,OAAO;iDACE,OAA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AAG,EAAE,CAAC,UAAU,CAAC,aAAa,CAC3C,iBAAiB,CACL,CAAC;QACjB,WAAW,CAAC,KAAK,EAAE,CAAC;QAEpB,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QACzB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAE5B,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;QAEf,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QACzB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QAC3B,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3C,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 '../sp-toast.js';\nimport { Toast, toastVariants } from '../';\nimport {\n elementUpdated,\n expect,\n fixture,\n html,\n nextFrame,\n waitUntil,\n} from '@open-wc/testing';\nimport { CloseButton } from '@spectrum-web-components/button';\nimport { waitForPredicate } from '../../../test/testing-helpers.js';\nimport { spy } from 'sinon';\n\ninterface TestableToast {\n _timeout: number;\n countdownStart: number;\n}\n\ndescribe('Toast', () => {\n it('loads', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast open>Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n toastVariants.map((variant) => {\n it(`loads - [variant=\"${variant}\"]`, async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast variant=${variant} open>\n This toast is of the \\`${variant}\\` variant.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n });\n it('loads - timeout', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast timeout=\"100\">Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n\n (el as unknown as TestableToast)._timeout = 100;\n el.open = true;\n await elementUpdated(el);\n\n await waitForPredicate(() => el.open === false);\n expect(el.open).to.be.false;\n });\n it('`timeout` updates `countdownStart`', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast timeout=\"100\">Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n\n const testableEl = el as unknown as TestableToast;\n testableEl._timeout = 100;\n el.open = true;\n await elementUpdated(el);\n\n const firstStart = testableEl.countdownStart;\n\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n el.timeout = 400;\n\n await elementUpdated(el);\n const secondStart = testableEl.countdownStart;\n\n expect(secondStart).to.not.equal(firstStart);\n\n await nextFrame();\n await nextFrame();\n\n el.timeout = 0;\n\n await elementUpdated(el);\n const thirdStart = testableEl.countdownStart;\n\n expect(thirdStart).to.equal(0);\n });\n it('stops timeout on `focusin`', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast timeout=\"100\">Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n\n const testableEl = el as unknown as TestableToast;\n expect(el.open, 'not open to start').to.be.false;\n\n el.open = true;\n await elementUpdated(el);\n await nextFrame();\n\n expect(testableEl.countdownStart, 'initially not 0').to.not.equal(0);\n\n testableEl._timeout = 100;\n\n el.dispatchEvent(new FocusEvent('focusin'));\n\n await elementUpdated(el);\n expect(testableEl.countdownStart, '0 after focusin').to.equal(0);\n el.dispatchEvent(new FocusEvent('focusout'));\n\n await elementUpdated(el);\n await nextFrame();\n expect(testableEl.countdownStart, 'not 0 after focusout').to.not.equal(\n 0\n );\n\n await waitUntil(() => el.open === false, 'closes');\n expect(el.open, 'not open to end').to.be.false;\n });\n it('closes', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast open>Help text.</sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n\n const renderRoot = el.shadowRoot ? el.shadowRoot : el;\n const closeButton = renderRoot.querySelector(\n 'sp-close-button'\n ) as CloseButton;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n });\n it('`close` can be prevented', async () => {\n const handleClose = (event: CustomEvent): void =>\n event.preventDefault();\n const el = await fixture<Toast>(\n html`\n <sp-toast open timeout=\"100\" @close=${handleClose}>\n Help text.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n\n const renderRoot = el.shadowRoot ? el.shadowRoot : el;\n const closeButton = renderRoot.querySelector(\n 'sp-close-button'\n ) as CloseButton;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n });\n it('can be a controlled element', async () => {\n const closeSpy = spy();\n const handleClose = (event: CustomEvent): void => {\n event.preventDefault();\n closeSpy();\n };\n const el = await fixture<Toast>(\n html`\n <sp-toast open timeout=\"100\" @close=${handleClose}>\n Help text.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n expect(closeSpy.callCount).to.equal(0);\n\n const renderRoot = el.shadowRoot ? el.shadowRoot : el;\n const closeButton = renderRoot.querySelector(\n 'sp-close-button'\n ) as CloseButton;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n expect(closeSpy.callCount).to.equal(1);\n\n el.open = false;\n await elementUpdated(el);\n expect(el.open).to.be.false;\n expect(closeSpy.callCount).to.equal(1);\n });\n it('validates variants', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast variant=\"invalid\" open>\n This toast validates variants.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.variant).to.equal('');\n\n el.variant = toastVariants[0];\n\n await elementUpdated(el);\n expect(el.variant).to.equal(toastVariants[0]);\n\n el.variant = toastVariants[0];\n\n await elementUpdated(el);\n expect(el.variant).to.equal(toastVariants[0]);\n });\n it('maintains [variant] when disconnected/connected', async () => {\n const el = await fixture<Toast>(\n html`\n <sp-toast variant=\"positive\" open>\n This toast maintains variants.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.variant).to.equal('positive');\n const parent = el.parentElement as HTMLElement;\n\n el.remove();\n\n expect(el.variant).to.equal('positive');\n\n parent.append(el);\n\n expect(el.variant).to.equal('positive');\n });\n it('reopens', async () => {\n const closeSpy = spy();\n const el = await fixture<Toast>(\n html`\n <sp-toast\n variant=\"positive\"\n open\n @close=${() => {\n closeSpy();\n }}\n >\n This toast maintains variants.\n </sp-toast>\n `\n );\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n\n const closeButton = el.shadowRoot.querySelector(\n 'sp-close-button'\n ) as HTMLElement;\n closeButton.click();\n\n await elementUpdated(el);\n expect(el.open).to.be.false;\n\n el.open = true;\n\n await elementUpdated(el);\n expect(el.open).to.be.true;\n expect(closeSpy.callCount).to.equal(1);\n });\n});\n"]}
|