@spectrum-web-components/reactive-controllers 0.47.1 → 0.48.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -2
- package/src/PendingState.d.ts +40 -0
- package/src/PendingState.dev.js +57 -0
- package/src/PendingState.dev.js.map +7 -0
- package/src/PendingState.js +10 -0
- package/src/PendingState.js.map +7 -0
- package/test/pending-state.test.js +128 -0
- package/test/pending-state.test.js.map +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/reactive-controllers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0-beta.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"development": "./src/MatchMedia.dev.js",
|
|
50
50
|
"default": "./src/MatchMedia.js"
|
|
51
51
|
},
|
|
52
|
+
"./src/PendingState.js": {
|
|
53
|
+
"development": "./src/PendingState.dev.js",
|
|
54
|
+
"default": "./src/PendingState.js"
|
|
55
|
+
},
|
|
52
56
|
"./src/RovingTabindex.js": {
|
|
53
57
|
"development": "./src/RovingTabindex.dev.js",
|
|
54
58
|
"default": "./src/RovingTabindex.js"
|
|
@@ -83,5 +87,5 @@
|
|
|
83
87
|
"sideEffects": [
|
|
84
88
|
"./**/*.dev.js"
|
|
85
89
|
],
|
|
86
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "9a1377f0402a17b732b96e17ad06b800df6ab52e"
|
|
87
91
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LitElement, ReactiveController, TemplateResult } from 'lit';
|
|
2
|
+
import '@spectrum-web-components/progress-circle/sp-progress-circle.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a host element with pending state.
|
|
5
|
+
*/
|
|
6
|
+
export interface HostWithPendingState extends LitElement {
|
|
7
|
+
pendingLabel?: string;
|
|
8
|
+
pending: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
pendingStateController: PendingStateController<HostWithPendingState>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Represents a controller for managing the pending state of a reactive element.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type of the reactive element.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PendingStateController<T extends HostWithPendingState> implements ReactiveController {
|
|
18
|
+
/**
|
|
19
|
+
* The host element that this controller is attached to.
|
|
20
|
+
*/
|
|
21
|
+
host: T;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of PendingStateController.
|
|
24
|
+
* @param host - The host element that this controller is attached to.
|
|
25
|
+
*/
|
|
26
|
+
constructor(host: T);
|
|
27
|
+
cachedAriaLabel: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Renders the pending state UI.
|
|
30
|
+
* @returns A TemplateResult representing the pending state UI.
|
|
31
|
+
*/
|
|
32
|
+
renderPendingState(): TemplateResult;
|
|
33
|
+
/**
|
|
34
|
+
* Updates the ARIA label of the host element based on the pending state.
|
|
35
|
+
* Manages Cached Aria Label
|
|
36
|
+
*/
|
|
37
|
+
private updateAriaLabel;
|
|
38
|
+
hostConnected(): void;
|
|
39
|
+
hostUpdated(): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { html } from "lit";
|
|
3
|
+
import "@spectrum-web-components/progress-circle/sp-progress-circle.js";
|
|
4
|
+
export class PendingStateController {
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of PendingStateController.
|
|
7
|
+
* @param host - The host element that this controller is attached to.
|
|
8
|
+
*/
|
|
9
|
+
constructor(host) {
|
|
10
|
+
this.cachedAriaLabel = null;
|
|
11
|
+
this.host = host;
|
|
12
|
+
this.host.addController(this);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Renders the pending state UI.
|
|
16
|
+
* @returns A TemplateResult representing the pending state UI.
|
|
17
|
+
*/
|
|
18
|
+
renderPendingState() {
|
|
19
|
+
const pendingLabel = this.host.pendingLabel || "Pending";
|
|
20
|
+
return this.host.pending ? html`
|
|
21
|
+
<sp-progress-circle
|
|
22
|
+
id="loader"
|
|
23
|
+
size="s"
|
|
24
|
+
indeterminate
|
|
25
|
+
aria-valuetext=${pendingLabel}
|
|
26
|
+
class="progress-circle"
|
|
27
|
+
></sp-progress-circle>
|
|
28
|
+
` : html``;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Updates the ARIA label of the host element based on the pending state.
|
|
32
|
+
* Manages Cached Aria Label
|
|
33
|
+
*/
|
|
34
|
+
updateAriaLabel() {
|
|
35
|
+
const { pending, disabled, pendingLabel } = this.host;
|
|
36
|
+
const currentAriaLabel = this.host.getAttribute("aria-label");
|
|
37
|
+
if (pending && !disabled && currentAriaLabel !== pendingLabel) {
|
|
38
|
+
this.cachedAriaLabel = currentAriaLabel;
|
|
39
|
+
this.host.setAttribute("aria-label", pendingLabel || "Pending");
|
|
40
|
+
} else if (!pending || disabled) {
|
|
41
|
+
if (this.cachedAriaLabel) {
|
|
42
|
+
this.host.setAttribute("aria-label", this.cachedAriaLabel);
|
|
43
|
+
} else if (!pending) {
|
|
44
|
+
this.host.removeAttribute("aria-label");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
hostConnected() {
|
|
49
|
+
if (!this.cachedAriaLabel)
|
|
50
|
+
this.cachedAriaLabel = this.host.getAttribute("aria-label");
|
|
51
|
+
this.updateAriaLabel();
|
|
52
|
+
}
|
|
53
|
+
hostUpdated() {
|
|
54
|
+
this.updateAriaLabel();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=PendingState.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["PendingState.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, LitElement, ReactiveController, TemplateResult } from 'lit';\nimport '@spectrum-web-components/progress-circle/sp-progress-circle.js';\n\n/**\n * Represents a host element with pending state.\n */\nexport interface HostWithPendingState extends LitElement {\n pendingLabel?: string;\n pending: boolean;\n disabled: boolean;\n pendingStateController: PendingStateController<HostWithPendingState>;\n}\n\n/**\n * Represents a controller for managing the pending state of a reactive element.\n *\n * @template T - The type of the reactive element.\n */\nexport class PendingStateController<T extends HostWithPendingState>\n implements ReactiveController\n{\n /**\n * The host element that this controller is attached to.\n */\n public host: T;\n\n /**\n * Creates an instance of PendingStateController.\n * @param host - The host element that this controller is attached to.\n */\n constructor(host: T) {\n this.host = host;\n this.host.addController(this);\n }\n\n public cachedAriaLabel: string | null = null;\n /**\n * Renders the pending state UI.\n * @returns A TemplateResult representing the pending state UI.\n */\n public renderPendingState(): TemplateResult {\n const pendingLabel = this.host.pendingLabel || 'Pending';\n return this.host.pending\n ? html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=${pendingLabel}\n class=\"progress-circle\"\n ></sp-progress-circle>\n `\n : html``;\n }\n\n /**\n * Updates the ARIA label of the host element based on the pending state.\n * Manages Cached Aria Label\n */\n private updateAriaLabel(): void {\n const { pending, disabled, pendingLabel } = this.host;\n const currentAriaLabel = this.host.getAttribute('aria-label');\n\n if (pending && !disabled && currentAriaLabel !== pendingLabel) {\n // Cache the current `aria-label` to be restored when no longer `pending`\n this.cachedAriaLabel = currentAriaLabel;\n // Since it is pending, we set the aria-label to `pendingLabel` or \"Pending\"\n this.host.setAttribute('aria-label', pendingLabel || 'Pending');\n } else if (!pending || disabled) {\n // Restore the cached `aria-label` if it exists\n if (this.cachedAriaLabel) {\n this.host.setAttribute('aria-label', this.cachedAriaLabel);\n } else if (!pending) {\n // If no cached `aria-label` and not `pending`, remove the `aria-label`\n this.host.removeAttribute('aria-label');\n }\n }\n }\n\n hostConnected(): void {\n if (!this.cachedAriaLabel)\n this.cachedAriaLabel = this.host.getAttribute('aria-label');\n this.updateAriaLabel();\n }\n\n hostUpdated(): void {\n this.updateAriaLabel();\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,YAA4D;AACrE,OAAO;AAiBA,aAAM,uBAEb;AAAA;AAAA;AAAA;AAAA;AAAA,EAUI,YAAY,MAAS;AAKrB,SAAO,kBAAiC;AAJpC,SAAK,OAAO;AACZ,SAAK,KAAK,cAAc,IAAI;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,qBAAqC;AACxC,UAAM,eAAe,KAAK,KAAK,gBAAgB;AAC/C,WAAO,KAAK,KAAK,UACX;AAAA;AAAA;AAAA;AAAA;AAAA,uCAKyB,YAAY;AAAA;AAAA;AAAA,kBAIrC;AAAA,EACV;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,kBAAwB;AAC5B,UAAM,EAAE,SAAS,UAAU,aAAa,IAAI,KAAK;AACjD,UAAM,mBAAmB,KAAK,KAAK,aAAa,YAAY;AAE5D,QAAI,WAAW,CAAC,YAAY,qBAAqB,cAAc;AAE3D,WAAK,kBAAkB;AAEvB,WAAK,KAAK,aAAa,cAAc,gBAAgB,SAAS;AAAA,IAClE,WAAW,CAAC,WAAW,UAAU;AAE7B,UAAI,KAAK,iBAAiB;AACtB,aAAK,KAAK,aAAa,cAAc,KAAK,eAAe;AAAA,MAC7D,WAAW,CAAC,SAAS;AAEjB,aAAK,KAAK,gBAAgB,YAAY;AAAA,MAC1C;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,gBAAsB;AAClB,QAAI,CAAC,KAAK;AACN,WAAK,kBAAkB,KAAK,KAAK,aAAa,YAAY;AAC9D,SAAK,gBAAgB;AAAA,EACzB;AAAA,EAEA,cAAoB;AAChB,SAAK,gBAAgB;AAAA,EACzB;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";import{html as s}from"lit";import"@spectrum-web-components/progress-circle/sp-progress-circle.js";export class PendingStateController{constructor(e){this.cachedAriaLabel=null;this.host=e,this.host.addController(this)}renderPendingState(){const e=this.host.pendingLabel||"Pending";return this.host.pending?s`
|
|
2
|
+
<sp-progress-circle
|
|
3
|
+
id="loader"
|
|
4
|
+
size="s"
|
|
5
|
+
indeterminate
|
|
6
|
+
aria-valuetext=${e}
|
|
7
|
+
class="progress-circle"
|
|
8
|
+
></sp-progress-circle>
|
|
9
|
+
`:s``}updateAriaLabel(){const{pending:e,disabled:t,pendingLabel:i}=this.host,a=this.host.getAttribute("aria-label");e&&!t&&a!==i?(this.cachedAriaLabel=a,this.host.setAttribute("aria-label",i||"Pending")):(!e||t)&&(this.cachedAriaLabel?this.host.setAttribute("aria-label",this.cachedAriaLabel):e||this.host.removeAttribute("aria-label"))}hostConnected(){this.cachedAriaLabel||(this.cachedAriaLabel=this.host.getAttribute("aria-label")),this.updateAriaLabel()}hostUpdated(){this.updateAriaLabel()}}
|
|
10
|
+
//# sourceMappingURL=PendingState.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["PendingState.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2024 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, LitElement, ReactiveController, TemplateResult } from 'lit';\nimport '@spectrum-web-components/progress-circle/sp-progress-circle.js';\n\n/**\n * Represents a host element with pending state.\n */\nexport interface HostWithPendingState extends LitElement {\n pendingLabel?: string;\n pending: boolean;\n disabled: boolean;\n pendingStateController: PendingStateController<HostWithPendingState>;\n}\n\n/**\n * Represents a controller for managing the pending state of a reactive element.\n *\n * @template T - The type of the reactive element.\n */\nexport class PendingStateController<T extends HostWithPendingState>\n implements ReactiveController\n{\n /**\n * The host element that this controller is attached to.\n */\n public host: T;\n\n /**\n * Creates an instance of PendingStateController.\n * @param host - The host element that this controller is attached to.\n */\n constructor(host: T) {\n this.host = host;\n this.host.addController(this);\n }\n\n public cachedAriaLabel: string | null = null;\n /**\n * Renders the pending state UI.\n * @returns A TemplateResult representing the pending state UI.\n */\n public renderPendingState(): TemplateResult {\n const pendingLabel = this.host.pendingLabel || 'Pending';\n return this.host.pending\n ? html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=${pendingLabel}\n class=\"progress-circle\"\n ></sp-progress-circle>\n `\n : html``;\n }\n\n /**\n * Updates the ARIA label of the host element based on the pending state.\n * Manages Cached Aria Label\n */\n private updateAriaLabel(): void {\n const { pending, disabled, pendingLabel } = this.host;\n const currentAriaLabel = this.host.getAttribute('aria-label');\n\n if (pending && !disabled && currentAriaLabel !== pendingLabel) {\n // Cache the current `aria-label` to be restored when no longer `pending`\n this.cachedAriaLabel = currentAriaLabel;\n // Since it is pending, we set the aria-label to `pendingLabel` or \"Pending\"\n this.host.setAttribute('aria-label', pendingLabel || 'Pending');\n } else if (!pending || disabled) {\n // Restore the cached `aria-label` if it exists\n if (this.cachedAriaLabel) {\n this.host.setAttribute('aria-label', this.cachedAriaLabel);\n } else if (!pending) {\n // If no cached `aria-label` and not `pending`, remove the `aria-label`\n this.host.removeAttribute('aria-label');\n }\n }\n }\n\n hostConnected(): void {\n if (!this.cachedAriaLabel)\n this.cachedAriaLabel = this.host.getAttribute('aria-label');\n this.updateAriaLabel();\n }\n\n hostUpdated(): void {\n this.updateAriaLabel();\n }\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OAAS,QAAAA,MAA4D,MACrE,MAAO,iEAiBA,aAAM,sBAEb,CAUI,YAAYC,EAAS,CAKrB,KAAO,gBAAiC,KAJpC,KAAK,KAAOA,EACZ,KAAK,KAAK,cAAc,IAAI,CAChC,CAOO,oBAAqC,CACxC,MAAMC,EAAe,KAAK,KAAK,cAAgB,UAC/C,OAAO,KAAK,KAAK,QACXF;AAAA;AAAA;AAAA;AAAA;AAAA,uCAKyBE,CAAY;AAAA;AAAA;AAAA,gBAIrCF,GACV,CAMQ,iBAAwB,CAC5B,KAAM,CAAE,QAAAG,EAAS,SAAAC,EAAU,aAAAF,CAAa,EAAI,KAAK,KAC3CG,EAAmB,KAAK,KAAK,aAAa,YAAY,EAExDF,GAAW,CAACC,GAAYC,IAAqBH,GAE7C,KAAK,gBAAkBG,EAEvB,KAAK,KAAK,aAAa,aAAcH,GAAgB,SAAS,IACvD,CAACC,GAAWC,KAEf,KAAK,gBACL,KAAK,KAAK,aAAa,aAAc,KAAK,eAAe,EACjDD,GAER,KAAK,KAAK,gBAAgB,YAAY,EAGlD,CAEA,eAAsB,CACb,KAAK,kBACN,KAAK,gBAAkB,KAAK,KAAK,aAAa,YAAY,GAC9D,KAAK,gBAAgB,CACzB,CAEA,aAAoB,CAChB,KAAK,gBAAgB,CACzB,CACJ",
|
|
6
|
+
"names": ["html", "host", "pendingLabel", "pending", "disabled", "currentAriaLabel"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { expect, fixture, html } from "@open-wc/testing";
|
|
3
|
+
import "@spectrum-web-components/progress-circle/sp-progress-circle.js";
|
|
4
|
+
import "@spectrum-web-components/picker/sp-picker.js";
|
|
5
|
+
describe("PendingStateController", () => {
|
|
6
|
+
let host;
|
|
7
|
+
let controller;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
host = await fixture(html`
|
|
10
|
+
<sp-picker aria-label="clickable" pending></sp-picker>
|
|
11
|
+
`);
|
|
12
|
+
controller = host.pendingStateController;
|
|
13
|
+
});
|
|
14
|
+
describe("renderPendingState", () => {
|
|
15
|
+
it("should change aria-label of host when pending and when not pending", async () => {
|
|
16
|
+
host = await fixture(html`
|
|
17
|
+
<sp-picker></sp-picker>
|
|
18
|
+
`);
|
|
19
|
+
controller = host.pendingStateController;
|
|
20
|
+
host.setAttribute("pending", "true");
|
|
21
|
+
await host.updateComplete;
|
|
22
|
+
let ariaLabel = host.getAttribute("aria-label");
|
|
23
|
+
expect(ariaLabel).to.equal("Pending");
|
|
24
|
+
host.removeAttribute("pending");
|
|
25
|
+
await host.updateComplete;
|
|
26
|
+
ariaLabel = host.getAttribute("aria-label");
|
|
27
|
+
expect(ariaLabel).to.equal(null);
|
|
28
|
+
host.setAttribute("aria-label", "clickable");
|
|
29
|
+
await host.updateComplete;
|
|
30
|
+
ariaLabel = host.getAttribute("aria-label");
|
|
31
|
+
expect(ariaLabel).to.equal("clickable");
|
|
32
|
+
host.setAttribute("pending", "true");
|
|
33
|
+
await host.updateComplete;
|
|
34
|
+
ariaLabel = host.getAttribute("aria-label");
|
|
35
|
+
expect(ariaLabel).to.equal("Pending");
|
|
36
|
+
host.removeAttribute("pending");
|
|
37
|
+
await host.updateComplete;
|
|
38
|
+
ariaLabel = host.getAttribute("aria-label");
|
|
39
|
+
expect(ariaLabel).to.equal("clickable");
|
|
40
|
+
host.setAttribute("pending", "true");
|
|
41
|
+
await host.updateComplete;
|
|
42
|
+
ariaLabel = host.getAttribute("aria-label");
|
|
43
|
+
expect(ariaLabel).to.equal("Pending");
|
|
44
|
+
});
|
|
45
|
+
it("should render the pending state UI", async () => {
|
|
46
|
+
const pendingLabel = "Custom Pending Label";
|
|
47
|
+
host.pendingLabel = pendingLabel;
|
|
48
|
+
const templateResult = controller.renderPendingState();
|
|
49
|
+
const renderedElement = await fixture(html`
|
|
50
|
+
${templateResult}
|
|
51
|
+
`);
|
|
52
|
+
const expectedElement = await fixture(html`
|
|
53
|
+
<sp-progress-circle
|
|
54
|
+
id="loader"
|
|
55
|
+
size="s"
|
|
56
|
+
indeterminate
|
|
57
|
+
aria-valuetext=${pendingLabel}
|
|
58
|
+
class="progress-circle"
|
|
59
|
+
></sp-progress-circle>
|
|
60
|
+
`);
|
|
61
|
+
expect(renderedElement.outerHTML === expectedElement.outerHTML).to.be.true;
|
|
62
|
+
});
|
|
63
|
+
it("should render the default pending state UI if no label is provided", async () => {
|
|
64
|
+
host.pendingLabel = void 0;
|
|
65
|
+
const templateResult = controller.renderPendingState();
|
|
66
|
+
const renderedElement = await fixture(html`
|
|
67
|
+
${templateResult}
|
|
68
|
+
`);
|
|
69
|
+
const expectedElement = await fixture(html`
|
|
70
|
+
<sp-progress-circle
|
|
71
|
+
id="loader"
|
|
72
|
+
size="s"
|
|
73
|
+
indeterminate
|
|
74
|
+
aria-valuetext="Pending"
|
|
75
|
+
class="progress-circle"
|
|
76
|
+
></sp-progress-circle>
|
|
77
|
+
`);
|
|
78
|
+
const renderedAttributes = renderedElement.attributes;
|
|
79
|
+
const expectedAttributes = expectedElement.attributes;
|
|
80
|
+
expect(renderedAttributes.length === expectedAttributes.length).to.be.true;
|
|
81
|
+
for (let i = 0; i < renderedAttributes.length; i++) {
|
|
82
|
+
const renderedAttr = renderedAttributes[i];
|
|
83
|
+
const expectedAttr = expectedAttributes.getNamedItem(
|
|
84
|
+
renderedAttr.name
|
|
85
|
+
);
|
|
86
|
+
expect(renderedAttr.value === (expectedAttr == null ? void 0 : expectedAttr.value)).to.be.true;
|
|
87
|
+
}
|
|
88
|
+
expect(host.pending).to.be.true;
|
|
89
|
+
});
|
|
90
|
+
it("should toggle the pending state on and off and preserve the component state correctly", async () => {
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
host.setAttribute("pending", "true");
|
|
93
|
+
await host.updateComplete;
|
|
94
|
+
let progressCircle = (_a = host.shadowRoot) == null ? void 0 : _a.querySelector("sp-progress-circle");
|
|
95
|
+
expect(progressCircle).to.not.be.null;
|
|
96
|
+
host.removeAttribute("pending");
|
|
97
|
+
await host.updateComplete;
|
|
98
|
+
progressCircle = (_b = host.shadowRoot) == null ? void 0 : _b.querySelector("sp-progress-circle");
|
|
99
|
+
expect(progressCircle).to.be.null;
|
|
100
|
+
host.setAttribute("pending", "true");
|
|
101
|
+
await host.updateComplete;
|
|
102
|
+
progressCircle = (_c = host.shadowRoot) == null ? void 0 : _c.querySelector("sp-progress-circle");
|
|
103
|
+
expect(progressCircle).to.not.be.null;
|
|
104
|
+
const expectedElement = await fixture(html`
|
|
105
|
+
<sp-progress-circle
|
|
106
|
+
id="loader"
|
|
107
|
+
size="s"
|
|
108
|
+
indeterminate
|
|
109
|
+
aria-valuetext="Pending"
|
|
110
|
+
class="progress-circle"
|
|
111
|
+
></sp-progress-circle>
|
|
112
|
+
`);
|
|
113
|
+
const renderedAttributes = progressCircle == null ? void 0 : progressCircle.attributes;
|
|
114
|
+
const expectedAttributes = expectedElement.attributes;
|
|
115
|
+
expect((renderedAttributes == null ? void 0 : renderedAttributes.length) === expectedAttributes.length).to.be.true;
|
|
116
|
+
if (renderedAttributes) {
|
|
117
|
+
for (let i = 0; i < renderedAttributes.length; i++) {
|
|
118
|
+
const renderedAttr = renderedAttributes[i];
|
|
119
|
+
const expectedAttr = expectedAttributes.getNamedItem(
|
|
120
|
+
renderedAttr.name
|
|
121
|
+
);
|
|
122
|
+
expect(renderedAttr.value === (expectedAttr == null ? void 0 : expectedAttr.value)).to.be.true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=pending-state.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["pending-state.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\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 { expect, fixture, html } from '@open-wc/testing';\nimport {\n HostWithPendingState,\n PendingStateController,\n} from '@spectrum-web-components/reactive-controllers/src/PendingState.js';\n\nimport '@spectrum-web-components/progress-circle/sp-progress-circle.js';\nimport '@spectrum-web-components/picker/sp-picker.js';\n\ndescribe('PendingStateController', () => {\n let host: HostWithPendingState;\n let controller: PendingStateController<HostWithPendingState>;\n\n beforeEach(async () => {\n host = await fixture<HostWithPendingState>(html`\n <sp-picker aria-label=\"clickable\" pending></sp-picker>\n `);\n controller = host.pendingStateController;\n });\n\n describe('renderPendingState', () => {\n it('should change aria-label of host when pending and when not pending', async () => {\n host = await fixture<HostWithPendingState>(html`\n <sp-picker></sp-picker>\n `);\n controller = host.pendingStateController;\n\n host.setAttribute('pending', 'true');\n await host.updateComplete;\n\n let ariaLabel = host.getAttribute('aria-label');\n expect(ariaLabel).to.equal('Pending');\n\n host.removeAttribute('pending');\n await host.updateComplete;\n\n ariaLabel = host.getAttribute('aria-label');\n expect(ariaLabel).to.equal(null);\n\n host.setAttribute('aria-label', 'clickable');\n await host.updateComplete;\n ariaLabel = host.getAttribute('aria-label');\n expect(ariaLabel).to.equal('clickable');\n host.setAttribute('pending', 'true');\n\n await host.updateComplete;\n ariaLabel = host.getAttribute('aria-label');\n expect(ariaLabel).to.equal('Pending');\n\n host.removeAttribute('pending');\n await host.updateComplete;\n ariaLabel = host.getAttribute('aria-label');\n expect(ariaLabel).to.equal('clickable');\n\n host.setAttribute('pending', 'true');\n await host.updateComplete;\n ariaLabel = host.getAttribute('aria-label');\n expect(ariaLabel).to.equal('Pending');\n });\n\n it('should render the pending state UI', async () => {\n const pendingLabel = 'Custom Pending Label';\n host.pendingLabel = pendingLabel;\n const templateResult = controller.renderPendingState();\n\n const renderedElement = await fixture(html`\n ${templateResult}\n `);\n const expectedElement = await fixture(html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=${pendingLabel}\n class=\"progress-circle\"\n ></sp-progress-circle>\n `);\n\n expect(renderedElement.outerHTML === expectedElement.outerHTML).to\n .be.true;\n });\n\n it('should render the default pending state UI if no label is provided', async () => {\n host.pendingLabel = undefined;\n const templateResult = controller.renderPendingState();\n const renderedElement = await fixture(html`\n ${templateResult}\n `);\n const expectedElement = await fixture(html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=\"Pending\"\n class=\"progress-circle\"\n ></sp-progress-circle>\n `);\n\n const renderedAttributes = renderedElement.attributes;\n const expectedAttributes = expectedElement.attributes;\n\n expect(renderedAttributes.length === expectedAttributes.length).to\n .be.true;\n\n for (let i = 0; i < renderedAttributes.length; i++) {\n const renderedAttr = renderedAttributes[i];\n const expectedAttr = expectedAttributes.getNamedItem(\n renderedAttr.name\n );\n\n expect(renderedAttr.value === expectedAttr?.value).to.be.true;\n }\n expect(host.pending).to.be.true;\n });\n\n it('should toggle the pending state on and off and preserve the component state correctly', async () => {\n // Set initial pending state to true\n host.setAttribute('pending', 'true');\n await host.updateComplete;\n let progressCircle =\n host.shadowRoot?.querySelector('sp-progress-circle');\n expect(progressCircle).to.not.be.null;\n host.removeAttribute('pending');\n await host.updateComplete;\n progressCircle =\n host.shadowRoot?.querySelector('sp-progress-circle');\n expect(progressCircle).to.be.null;\n host.setAttribute('pending', 'true');\n await host.updateComplete;\n progressCircle =\n host.shadowRoot?.querySelector('sp-progress-circle');\n expect(progressCircle).to.not.be.null;\n const expectedElement = await fixture(html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=\"Pending\"\n class=\"progress-circle\"\n ></sp-progress-circle>\n `);\n\n const renderedAttributes = progressCircle?.attributes;\n const expectedAttributes = expectedElement.attributes;\n expect(renderedAttributes?.length === expectedAttributes.length).to\n .be.true;\n if (renderedAttributes) {\n for (let i = 0; i < renderedAttributes.length; i++) {\n const renderedAttr = renderedAttributes[i];\n const expectedAttr = expectedAttributes.getNamedItem(\n renderedAttr.name\n );\n\n expect(renderedAttr.value === expectedAttr?.value).to.be\n .true;\n }\n }\n });\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAaA,SAAS,QAAQ,SAAS,YAAY;AAMtC,OAAO;AACP,OAAO;AAEP,SAAS,0BAA0B,MAAM;AACrC,MAAI;AACJ,MAAI;AAEJ,aAAW,YAAY;AACnB,WAAO,MAAM,QAA8B;AAAA;AAAA,SAE1C;AACD,iBAAa,KAAK;AAAA,EACtB,CAAC;AAED,WAAS,sBAAsB,MAAM;AACjC,OAAG,sEAAsE,YAAY;AACjF,aAAO,MAAM,QAA8B;AAAA;AAAA,aAE1C;AACD,mBAAa,KAAK;AAElB,WAAK,aAAa,WAAW,MAAM;AACnC,YAAM,KAAK;AAEX,UAAI,YAAY,KAAK,aAAa,YAAY;AAC9C,aAAO,SAAS,EAAE,GAAG,MAAM,SAAS;AAEpC,WAAK,gBAAgB,SAAS;AAC9B,YAAM,KAAK;AAEX,kBAAY,KAAK,aAAa,YAAY;AAC1C,aAAO,SAAS,EAAE,GAAG,MAAM,IAAI;AAE/B,WAAK,aAAa,cAAc,WAAW;AAC3C,YAAM,KAAK;AACX,kBAAY,KAAK,aAAa,YAAY;AAC1C,aAAO,SAAS,EAAE,GAAG,MAAM,WAAW;AACtC,WAAK,aAAa,WAAW,MAAM;AAEnC,YAAM,KAAK;AACX,kBAAY,KAAK,aAAa,YAAY;AAC1C,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