@spectrum-web-components/tooltip 1.1.0 → 1.1.2

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.
Files changed (58) hide show
  1. package/package.json +6 -6
  2. package/sp-tooltip.d.ts +6 -0
  3. package/sp-tooltip.dev.js +5 -0
  4. package/sp-tooltip.dev.js.map +7 -0
  5. package/sp-tooltip.js +2 -0
  6. package/sp-tooltip.js.map +7 -0
  7. package/src/Tooltip.d.ts +48 -0
  8. package/src/Tooltip.dev.js +259 -0
  9. package/src/Tooltip.dev.js.map +7 -0
  10. package/src/Tooltip.js +29 -0
  11. package/src/Tooltip.js.map +7 -0
  12. package/src/index.d.ts +1 -0
  13. package/src/index.dev.js +3 -0
  14. package/src/index.dev.js.map +7 -0
  15. package/src/index.js +2 -0
  16. package/src/index.js.map +7 -0
  17. package/src/spectrum-tooltip.css.d.ts +2 -0
  18. package/src/spectrum-tooltip.css.dev.js +7 -0
  19. package/src/spectrum-tooltip.css.dev.js.map +7 -0
  20. package/src/spectrum-tooltip.css.js +4 -0
  21. package/src/spectrum-tooltip.css.js.map +7 -0
  22. package/src/tooltip-directive.d.ts +5 -0
  23. package/src/tooltip-directive.dev.js +27 -0
  24. package/src/tooltip-directive.dev.js.map +7 -0
  25. package/src/tooltip-directive.js +6 -0
  26. package/src/tooltip-directive.js.map +7 -0
  27. package/src/tooltip-overrides.css.d.ts +2 -0
  28. package/src/tooltip-overrides.css.dev.js +7 -0
  29. package/src/tooltip-overrides.css.dev.js.map +7 -0
  30. package/src/tooltip-overrides.css.js +4 -0
  31. package/src/tooltip-overrides.css.js.map +7 -0
  32. package/src/tooltip.css.d.ts +2 -0
  33. package/src/tooltip.css.dev.js +7 -0
  34. package/src/tooltip.css.dev.js.map +7 -0
  35. package/src/tooltip.css.js +4 -0
  36. package/src/tooltip.css.js.map +7 -0
  37. package/stories/tooltip-directive.stories.js +117 -0
  38. package/stories/tooltip-directive.stories.js.map +7 -0
  39. package/stories/tooltip.stories.js +409 -0
  40. package/stories/tooltip.stories.js.map +7 -0
  41. package/test/benchmark/test-basic.js +12 -0
  42. package/test/benchmark/test-basic.js.map +7 -0
  43. package/test/benchmark/test-directive.js +13 -0
  44. package/test/benchmark/test-directive.js.map +7 -0
  45. package/test/benchmark/test-element.js +13 -0
  46. package/test/benchmark/test-element.js.map +7 -0
  47. package/test/benchmark/test-lazy.js +24 -0
  48. package/test/benchmark/test-lazy.js.map +7 -0
  49. package/test/tooltip-directive.test-vrt.js +5 -0
  50. package/test/tooltip-directive.test-vrt.js.map +7 -0
  51. package/test/tooltip-directive.test.js +101 -0
  52. package/test/tooltip-directive.test.js.map +7 -0
  53. package/test/tooltip-memory.test.js +8 -0
  54. package/test/tooltip-memory.test.js.map +7 -0
  55. package/test/tooltip.test-vrt.js +5 -0
  56. package/test/tooltip.test-vrt.js.map +7 -0
  57. package/test/tooltip.test.js +235 -0
  58. package/test/tooltip.test.js.map +7 -0
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ import "@spectrum-web-components/tooltip/sp-tooltip.js";
3
+ import {
4
+ elementUpdated,
5
+ expect,
6
+ html,
7
+ nextFrame,
8
+ oneEvent
9
+ } from "@open-wc/testing";
10
+ import "@spectrum-web-components/button/sp-button.js";
11
+ import { tooltip } from "@spectrum-web-components/tooltip/src/tooltip-directive.js";
12
+ import { sendKeys } from "@web/test-runner-commands";
13
+ import { render } from "@spectrum-web-components/base";
14
+ describe("Tooltip Directive", () => {
15
+ const renderTooltip = () => html`
16
+ Tip me!
17
+ `;
18
+ function renderButton(...directiveParams) {
19
+ return html`
20
+ <sp-button ${tooltip(...directiveParams)}>
21
+ I'm a button...
22
+ </sp-button>
23
+ `;
24
+ }
25
+ function opensTooltip() {
26
+ it("opens tooltip not previously on DOM", async function() {
27
+ await elementUpdated(this.el);
28
+ const input = document.createElement("input");
29
+ this.el.insertAdjacentElement("beforebegin", input);
30
+ this.overlays = document.querySelectorAll("sp-overlay");
31
+ expect(this.overlays.length).to.equal(0);
32
+ const opened = oneEvent(this.el, "sp-opened");
33
+ input.focus();
34
+ await sendKeys({
35
+ press: "Tab"
36
+ });
37
+ expect(document.activeElement === this.el).to.be.true;
38
+ expect(this.el.matches(":focus-visible")).to.be.true;
39
+ await opened;
40
+ this.overlays = document.querySelectorAll("sp-overlay");
41
+ expect(this.overlays.length).to.equal(1);
42
+ });
43
+ }
44
+ function closesTooltip() {
45
+ it("closes a tooltip and removes it from the DOM", async function() {
46
+ const closed = oneEvent(this.overlays[0], "slottable-request");
47
+ this.el.blur();
48
+ await closed;
49
+ await nextFrame();
50
+ await nextFrame();
51
+ this.overlays = document.querySelectorAll("sp-overlay");
52
+ expect(this.overlays.length).to.equal(0);
53
+ });
54
+ }
55
+ describe("template only", () => {
56
+ before(async function() {
57
+ this.testEl = document.createElement("div");
58
+ document.body.append(this.testEl);
59
+ render(renderButton(renderTooltip), this.testEl);
60
+ this.el = this.testEl.querySelector("sp-button");
61
+ this.overlays = null;
62
+ });
63
+ after(function() {
64
+ this.testEl.remove();
65
+ });
66
+ opensTooltip();
67
+ closesTooltip();
68
+ });
69
+ describe("with `options`", () => {
70
+ before(async function() {
71
+ this.variant = "positive";
72
+ this.offset = 10;
73
+ this.testEl = document.createElement("div");
74
+ document.body.append(this.testEl);
75
+ render(
76
+ renderButton(renderTooltip, {
77
+ variant: this.variant,
78
+ overlayOptions: {
79
+ offset: this.offset
80
+ }
81
+ }),
82
+ this.testEl
83
+ );
84
+ this.el = this.testEl.querySelector("sp-button");
85
+ this.overlays = null;
86
+ });
87
+ after(function() {
88
+ this.testEl.remove();
89
+ });
90
+ opensTooltip();
91
+ it("passes `options` to the overlay", async function() {
92
+ expect(this.overlays[0].offset).to.equal(this.offset);
93
+ const tooltipEl = this.overlays[0].querySelector(
94
+ "sp-tooltip"
95
+ );
96
+ expect(tooltipEl.variant).to.equal(this.variant);
97
+ });
98
+ closesTooltip();
99
+ });
100
+ });
101
+ //# sourceMappingURL=tooltip-directive.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["tooltip-directive.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport {\n elementUpdated,\n expect,\n html,\n nextFrame,\n oneEvent,\n} from '@open-wc/testing';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { tooltip } from '@spectrum-web-components/tooltip/src/tooltip-directive.js';\nimport type { Tooltip } from '@spectrum-web-components/tooltip';\nimport { sendKeys } from '@web/test-runner-commands';\nimport { render, TemplateResult } from '@spectrum-web-components/base';\n\ndescribe('Tooltip Directive', () => {\n const renderTooltip = (): TemplateResult =>\n html`\n Tip me!\n `;\n function renderButton(\n ...directiveParams: Parameters<typeof tooltip>\n ): TemplateResult {\n return html`\n <sp-button ${tooltip(...directiveParams)}>\n I'm a button...\n </sp-button>\n `;\n }\n function opensTooltip(): void {\n it('opens tooltip not previously on DOM', async function () {\n await elementUpdated(this.el);\n\n const input = document.createElement('input');\n this.el.insertAdjacentElement('beforebegin', input);\n\n this.overlays = document.querySelectorAll('sp-overlay');\n expect(this.overlays.length).to.equal(0);\n\n const opened = oneEvent(this.el, 'sp-opened');\n input.focus();\n await sendKeys({\n press: 'Tab',\n });\n expect(document.activeElement === this.el).to.be.true;\n expect(this.el.matches(':focus-visible')).to.be.true;\n await opened;\n\n this.overlays = document.querySelectorAll('sp-overlay');\n expect(this.overlays.length).to.equal(1);\n });\n }\n function closesTooltip(): void {\n it('closes a tooltip and removes it from the DOM', async function () {\n // `slottable-request` comes _after_ `sp-closed` and triggers DOM cleanup\n const closed = oneEvent(this.overlays[0], 'slottable-request');\n this.el.blur();\n await closed;\n\n // Wait for DOM clean up to complete\n await nextFrame();\n await nextFrame();\n\n this.overlays = document.querySelectorAll('sp-overlay');\n expect(this.overlays.length).to.equal(0);\n });\n }\n describe('template only', () => {\n before(async function () {\n this.testEl = document.createElement('div');\n document.body.append(this.testEl);\n render(renderButton(renderTooltip), this.testEl);\n this.el = this.testEl.querySelector('sp-button');\n this.overlays = null;\n });\n after(function () {\n this.testEl.remove();\n });\n opensTooltip();\n closesTooltip();\n });\n describe('with `options`', () => {\n before(async function () {\n this.variant = 'positive';\n this.offset = 10;\n this.testEl = document.createElement('div');\n document.body.append(this.testEl);\n render(\n renderButton(renderTooltip, {\n variant: this.variant,\n overlayOptions: {\n offset: this.offset,\n },\n }),\n this.testEl\n );\n this.el = this.testEl.querySelector('sp-button');\n this.overlays = null;\n });\n after(function () {\n this.testEl.remove();\n });\n opensTooltip();\n it('passes `options` to the overlay', async function () {\n expect(this.overlays[0].offset).to.equal(this.offset);\n const tooltipEl = this.overlays[0].querySelector(\n 'sp-tooltip'\n ) as Tooltip;\n expect(tooltipEl.variant).to.equal(this.variant);\n });\n closesTooltip();\n });\n});\n"],
5
+ "mappings": ";AAYA,OAAO;AACP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,OAAO;AACP,SAAS,eAAe;AAExB,SAAS,gBAAgB;AACzB,SAAS,cAA8B;AAEvC,SAAS,qBAAqB,MAAM;AAChC,QAAM,gBAAgB,MAClB;AAAA;AAAA;AAGJ,WAAS,gBACF,iBACW;AACd,WAAO;AAAA,yBACU,QAAQ,GAAG,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA,EAIhD;AACA,WAAS,eAAqB;AAC1B,OAAG,uCAAuC,iBAAkB;AACxD,YAAM,eAAe,KAAK,EAAE;AAE5B,YAAM,QAAQ,SAAS,cAAc,OAAO;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,WAAK,SAAS,SAAS,cAAc,KAAK;AAC1C,eAAS,KAAK,OAAO,KAAK,MAAM;AAChC;AAAA,QACI,aAAa,eAAe;AAAA,UACxB,SAAS,KAAK;AAAA,UACd,gBAAgB;AAAA,YACZ,QAAQ,KAAK;AAAA,UACjB;AAAA,QACJ,CAAC;AAAA,QACD,KAAK;AAAA,MACT;AACA,WAAK,KAAK,KAAK,OAAO,cAAc,WAAW;AAC/C,WAAK,WAAW;AAAA,IACpB,CAAC;AACD,UAAM,WAAY;AACd,WAAK,OAAO,OAAO;AAAA,IACvB,CAAC;AACD,iBAAa;AACb,OAAG,mCAAmC,iBAAkB;AACpD,aAAO,KAAK,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,MAAM;AACpD,YAAM,YAAY,KAAK,SAAS,CAAC,EAAE;AAAA,QAC/B;AAAA,MACJ;AACA,aAAO,UAAU,OAAO,EAAE,GAAG,MAAM,KAAK,OAAO;AAAA,IACnD,CAAC;AACD,kBAAc;AAAA,EAClB,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ import { html } from "@open-wc/testing";
3
+ import "@spectrum-web-components/tooltip/sp-tooltip.js";
4
+ import { testForMemoryLeaks } from "../../../test/testing-helpers.js";
5
+ testForMemoryLeaks(html`
6
+ <sp-tooltip></sp-tooltip>
7
+ `);
8
+ //# sourceMappingURL=tooltip-memory.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["tooltip-memory.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2023 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html } from '@open-wc/testing';\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport { testForMemoryLeaks } from '../../../test/testing-helpers.js';\n\ntestForMemoryLeaks(html`\n <sp-tooltip></sp-tooltip>\n`);\n"],
5
+ "mappings": ";AAWA,SAAS,YAAY;AACrB,OAAO;AACP,SAAS,0BAA0B;AAEnC,mBAAmB;AAAA;AAAA,CAElB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ import * as stories from "../stories/tooltip.stories.js";
3
+ import { regressVisuals } from "../../../test/visual/test.js";
4
+ regressVisuals("TooltipStories", stories);
5
+ //# sourceMappingURL=tooltip.test-vrt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["tooltip.test-vrt.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/tooltip.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\nimport type { TestsType } from '../../../test/visual/test.js';\n\nregressVisuals('TooltipStories', stories as unknown as TestsType);\n"],
5
+ "mappings": ";AAYA,YAAY,aAAa;AACzB,SAAS,sBAAsB;AAG/B,eAAe,kBAAkB,OAA+B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ import "@spectrum-web-components/tooltip/sp-tooltip.js";
3
+ import {
4
+ elementUpdated,
5
+ expect,
6
+ fixture,
7
+ html,
8
+ nextFrame,
9
+ oneEvent
10
+ } from "@open-wc/testing";
11
+ import "@spectrum-web-components/button/sp-button.js";
12
+ import { spy, stub } from "sinon";
13
+ import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
14
+ import { sendMouse } from "../../../test/plugins/browser.js";
15
+ describe("Tooltip", () => {
16
+ testForLitDevWarnings(
17
+ async () => await fixture(html`
18
+ <sp-tooltip>Help text.</sp-tooltip>
19
+ `)
20
+ );
21
+ it("loads", async () => {
22
+ const el = await fixture(html`
23
+ <sp-tooltip>Help text.</sp-tooltip>
24
+ `);
25
+ await elementUpdated(el);
26
+ await expect(el).to.be.accessible();
27
+ });
28
+ it("self manages", async () => {
29
+ await sendMouse({
30
+ steps: [
31
+ {
32
+ type: "move",
33
+ position: [1, 1]
34
+ }
35
+ ]
36
+ });
37
+ const button = await fixture(html`
38
+ <sp-button>
39
+ This is a button.
40
+ <sp-tooltip self-managed placement="top">Help text.</sp-tooltip>
41
+ </sp-button>
42
+ `);
43
+ const el = button.querySelector("sp-tooltip");
44
+ await elementUpdated(el);
45
+ await nextFrame();
46
+ await nextFrame();
47
+ await nextFrame();
48
+ await nextFrame();
49
+ await expect(button).to.be.accessible();
50
+ const opened = oneEvent(button, "sp-opened");
51
+ button.focus();
52
+ await opened;
53
+ expect(el.open).to.be.true;
54
+ await expect(button).to.be.accessible();
55
+ const closed = oneEvent(button, "sp-closed");
56
+ button.blur();
57
+ await closed;
58
+ expect(el.open).to.be.false;
59
+ });
60
+ it("self manages through a shadow boundary", async () => {
61
+ const test = await fixture(html`
62
+ <div></div>
63
+ `);
64
+ test.attachShadow({ mode: "open" });
65
+ if (!test.shadowRoot) return;
66
+ test.shadowRoot.innerHTML = `
67
+ <sp-button>
68
+ This is a button.
69
+ <sp-tooltip self-managed placement="top">
70
+ Help text.
71
+ </sp-tooltip>
72
+ </sp-button>
73
+ `;
74
+ const button = test.shadowRoot.querySelector("sp-button");
75
+ const el = test.shadowRoot.querySelector("sp-tooltip");
76
+ await elementUpdated(el);
77
+ await nextFrame();
78
+ await nextFrame();
79
+ await nextFrame();
80
+ await nextFrame();
81
+ const opened = oneEvent(button, "sp-opened");
82
+ button.focus();
83
+ await opened;
84
+ expect(el.open).to.be.true;
85
+ await expect(button).to.be.accessible();
86
+ const closed = oneEvent(button, "sp-closed");
87
+ button.blur();
88
+ await closed;
89
+ expect(el.open).to.be.false;
90
+ });
91
+ it("cleans up when self manages", async () => {
92
+ const button = await fixture(html`
93
+ <sp-button>
94
+ This is a button.
95
+ <sp-tooltip self-managed>Help text.</sp-tooltip>
96
+ </sp-button>
97
+ `);
98
+ const el = button.querySelector("sp-tooltip");
99
+ await elementUpdated(el);
100
+ expect(el.open).to.be.false;
101
+ const opened = oneEvent(button, "sp-opened");
102
+ button.focus();
103
+ await opened;
104
+ await elementUpdated(el);
105
+ expect(el.open).to.be.true;
106
+ const closed = oneEvent(button, "sp-closed");
107
+ button.blur();
108
+ await closed;
109
+ expect(el.open).to.be.false;
110
+ });
111
+ it("cleans up when self managed and removed", async () => {
112
+ const button = await fixture(html`
113
+ <sp-button>
114
+ This is a button.
115
+ <sp-tooltip self-managed>Help text.</sp-tooltip>
116
+ </sp-button>
117
+ `);
118
+ const el = button.querySelector("sp-tooltip");
119
+ await elementUpdated(el);
120
+ expect(el.open).to.be.false;
121
+ const opened = oneEvent(button, "sp-opened");
122
+ button.focus();
123
+ await opened;
124
+ expect(el.open).to.be.true;
125
+ const closed = oneEvent(button, "sp-closed");
126
+ button.remove();
127
+ await closed;
128
+ expect(el.open).to.be.false;
129
+ });
130
+ it("accepts variants", async () => {
131
+ const el = await fixture(html`
132
+ <sp-tooltip variant="negative">Help text.</sp-tooltip>
133
+ `);
134
+ await elementUpdated(el);
135
+ expect(el.variant).to.equal("negative");
136
+ expect(el.getAttribute("variant")).to.equal("negative");
137
+ el.variant = "info";
138
+ await elementUpdated(el);
139
+ expect(el.variant).to.equal("info");
140
+ expect(el.getAttribute("variant")).to.equal("info");
141
+ el.setAttribute("variant", "positive");
142
+ await elementUpdated(el);
143
+ expect(el.variant).to.equal("positive");
144
+ expect(el.getAttribute("variant")).to.equal("positive");
145
+ el.removeAttribute("variant");
146
+ await elementUpdated(el);
147
+ expect(el.variant).to.equal("");
148
+ expect(el.hasAttribute("variant")).to.be.false;
149
+ });
150
+ it("validates variants", async () => {
151
+ const el = await fixture(html`
152
+ <sp-tooltip variant="other">Help text.</sp-tooltip>
153
+ `);
154
+ await elementUpdated(el);
155
+ expect(el.variant).to.equal("");
156
+ expect(el.hasAttribute("variant")).to.be.false;
157
+ el.variant = "info";
158
+ await elementUpdated(el);
159
+ expect(el.variant).to.equal("info");
160
+ expect(el.getAttribute("variant")).to.equal("info");
161
+ el.variant = "info";
162
+ await elementUpdated(el);
163
+ expect(el.variant).to.equal("info");
164
+ expect(el.getAttribute("variant")).to.equal("info");
165
+ });
166
+ it("surfaces tip element", async () => {
167
+ const el = await fixture(html`
168
+ <sp-tooltip placement="top">Help text.</sp-tooltip>
169
+ `);
170
+ await elementUpdated(el);
171
+ expect(typeof el.tipElement).to.not.equal("undefined");
172
+ });
173
+ describe("self-managed", () => {
174
+ let documentEventsSpy;
175
+ before(() => {
176
+ documentEventsSpy = spy(document, "addEventListener");
177
+ });
178
+ afterEach(() => {
179
+ documentEventsSpy.resetHistory();
180
+ });
181
+ after(() => {
182
+ documentEventsSpy.restore();
183
+ });
184
+ it("does not attach event listeners if no trigger was found", async function() {
185
+ var _a;
186
+ const el = await fixture(html`
187
+ <sp-tooltip self-managed>Help text.</sp-tooltip>
188
+ `);
189
+ await elementUpdated(el);
190
+ let calls = documentEventsSpy.callCount;
191
+ while (calls) {
192
+ calls -= 1;
193
+ const call = documentEventsSpy.getCall(calls);
194
+ expect(call.args[0]).to.not.equal("pointerenter");
195
+ }
196
+ expect((_a = el.overlayElement) == null ? void 0 : _a.triggerElement).to.be.null;
197
+ });
198
+ });
199
+ describe("dev mode", () => {
200
+ let consoleWarnStub;
201
+ before(() => {
202
+ window.__swc.verbose = true;
203
+ consoleWarnStub = stub(console, "warn");
204
+ });
205
+ afterEach(() => {
206
+ consoleWarnStub.resetHistory();
207
+ });
208
+ after(() => {
209
+ window.__swc.verbose = false;
210
+ consoleWarnStub.restore();
211
+ });
212
+ it("warns when incorrectly using `self-managed`", async () => {
213
+ const el = await fixture(html`
214
+ <sp-tooltip variant="negative" self-managed>
215
+ Help text.
216
+ </sp-tooltip>
217
+ `);
218
+ await elementUpdated(el);
219
+ expect(consoleWarnStub.called).to.be.true;
220
+ const spyCall = consoleWarnStub.getCall(0);
221
+ expect(
222
+ spyCall.args.at(0).includes("Self managed"),
223
+ "confirm self managed-centric message"
224
+ ).to.be.true;
225
+ expect(spyCall.args.at(-1), "confirm `data` shape").to.deep.equal({
226
+ data: {
227
+ localName: "sp-tooltip",
228
+ type: "api",
229
+ level: "high"
230
+ }
231
+ });
232
+ });
233
+ });
234
+ });
235
+ //# sourceMappingURL=tooltip.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["tooltip.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/tooltip/sp-tooltip.js';\nimport { Tooltip } from '@spectrum-web-components/tooltip';\nimport {\n elementUpdated,\n expect,\n fixture,\n html,\n nextFrame,\n oneEvent,\n} from '@open-wc/testing';\nimport { Button } from '@spectrum-web-components/button';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { spy, stub } from 'sinon';\nimport { testForLitDevWarnings } from '../../../test/testing-helpers.js';\nimport { sendMouse } from '../../../test/plugins/browser.js';\n\ndescribe('Tooltip', () => {\n testForLitDevWarnings(\n async () =>\n await fixture<Tooltip>(html`\n <sp-tooltip>Help text.</sp-tooltip>\n `)\n );\n it('loads', async () => {\n const el = await fixture<Tooltip>(html`\n <sp-tooltip>Help text.</sp-tooltip>\n `);\n\n await elementUpdated(el);\n\n await expect(el).to.be.accessible();\n });\n it('self manages', async () => {\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [1, 1],\n },\n ],\n });\n const button = await fixture<Button>(html`\n <sp-button>\n This is a button.\n <sp-tooltip self-managed placement=\"top\">Help text.</sp-tooltip>\n </sp-button>\n `);\n\n const el = button.querySelector('sp-tooltip') as Tooltip;\n\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await expect(button).to.be.accessible();\n\n const opened = oneEvent(button, 'sp-opened');\n button.focus();\n await opened;\n\n expect(el.open).to.be.true;\n await expect(button).to.be.accessible();\n\n const closed = oneEvent(button, 'sp-closed');\n button.blur();\n await closed;\n\n expect(el.open).to.be.false;\n });\n it('self manages through a shadow boundary', async () => {\n const test = await fixture<HTMLDivElement>(html`\n <div></div>\n `);\n test.attachShadow({ mode: 'open' });\n if (!test.shadowRoot) return;\n test.shadowRoot.innerHTML = `\n <sp-button>\n This is a button.\n <sp-tooltip self-managed placement=\"top\">\n Help text.\n </sp-tooltip>\n </sp-button>\n `;\n\n const button = test.shadowRoot.querySelector('sp-button') as Button;\n const el = test.shadowRoot.querySelector('sp-tooltip') as Tooltip;\n\n await elementUpdated(el);\n await nextFrame();\n await nextFrame();\n await nextFrame();\n await nextFrame();\n\n const opened = oneEvent(button, 'sp-opened');\n button.focus();\n await opened;\n\n expect(el.open).to.be.true;\n await expect(button).to.be.accessible();\n\n const closed = oneEvent(button, 'sp-closed');\n button.blur();\n await closed;\n\n expect(el.open).to.be.false;\n });\n it('cleans up when self manages', async () => {\n const button = await fixture<Button>(html`\n <sp-button>\n This is a button.\n <sp-tooltip self-managed>Help text.</sp-tooltip>\n </sp-button>\n `);\n\n const el = button.querySelector('sp-tooltip') as Tooltip;\n\n await elementUpdated(el);\n\n expect(el.open).to.be.false;\n const opened = oneEvent(button, 'sp-opened');\n button.focus();\n await opened;\n await elementUpdated(el);\n\n expect(el.open).to.be.true;\n\n const closed = oneEvent(button, 'sp-closed');\n button.blur();\n await closed;\n\n expect(el.open).to.be.false;\n });\n it('cleans up when self managed and removed', async () => {\n const button = await fixture<Button>(html`\n <sp-button>\n This is a button.\n <sp-tooltip self-managed>Help text.</sp-tooltip>\n </sp-button>\n `);\n\n const el = button.querySelector('sp-tooltip') as Tooltip;\n\n await elementUpdated(el);\n\n expect(el.open).to.be.false;\n const opened = oneEvent(button, 'sp-opened');\n button.focus();\n await opened;\n\n expect(el.open).to.be.true;\n\n const closed = oneEvent(button, 'sp-closed');\n button.remove();\n await closed;\n\n expect(el.open).to.be.false;\n });\n it('accepts variants', async () => {\n const el = await fixture<Tooltip>(html`\n <sp-tooltip variant=\"negative\">Help text.</sp-tooltip>\n `);\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('negative');\n expect(el.getAttribute('variant')).to.equal('negative');\n\n el.variant = 'info';\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('info');\n expect(el.getAttribute('variant')).to.equal('info');\n\n el.setAttribute('variant', 'positive');\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('positive');\n expect(el.getAttribute('variant')).to.equal('positive');\n\n el.removeAttribute('variant');\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('');\n expect(el.hasAttribute('variant')).to.be.false;\n });\n it('validates variants', async () => {\n const el = await fixture<Tooltip>(html`\n <sp-tooltip variant=\"other\">Help text.</sp-tooltip>\n `);\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('');\n expect(el.hasAttribute('variant')).to.be.false;\n\n el.variant = 'info';\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('info');\n expect(el.getAttribute('variant')).to.equal('info');\n\n el.variant = 'info';\n\n await elementUpdated(el);\n\n expect(el.variant).to.equal('info');\n expect(el.getAttribute('variant')).to.equal('info');\n });\n\n it('surfaces tip element', async () => {\n const el = await fixture<Tooltip>(html`\n <sp-tooltip placement=\"top\">Help text.</sp-tooltip>\n `);\n\n await elementUpdated(el);\n\n expect(typeof el.tipElement).to.not.equal('undefined');\n });\n describe('self-managed', () => {\n let documentEventsSpy!: ReturnType<typeof spy>;\n before(() => {\n documentEventsSpy = spy(document, 'addEventListener');\n });\n afterEach(() => {\n documentEventsSpy.resetHistory();\n });\n after(() => {\n documentEventsSpy.restore();\n });\n it('does not attach event listeners if no trigger was found', async function () {\n const el = await fixture<Tooltip>(html`\n <sp-tooltip self-managed>Help text.</sp-tooltip>\n `);\n\n await elementUpdated(el);\n let calls = documentEventsSpy.callCount;\n while (calls) {\n calls -= 1;\n const call = documentEventsSpy.getCall(calls);\n expect(call.args[0]).to.not.equal('pointerenter');\n }\n expect(el.overlayElement?.triggerElement).to.be.null;\n });\n });\n describe('dev mode', () => {\n let consoleWarnStub!: ReturnType<typeof stub>;\n before(() => {\n window.__swc.verbose = true;\n consoleWarnStub = stub(console, 'warn');\n });\n afterEach(() => {\n consoleWarnStub.resetHistory();\n });\n after(() => {\n window.__swc.verbose = false;\n consoleWarnStub.restore();\n });\n\n it('warns when incorrectly using `self-managed`', async () => {\n const el = await fixture<Tooltip>(html`\n <sp-tooltip variant=\"negative\" self-managed>\n Help text.\n </sp-tooltip>\n `);\n\n await elementUpdated(el);\n\n expect(consoleWarnStub.called).to.be.true;\n const spyCall = consoleWarnStub.getCall(0);\n expect(\n (spyCall.args.at(0) as string).includes('Self managed'),\n 'confirm self managed-centric message'\n ).to.be.true;\n expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({\n data: {\n localName: 'sp-tooltip',\n type: 'api',\n level: 'high',\n },\n });\n });\n });\n});\n"],
5
+ "mappings": ";AAYA,OAAO;AAEP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,OAAO;AACP,SAAS,KAAK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