@govtechsg/sgds-web-component 0.0.7 → 0.0.10
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/.github/workflows/publish-latest.yml +22 -0
- package/.github/workflows/publish-pr.yml +28 -0
- package/.husky/commit-msg +4 -0
- package/.husky/prepare-commit-msg +8 -0
- package/.storybook/main.js +16 -0
- package/.storybook/preview-head.html +11 -0
- package/.storybook/preview.js +9 -0
- package/.vscode/settings.json +7 -0
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +20 -0
- package/amplify.yml +22 -0
- package/commitlint.config.js +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/button-element.scss.html +112 -0
- package/coverage/lcov-report/button-element.ts.html +145 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +116 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +32 -0
- package/index.html +430 -0
- package/{Button → lib/Button}/index.d.ts +0 -0
- package/{Button → lib/Button}/index.js +304 -39
- package/lib/Button/index.js.map +1 -0
- package/{Button → lib/Button}/package.json +0 -0
- package/lib/Button/sgds-button.d.ts +48 -0
- package/lib/Card/index.d.ts +1 -0
- package/lib/Card/index.js +6150 -0
- package/lib/Card/index.js.map +1 -0
- package/lib/Card/package.json +7 -0
- package/lib/Card/sgds-action-card.d.ts +20 -0
- package/lib/Checkbox/index.d.ts +1 -0
- package/lib/Checkbox/index.js +6366 -0
- package/lib/Checkbox/index.js.map +1 -0
- package/lib/Checkbox/package.json +7 -0
- package/lib/Checkbox/sgds-checkbox.d.ts +36 -0
- package/lib/Dropdown/index.d.ts +3 -0
- package/{Mainnav → lib/Dropdown}/index.js +2786 -9258
- package/lib/Dropdown/index.js.map +1 -0
- package/lib/Dropdown/package.json +7 -0
- package/lib/Dropdown/sgds-dropdown-item.d.ts +7 -0
- package/lib/Dropdown/sgds-dropdown.d.ts +7 -0
- package/{Footer → lib/Footer}/index.d.ts +0 -0
- package/{Footer → lib/Footer}/index.js +111 -95
- package/lib/Footer/index.js.map +1 -0
- package/{Footer → lib/Footer}/package.json +0 -0
- package/{Footer → lib/Footer}/sgds-footer.d.ts +2 -2
- package/lib/Input/index.d.ts +1 -0
- package/lib/Input/index.js +6656 -0
- package/lib/Input/index.js.map +1 -0
- package/lib/Input/package.json +7 -0
- package/lib/Input/sgds-input.d.ts +42 -0
- package/{Mainnav → lib/Mainnav}/index.d.ts +1 -0
- package/{index.js → lib/Mainnav/index.js} +3876 -23415
- package/lib/Mainnav/index.js.map +1 -0
- package/{Mainnav → lib/Mainnav}/package.json +0 -0
- package/lib/Mainnav/sgds-mainnav-dropdown.d.ts +5 -0
- package/lib/Mainnav/sgds-mainnav-item.d.ts +4 -0
- package/{Mainnav → lib/Mainnav}/sgds-mainnav.d.ts +3 -2
- package/{Masthead → lib/Masthead}/index.d.ts +0 -0
- package/{Masthead → lib/Masthead}/index.js +140 -114
- package/lib/Masthead/index.js.map +1 -0
- package/{Masthead → lib/Masthead}/package.json +0 -0
- package/{Masthead → lib/Masthead}/sgds-masthead.d.ts +1 -1
- package/lib/Modal/index.d.ts +1 -0
- package/lib/Modal/index.js +6432 -0
- package/lib/Modal/index.js.map +1 -0
- package/lib/Modal/package.json +7 -0
- package/lib/Modal/sgds-modal.d.ts +28 -0
- package/lib/QuantityToggle/index.d.ts +1 -0
- package/lib/QuantityToggle/index.js +7049 -0
- package/lib/QuantityToggle/index.js.map +1 -0
- package/lib/QuantityToggle/package.json +7 -0
- package/lib/QuantityToggle/sgds-quantitytoggle.d.ts +30 -0
- package/lib/Radio/index.d.ts +2 -0
- package/lib/Radio/index.js +12607 -0
- package/lib/Radio/index.js.map +1 -0
- package/lib/Radio/package.json +7 -0
- package/lib/Radio/sgds-radio.d.ts +31 -0
- package/lib/Radio/sgds-radiogroup.d.ts +41 -0
- package/{Sidenav → lib/Sidenav}/index.d.ts +0 -0
- package/{Sidenav → lib/Sidenav}/index.js +2266 -2171
- package/lib/Sidenav/index.js.map +1 -0
- package/{Sidenav → lib/Sidenav}/package.json +0 -0
- package/{Sidenav → lib/Sidenav}/sgds-sidenav-item.d.ts +2 -1
- package/lib/Sidenav/sgds-sidenav-link.d.ts +4 -0
- package/{Sidenav → lib/Sidenav}/sgds-sidenav.d.ts +1 -1
- package/lib/Tab/index.d.ts +3 -0
- package/lib/Tab/index.js +13557 -0
- package/lib/Tab/index.js.map +1 -0
- package/lib/Tab/package.json +7 -0
- package/lib/Tab/sgds-tab.d.ts +26 -0
- package/lib/Tab/sgds-tabgroup.d.ts +47 -0
- package/lib/Tab/sgds-tabpanel.d.ts +25 -0
- package/lib/Textarea/index.d.ts +1 -0
- package/lib/Textarea/index.js +6696 -0
- package/lib/Textarea/index.js.map +1 -0
- package/lib/Textarea/package.json +7 -0
- package/lib/Textarea/sgds-textarea.d.ts +53 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +134580 -0
- package/lib/index.js.map +1 -0
- package/lib/umd/index.js +134587 -0
- package/lib/umd/index.js.map +1 -0
- package/lib/utils/animate.d.ts +10 -0
- package/lib/utils/animation-registry.d.ts +18 -0
- package/{utils → lib/utils}/breakpoints.d.ts +0 -0
- package/lib/utils/card-element.d.ts +11 -0
- package/lib/utils/defaultvalue.d.ts +2 -0
- package/lib/utils/dropdown-element.d.ts +37 -0
- package/lib/utils/event.d.ts +2 -0
- package/lib/utils/form.d.ts +38 -0
- package/{utils → lib/utils}/generateId.d.ts +0 -0
- package/lib/utils/link-element.d.ts +7 -0
- package/lib/utils/mergeDeep.d.ts +2 -0
- package/lib/utils/modal.d.ts +12 -0
- package/lib/utils/object.d.ts +2 -0
- package/lib/utils/offset.d.ts +4 -0
- package/lib/utils/scroll.d.ts +13 -0
- package/{utils → lib/utils}/sgds-element.d.ts +0 -0
- package/lib/utils/slot.d.ts +22 -0
- package/lib/utils/tabbable.d.ts +8 -0
- package/lib/utils/watch.d.ts +14 -0
- package/mocks/dropdown.d.ts +4 -0
- package/mocks/dropdown.ts +27 -0
- package/mocks/link.d.ts +3 -0
- package/mocks/link.ts +6 -0
- package/package.json +65 -10
- package/rollup.config.js +73 -0
- package/rollup.test.config.js +42 -0
- package/scripts/buildUtils.js +30 -0
- package/scripts/frankBuild.js +49 -0
- package/src/Button/index.ts +1 -0
- package/src/Button/sgds-button.scss +28 -0
- package/src/Button/sgds-button.ts +153 -0
- package/src/Card/index.ts +1 -0
- package/src/Card/sgds-action-card.scss +27 -0
- package/src/Card/sgds-action-card.ts +115 -0
- package/src/Checkbox/index.ts +1 -0
- package/src/Checkbox/sgds-checkbox.scss +4 -0
- package/src/Checkbox/sgds-checkbox.ts +149 -0
- package/src/Dropdown/index.ts +3 -0
- package/src/Dropdown/sgds-dropdown-item.ts +39 -0
- package/src/Dropdown/sgds-dropdown.scss +5 -0
- package/src/Dropdown/sgds-dropdown.ts +54 -0
- package/src/Footer/index.ts +3 -0
- package/src/Footer/sgds-footer.scss +5 -0
- package/src/Footer/sgds-footer.ts +121 -0
- package/src/Input/index.ts +1 -0
- package/src/Input/sgds-input.scss +20 -0
- package/src/Input/sgds-input.ts +178 -0
- package/src/Mainnav/index.ts +4 -0
- package/src/Mainnav/sgds-mainnav-dropdown.scss +13 -0
- package/src/Mainnav/sgds-mainnav-dropdown.ts +45 -0
- package/src/Mainnav/sgds-mainnav-item.scss +24 -0
- package/src/Mainnav/sgds-mainnav-item.ts +8 -0
- package/src/Mainnav/sgds-mainnav.scss +39 -0
- package/src/Mainnav/sgds-mainnav.ts +183 -0
- package/src/Masthead/index.ts +1 -0
- package/src/Masthead/sgds-masthead.scss +217 -0
- package/src/Masthead/sgds-masthead.ts +189 -0
- package/src/Modal/index.ts +1 -0
- package/src/Modal/sgds-modal.scss +128 -0
- package/src/Modal/sgds-modal.ts +309 -0
- package/src/QuantityToggle/index.ts +1 -0
- package/src/QuantityToggle/sgds-quantitytoggle.scss +10 -0
- package/src/QuantityToggle/sgds-quantitytoggle.ts +130 -0
- package/src/Radio/index.ts +2 -0
- package/src/Radio/sgds-radio.scss +5 -0
- package/src/Radio/sgds-radio.ts +120 -0
- package/src/Radio/sgds-radiogroup.scss +22 -0
- package/src/Radio/sgds-radiogroup.ts +221 -0
- package/src/Sidenav/index.ts +4 -0
- package/src/Sidenav/sgds-sidenav-item.scss +73 -0
- package/src/Sidenav/sgds-sidenav-item.ts +145 -0
- package/src/Sidenav/sgds-sidenav-link.scss +25 -0
- package/src/Sidenav/sgds-sidenav-link.ts +8 -0
- package/src/Sidenav/sgds-sidenav.scss +6 -0
- package/src/Sidenav/sgds-sidenav.ts +33 -0
- package/src/Tab/index.ts +3 -0
- package/src/Tab/sgds-tab.scss +84 -0
- package/src/Tab/sgds-tab.ts +87 -0
- package/src/Tab/sgds-tabgroup.scss +198 -0
- package/src/Tab/sgds-tabgroup.ts +295 -0
- package/src/Tab/sgds-tabpanel.scss +12 -0
- package/src/Tab/sgds-tabpanel.ts +55 -0
- package/src/Textarea/index.ts +1 -0
- package/src/Textarea/sgds-textarea.scss +23 -0
- package/src/Textarea/sgds-textarea.ts +201 -0
- package/src/index.ts +16 -0
- package/src/utils/animate.ts +69 -0
- package/src/utils/animation-registry.ts +71 -0
- package/src/utils/base.scss +14 -0
- package/src/utils/breakpoints.ts +5 -0
- package/src/utils/card-element.ts +42 -0
- package/src/utils/components.style.scss +531 -0
- package/src/utils/defaultvalue.ts +51 -0
- package/src/utils/dropdown-element.ts +244 -0
- package/src/utils/event.ts +13 -0
- package/src/utils/form.ts +183 -0
- package/src/utils/generateId.ts +4 -0
- package/src/utils/link-element.ts +34 -0
- package/src/utils/mergeDeep.ts +22 -0
- package/src/utils/modal.ts +64 -0
- package/src/utils/object.ts +2 -0
- package/src/utils/offset.ts +6 -0
- package/src/utils/scroll.ts +57 -0
- package/src/utils/sgds-element.ts +18 -0
- package/src/utils/slot.ts +102 -0
- package/src/utils/tabbable.ts +81 -0
- package/src/utils/watch.ts +62 -0
- package/stories/ActionCard.stories.mdx +199 -0
- package/stories/Button.stories.mdx +194 -0
- package/stories/Checkbox.stories.mdx +196 -0
- package/stories/Dropdown.stories.mdx +152 -0
- package/stories/Footer.stories.mdx +261 -0
- package/stories/Input.stories.mdx +236 -0
- package/stories/MainNav.stories.mdx +169 -0
- package/stories/Masthead.stories.mdx +112 -0
- package/stories/Modal.stories.mdx +103 -0
- package/stories/QuantityToggle.stories.mdx +97 -0
- package/stories/Radio.stories.mdx +262 -0
- package/stories/Sample.stories.js +29 -0
- package/stories/Sample.stories.mdx +33 -0
- package/stories/SideNav.stories.mdx +245 -0
- package/stories/common.js +185 -0
- package/stories/textarea.stories.mdx +253 -0
- package/test/button.element.test.ts +185 -0
- package/test/checkbox.test.ts +240 -0
- package/test/dropdown.test.ts +637 -0
- package/test/footer.test.ts +181 -0
- package/test/generateId.test.ts +18 -0
- package/test/input.element.test.ts +316 -0
- package/test/link-element.test.ts +38 -0
- package/test/mainnav.test.ts +313 -0
- package/test/masthead.test.ts +116 -0
- package/test/modal.test.ts +149 -0
- package/test/quantitytoggle.test.ts +76 -0
- package/test/radio.test.ts +310 -0
- package/test/selectable-card.test.ts +159 -0
- package/test/sidenav.test.ts +390 -0
- package/test/tab.test.ts +76 -0
- package/test/textarea.test.ts +126 -0
- package/tsconfig.json +26 -0
- package/tsconfig.test.json +24 -0
- package/typings/scss.d.ts +5 -0
- package/web-dev-server.config.mjs +7 -0
- package/web-test-runner.config.mjs +47 -0
- package/Button/index.js.map +0 -1
- package/Button/sgds-button.d.ts +0 -23
- package/Footer/index.js.map +0 -1
- package/Mainnav/index.js.map +0 -1
- package/Mainnav/sgds-mainnav-item.d.ts +0 -7
- package/Masthead/index.js.map +0 -1
- package/Sidenav/index.js.map +0 -1
- package/Sidenav/sgds-sidenav-link.d.ts +0 -7
- package/index.d.ts +0 -5
- package/index.js.map +0 -1
- package/umd/index.js +0 -52092
- package/umd/index.js.map +0 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
aTimeout,
|
|
3
|
+
expect,
|
|
4
|
+
fixture,
|
|
5
|
+
html,
|
|
6
|
+
oneEvent,
|
|
7
|
+
assert,
|
|
8
|
+
waitUntil,
|
|
9
|
+
elementUpdated,
|
|
10
|
+
} from "@open-wc/testing";
|
|
11
|
+
import sinon from "sinon";
|
|
12
|
+
import "../src/Checkbox";
|
|
13
|
+
import { SgdsCheckbox } from "../src/Checkbox";
|
|
14
|
+
import { SgdsButton } from "../src/Button";
|
|
15
|
+
import { sendKeys } from "@web/test-runner-commands";
|
|
16
|
+
|
|
17
|
+
describe("<sgds-checkbox>", () => {
|
|
18
|
+
it("is defined", () => {
|
|
19
|
+
const el = document.createElement("sgds-checkbox");
|
|
20
|
+
assert.instanceOf(el, SgdsCheckbox);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should be disabled with the disabled attribute & aria-disabled to be true", async () => {
|
|
24
|
+
const el = await fixture(html`<sgds-checkbox disabled></sgds-checkbox>`);
|
|
25
|
+
const checkbox = el.shadowRoot?.querySelector("input");
|
|
26
|
+
expect(checkbox?.disabled).to.be.true;
|
|
27
|
+
expect(checkbox).to.have.attribute("aria-disabled", "true");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should be able to pass in checkboxId to attributes(id/for pair)", async () => {
|
|
31
|
+
const el = await fixture(
|
|
32
|
+
html`<sgds-checkbox checkboxId="checkbox-123"></sgds-checkbox>`
|
|
33
|
+
);
|
|
34
|
+
const input = el.shadowRoot?.querySelector("input");
|
|
35
|
+
expect(input).to.have.attribute("id", "checkbox-123");
|
|
36
|
+
const label = el.shadowRoot?.querySelector("label");
|
|
37
|
+
expect(label).to.have.attribute("for", "checkbox-123");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should be able to pass in aria-label attribute", async () => {
|
|
41
|
+
const el = await fixture(
|
|
42
|
+
html`<sgds-checkbox ariaLabel="label"></sgds-checkbox>`
|
|
43
|
+
);
|
|
44
|
+
const checkbox = el.shadowRoot?.querySelector("label");
|
|
45
|
+
expect(checkbox).to.have.attribute("aria-label", "label");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should have class .is-invalid with invalid state", async () => {
|
|
49
|
+
const el = await fixture(html`<sgds-checkbox invalid></sgds-checkbox>`);
|
|
50
|
+
const checkbox = el.shadowRoot?.querySelector("input");
|
|
51
|
+
expect(checkbox?.classList.value).to.contain("is-invalid");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should render aria-invalid to true with invalid state and required attribute", async () => {
|
|
55
|
+
const el = await fixture(
|
|
56
|
+
html`<sgds-checkbox invalid required></sgds-checkbox>`
|
|
57
|
+
);
|
|
58
|
+
const checkbox = el.shadowRoot?.querySelector("input");
|
|
59
|
+
expect(checkbox).to.have.attribute("aria-invalid", "true");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("if class input is .is-invalid, feedback el should contain .invalid-feedback", async () => {
|
|
63
|
+
const el = await fixture(
|
|
64
|
+
html`<sgds-checkbox invalid required
|
|
65
|
+
><span slot="feedback">Hello world</span></sgds-checkbox
|
|
66
|
+
>`
|
|
67
|
+
);
|
|
68
|
+
const checkbox = el.shadowRoot?.querySelector("slot[name='feedback']");
|
|
69
|
+
expect(checkbox?.classList.value).to.contain("invalid-feedback");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("if class input is not .is-invalid, feedback el should be undefined", async () => {
|
|
73
|
+
const el = await fixture(
|
|
74
|
+
html`<sgds-checkbox
|
|
75
|
+
><div slot="feedback">Hello world</div></sgds-checkbox
|
|
76
|
+
>`
|
|
77
|
+
);
|
|
78
|
+
const checkbox = el.shadowRoot?.querySelector("slot[name='feedback']");
|
|
79
|
+
expect(checkbox).to.not.exist;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("should emit sgds-change event when input is clicked", async () => {
|
|
83
|
+
const el = await fixture(html`<sgds-checkbox></sgds-checkbox>`);
|
|
84
|
+
const toggleHandler = sinon.spy();
|
|
85
|
+
el.addEventListener("sgds-change", toggleHandler);
|
|
86
|
+
el.shadowRoot?.querySelector("input")?.click();
|
|
87
|
+
expect(toggleHandler).to.have.been.calledOnce;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should emit sgds-change event when label is clicked", async () => {
|
|
91
|
+
const el = await fixture(html`<sgds-checkbox></sgds-checkbox>`);
|
|
92
|
+
const toggleHandler = sinon.spy();
|
|
93
|
+
el.addEventListener("sgds-change", toggleHandler);
|
|
94
|
+
el.shadowRoot?.querySelector("label")?.click();
|
|
95
|
+
expect(toggleHandler).to.have.been.calledOnce;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should have input aria-checked false by default", async () => {
|
|
99
|
+
const el = await fixture<SgdsCheckbox>(
|
|
100
|
+
html`<sgds-checkbox></sgds-checkbox>`
|
|
101
|
+
);
|
|
102
|
+
const checkbox = el.shadowRoot!.querySelector("input");
|
|
103
|
+
|
|
104
|
+
expect(checkbox!).to.have.attribute("aria-checked", "false");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should show aria-checked to be true when checked is true", async () => {
|
|
108
|
+
const el = await fixture<SgdsCheckbox>(
|
|
109
|
+
html`<sgds-checkbox></sgds-checkbox>`
|
|
110
|
+
);
|
|
111
|
+
const checkbox = el.shadowRoot!.querySelector("input")!;
|
|
112
|
+
const clickSpy = sinon.spy();
|
|
113
|
+
|
|
114
|
+
checkbox.addEventListener("click", clickSpy, { once: true });
|
|
115
|
+
|
|
116
|
+
el.click();
|
|
117
|
+
await el.updateComplete;
|
|
118
|
+
|
|
119
|
+
expect(clickSpy.called).to.equal(true);
|
|
120
|
+
expect(el.checked).to.equal(true);
|
|
121
|
+
expect(checkbox).to.have.attribute("aria-checked", "true");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should be invalid when the input is empty and form.reportValidity() is called", async () => {
|
|
125
|
+
const form = await fixture<HTMLFormElement>(html`
|
|
126
|
+
<form>
|
|
127
|
+
<sgds-checkbox required value=""></sgds-checkbox>
|
|
128
|
+
</form>
|
|
129
|
+
`);
|
|
130
|
+
|
|
131
|
+
expect(form.reportValidity()).to.be.false;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should bypass validity when the input is not checked, reportValidity() is called, and the form has novalidate", async () => {
|
|
135
|
+
const form = await fixture<HTMLFormElement>(html`
|
|
136
|
+
<form novalidate>
|
|
137
|
+
<sgds-checkbox required value="hello"></sgds-checkbox>
|
|
138
|
+
</form>
|
|
139
|
+
`);
|
|
140
|
+
|
|
141
|
+
expect(form.reportValidity()).to.be.true;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should not show checked by default", async () => {
|
|
145
|
+
const el = await fixture<SgdsCheckbox>(
|
|
146
|
+
html`<sgds-checkbox></sgds-checkbox>`
|
|
147
|
+
);
|
|
148
|
+
expect(el.checked).to.be.false;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should show checked to be true when click", async () => {
|
|
152
|
+
const el = await fixture<SgdsCheckbox>(
|
|
153
|
+
html`<sgds-checkbox></sgds-checkbox>`
|
|
154
|
+
);
|
|
155
|
+
const checkbox = el.shadowRoot!.querySelector("input")!;
|
|
156
|
+
const clickSpy = sinon.spy();
|
|
157
|
+
|
|
158
|
+
checkbox.addEventListener("click", clickSpy, { once: true });
|
|
159
|
+
|
|
160
|
+
el.click();
|
|
161
|
+
await el.updateComplete;
|
|
162
|
+
|
|
163
|
+
expect(clickSpy.called).to.equal(true);
|
|
164
|
+
expect(el.checked).to.equal(true);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("When required attr is passed in, it should not show invalid on first load", async () => {
|
|
168
|
+
const el = await fixture<SgdsCheckbox>(
|
|
169
|
+
html` <sgds-checkbox required></sgds-checkbox> `
|
|
170
|
+
);
|
|
171
|
+
expect(el.invalid).to.be.false;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("When required attr is passed in, it should show invalid on submit", async () => {
|
|
175
|
+
const el = await fixture<SgdsCheckbox>(
|
|
176
|
+
html` <sgds-checkbox required></sgds-checkbox> `
|
|
177
|
+
);
|
|
178
|
+
expect(el.invalid).to.be.false;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("when required attr is passed in, should show invalid state upon submission", async () => {
|
|
182
|
+
const form = await fixture<HTMLFormElement>(
|
|
183
|
+
html`
|
|
184
|
+
<form>
|
|
185
|
+
<sgds-checkbox required></sgds-checkbox
|
|
186
|
+
><sgds-button type="submit"></sgds-button>
|
|
187
|
+
</form>
|
|
188
|
+
`
|
|
189
|
+
);
|
|
190
|
+
const button = form.querySelector<SgdsButton>("sgds-button")!;
|
|
191
|
+
const checkbox = form.querySelector<SgdsCheckbox>("sgds-checkbox")!;
|
|
192
|
+
|
|
193
|
+
const clickSpy = sinon.spy();
|
|
194
|
+
|
|
195
|
+
button.addEventListener("click", clickSpy, { once: true });
|
|
196
|
+
await elementUpdated(checkbox);
|
|
197
|
+
expect(checkbox.invalid).to.exist;
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("By default, should be able to check and uncheck using enter key", async () => {
|
|
201
|
+
const el = await fixture<SgdsCheckbox>(
|
|
202
|
+
html`<sgds-checkbox></sgds-checkbox>`
|
|
203
|
+
);
|
|
204
|
+
el.shadowRoot?.querySelector("input")?.focus();
|
|
205
|
+
await sendKeys({ press: "Enter" });
|
|
206
|
+
await el.updateComplete;
|
|
207
|
+
expect(el.checked).to.be.true;
|
|
208
|
+
|
|
209
|
+
await sendKeys({ press: "Enter" });
|
|
210
|
+
await el.updateComplete;
|
|
211
|
+
expect(el.checked).to.be.false;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("when required attr is passed in, should show valid state on first check and invalid state on unchecked by clicking", async () => {
|
|
215
|
+
const el = await fixture<SgdsCheckbox>(
|
|
216
|
+
html`<sgds-checkbox required></sgds-checkbox>`
|
|
217
|
+
);
|
|
218
|
+
el.shadowRoot?.querySelector("input")?.focus();
|
|
219
|
+
el.shadowRoot?.querySelector("input")?.click();
|
|
220
|
+
await elementUpdated(el);
|
|
221
|
+
expect(el.valid).to.be.true;
|
|
222
|
+
el.shadowRoot?.querySelector("input")?.click();
|
|
223
|
+
await elementUpdated(el);
|
|
224
|
+
expect(el.invalid).to.be.true;
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("when required attr is passed in, should show valid state on first check and invalid state on unchecked using enter key", async () => {
|
|
228
|
+
const el = await fixture<SgdsCheckbox>(
|
|
229
|
+
html`<sgds-checkbox required></sgds-checkbox>`
|
|
230
|
+
);
|
|
231
|
+
el.shadowRoot?.querySelector("input")?.focus();
|
|
232
|
+
await sendKeys({ press: "Enter" });
|
|
233
|
+
await el.updateComplete;
|
|
234
|
+
expect(el.valid).to.be.true;
|
|
235
|
+
|
|
236
|
+
await sendKeys({ press: "Enter" });
|
|
237
|
+
await el.updateComplete;
|
|
238
|
+
expect(el.invalid).to.be.true;
|
|
239
|
+
});
|
|
240
|
+
});
|