@govtechsg/sgds-web-component 0.0.10 → 0.0.11

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 (251) hide show
  1. package/package.json +7 -64
  2. package/.github/workflows/publish-latest.yml +0 -22
  3. package/.github/workflows/publish-pr.yml +0 -28
  4. package/.husky/commit-msg +0 -4
  5. package/.husky/prepare-commit-msg +0 -8
  6. package/.storybook/main.js +0 -16
  7. package/.storybook/preview-head.html +0 -11
  8. package/.storybook/preview.js +0 -9
  9. package/.vscode/settings.json +0 -7
  10. package/CONTRIBUTING.md +0 -56
  11. package/LICENSE +0 -20
  12. package/amplify.yml +0 -22
  13. package/commitlint.config.js +0 -1
  14. package/coverage/lcov-report/base.css +0 -224
  15. package/coverage/lcov-report/block-navigation.js +0 -87
  16. package/coverage/lcov-report/button-element.scss.html +0 -112
  17. package/coverage/lcov-report/button-element.ts.html +0 -145
  18. package/coverage/lcov-report/favicon.png +0 -0
  19. package/coverage/lcov-report/index.html +0 -116
  20. package/coverage/lcov-report/prettify.css +0 -1
  21. package/coverage/lcov-report/prettify.js +0 -2
  22. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  23. package/coverage/lcov-report/sorter.js +0 -196
  24. package/coverage/lcov.info +0 -32
  25. package/index.html +0 -430
  26. package/mocks/dropdown.d.ts +0 -4
  27. package/mocks/dropdown.ts +0 -27
  28. package/mocks/link.d.ts +0 -3
  29. package/mocks/link.ts +0 -6
  30. package/rollup.config.js +0 -73
  31. package/rollup.test.config.js +0 -42
  32. package/scripts/buildUtils.js +0 -30
  33. package/scripts/frankBuild.js +0 -49
  34. package/src/Button/index.ts +0 -1
  35. package/src/Button/sgds-button.scss +0 -28
  36. package/src/Button/sgds-button.ts +0 -153
  37. package/src/Card/index.ts +0 -1
  38. package/src/Card/sgds-action-card.scss +0 -27
  39. package/src/Card/sgds-action-card.ts +0 -115
  40. package/src/Checkbox/index.ts +0 -1
  41. package/src/Checkbox/sgds-checkbox.scss +0 -4
  42. package/src/Checkbox/sgds-checkbox.ts +0 -149
  43. package/src/Dropdown/index.ts +0 -3
  44. package/src/Dropdown/sgds-dropdown-item.ts +0 -39
  45. package/src/Dropdown/sgds-dropdown.scss +0 -5
  46. package/src/Dropdown/sgds-dropdown.ts +0 -54
  47. package/src/Footer/index.ts +0 -3
  48. package/src/Footer/sgds-footer.scss +0 -5
  49. package/src/Footer/sgds-footer.ts +0 -121
  50. package/src/Input/index.ts +0 -1
  51. package/src/Input/sgds-input.scss +0 -20
  52. package/src/Input/sgds-input.ts +0 -178
  53. package/src/Mainnav/index.ts +0 -4
  54. package/src/Mainnav/sgds-mainnav-dropdown.scss +0 -13
  55. package/src/Mainnav/sgds-mainnav-dropdown.ts +0 -45
  56. package/src/Mainnav/sgds-mainnav-item.scss +0 -24
  57. package/src/Mainnav/sgds-mainnav-item.ts +0 -8
  58. package/src/Mainnav/sgds-mainnav.scss +0 -39
  59. package/src/Mainnav/sgds-mainnav.ts +0 -183
  60. package/src/Masthead/index.ts +0 -1
  61. package/src/Masthead/sgds-masthead.scss +0 -217
  62. package/src/Masthead/sgds-masthead.ts +0 -189
  63. package/src/Modal/index.ts +0 -1
  64. package/src/Modal/sgds-modal.scss +0 -128
  65. package/src/Modal/sgds-modal.ts +0 -309
  66. package/src/QuantityToggle/index.ts +0 -1
  67. package/src/QuantityToggle/sgds-quantitytoggle.scss +0 -10
  68. package/src/QuantityToggle/sgds-quantitytoggle.ts +0 -130
  69. package/src/Radio/index.ts +0 -2
  70. package/src/Radio/sgds-radio.scss +0 -5
  71. package/src/Radio/sgds-radio.ts +0 -120
  72. package/src/Radio/sgds-radiogroup.scss +0 -22
  73. package/src/Radio/sgds-radiogroup.ts +0 -221
  74. package/src/Sidenav/index.ts +0 -4
  75. package/src/Sidenav/sgds-sidenav-item.scss +0 -73
  76. package/src/Sidenav/sgds-sidenav-item.ts +0 -145
  77. package/src/Sidenav/sgds-sidenav-link.scss +0 -25
  78. package/src/Sidenav/sgds-sidenav-link.ts +0 -8
  79. package/src/Sidenav/sgds-sidenav.scss +0 -6
  80. package/src/Sidenav/sgds-sidenav.ts +0 -33
  81. package/src/Tab/index.ts +0 -3
  82. package/src/Tab/sgds-tab.scss +0 -84
  83. package/src/Tab/sgds-tab.ts +0 -87
  84. package/src/Tab/sgds-tabgroup.scss +0 -198
  85. package/src/Tab/sgds-tabgroup.ts +0 -295
  86. package/src/Tab/sgds-tabpanel.scss +0 -12
  87. package/src/Tab/sgds-tabpanel.ts +0 -55
  88. package/src/Textarea/index.ts +0 -1
  89. package/src/Textarea/sgds-textarea.scss +0 -23
  90. package/src/Textarea/sgds-textarea.ts +0 -201
  91. package/src/index.ts +0 -16
  92. package/src/utils/animate.ts +0 -69
  93. package/src/utils/animation-registry.ts +0 -71
  94. package/src/utils/base.scss +0 -14
  95. package/src/utils/breakpoints.ts +0 -5
  96. package/src/utils/card-element.ts +0 -42
  97. package/src/utils/components.style.scss +0 -531
  98. package/src/utils/defaultvalue.ts +0 -51
  99. package/src/utils/dropdown-element.ts +0 -244
  100. package/src/utils/event.ts +0 -13
  101. package/src/utils/form.ts +0 -183
  102. package/src/utils/generateId.ts +0 -4
  103. package/src/utils/link-element.ts +0 -34
  104. package/src/utils/mergeDeep.ts +0 -22
  105. package/src/utils/modal.ts +0 -64
  106. package/src/utils/object.ts +0 -2
  107. package/src/utils/offset.ts +0 -6
  108. package/src/utils/scroll.ts +0 -57
  109. package/src/utils/sgds-element.ts +0 -18
  110. package/src/utils/slot.ts +0 -102
  111. package/src/utils/tabbable.ts +0 -81
  112. package/src/utils/watch.ts +0 -62
  113. package/stories/ActionCard.stories.mdx +0 -199
  114. package/stories/Button.stories.mdx +0 -194
  115. package/stories/Checkbox.stories.mdx +0 -196
  116. package/stories/Dropdown.stories.mdx +0 -152
  117. package/stories/Footer.stories.mdx +0 -261
  118. package/stories/Input.stories.mdx +0 -236
  119. package/stories/MainNav.stories.mdx +0 -169
  120. package/stories/Masthead.stories.mdx +0 -112
  121. package/stories/Modal.stories.mdx +0 -103
  122. package/stories/QuantityToggle.stories.mdx +0 -97
  123. package/stories/Radio.stories.mdx +0 -262
  124. package/stories/Sample.stories.js +0 -29
  125. package/stories/Sample.stories.mdx +0 -33
  126. package/stories/SideNav.stories.mdx +0 -245
  127. package/stories/common.js +0 -185
  128. package/stories/textarea.stories.mdx +0 -253
  129. package/test/button.element.test.ts +0 -185
  130. package/test/checkbox.test.ts +0 -240
  131. package/test/dropdown.test.ts +0 -637
  132. package/test/footer.test.ts +0 -181
  133. package/test/generateId.test.ts +0 -18
  134. package/test/input.element.test.ts +0 -316
  135. package/test/link-element.test.ts +0 -38
  136. package/test/mainnav.test.ts +0 -313
  137. package/test/masthead.test.ts +0 -116
  138. package/test/modal.test.ts +0 -149
  139. package/test/quantitytoggle.test.ts +0 -76
  140. package/test/radio.test.ts +0 -310
  141. package/test/selectable-card.test.ts +0 -159
  142. package/test/sidenav.test.ts +0 -390
  143. package/test/tab.test.ts +0 -76
  144. package/test/textarea.test.ts +0 -126
  145. package/tsconfig.json +0 -26
  146. package/tsconfig.test.json +0 -24
  147. package/typings/scss.d.ts +0 -5
  148. package/web-dev-server.config.mjs +0 -7
  149. package/web-test-runner.config.mjs +0 -47
  150. /package/{lib/Button → Button}/index.d.ts +0 -0
  151. /package/{lib/Button → Button}/index.js +0 -0
  152. /package/{lib/Button → Button}/index.js.map +0 -0
  153. /package/{lib/Button → Button}/package.json +0 -0
  154. /package/{lib/Button → Button}/sgds-button.d.ts +0 -0
  155. /package/{lib/Card → Card}/index.d.ts +0 -0
  156. /package/{lib/Card → Card}/index.js +0 -0
  157. /package/{lib/Card → Card}/index.js.map +0 -0
  158. /package/{lib/Card → Card}/package.json +0 -0
  159. /package/{lib/Card → Card}/sgds-action-card.d.ts +0 -0
  160. /package/{lib/Checkbox → Checkbox}/index.d.ts +0 -0
  161. /package/{lib/Checkbox → Checkbox}/index.js +0 -0
  162. /package/{lib/Checkbox → Checkbox}/index.js.map +0 -0
  163. /package/{lib/Checkbox → Checkbox}/package.json +0 -0
  164. /package/{lib/Checkbox → Checkbox}/sgds-checkbox.d.ts +0 -0
  165. /package/{lib/Dropdown → Dropdown}/index.d.ts +0 -0
  166. /package/{lib/Dropdown → Dropdown}/index.js +0 -0
  167. /package/{lib/Dropdown → Dropdown}/index.js.map +0 -0
  168. /package/{lib/Dropdown → Dropdown}/package.json +0 -0
  169. /package/{lib/Dropdown → Dropdown}/sgds-dropdown-item.d.ts +0 -0
  170. /package/{lib/Dropdown → Dropdown}/sgds-dropdown.d.ts +0 -0
  171. /package/{lib/Footer → Footer}/index.d.ts +0 -0
  172. /package/{lib/Footer → Footer}/index.js +0 -0
  173. /package/{lib/Footer → Footer}/index.js.map +0 -0
  174. /package/{lib/Footer → Footer}/package.json +0 -0
  175. /package/{lib/Footer → Footer}/sgds-footer.d.ts +0 -0
  176. /package/{lib/Input → Input}/index.d.ts +0 -0
  177. /package/{lib/Input → Input}/index.js +0 -0
  178. /package/{lib/Input → Input}/index.js.map +0 -0
  179. /package/{lib/Input → Input}/package.json +0 -0
  180. /package/{lib/Input → Input}/sgds-input.d.ts +0 -0
  181. /package/{lib/Mainnav → Mainnav}/index.d.ts +0 -0
  182. /package/{lib/Mainnav → Mainnav}/index.js +0 -0
  183. /package/{lib/Mainnav → Mainnav}/index.js.map +0 -0
  184. /package/{lib/Mainnav → Mainnav}/package.json +0 -0
  185. /package/{lib/Mainnav → Mainnav}/sgds-mainnav-dropdown.d.ts +0 -0
  186. /package/{lib/Mainnav → Mainnav}/sgds-mainnav-item.d.ts +0 -0
  187. /package/{lib/Mainnav → Mainnav}/sgds-mainnav.d.ts +0 -0
  188. /package/{lib/Masthead → Masthead}/index.d.ts +0 -0
  189. /package/{lib/Masthead → Masthead}/index.js +0 -0
  190. /package/{lib/Masthead → Masthead}/index.js.map +0 -0
  191. /package/{lib/Masthead → Masthead}/package.json +0 -0
  192. /package/{lib/Masthead → Masthead}/sgds-masthead.d.ts +0 -0
  193. /package/{lib/Modal → Modal}/index.d.ts +0 -0
  194. /package/{lib/Modal → Modal}/index.js +0 -0
  195. /package/{lib/Modal → Modal}/index.js.map +0 -0
  196. /package/{lib/Modal → Modal}/package.json +0 -0
  197. /package/{lib/Modal → Modal}/sgds-modal.d.ts +0 -0
  198. /package/{lib/QuantityToggle → QuantityToggle}/index.d.ts +0 -0
  199. /package/{lib/QuantityToggle → QuantityToggle}/index.js +0 -0
  200. /package/{lib/QuantityToggle → QuantityToggle}/index.js.map +0 -0
  201. /package/{lib/QuantityToggle → QuantityToggle}/package.json +0 -0
  202. /package/{lib/QuantityToggle → QuantityToggle}/sgds-quantitytoggle.d.ts +0 -0
  203. /package/{lib/Radio → Radio}/index.d.ts +0 -0
  204. /package/{lib/Radio → Radio}/index.js +0 -0
  205. /package/{lib/Radio → Radio}/index.js.map +0 -0
  206. /package/{lib/Radio → Radio}/package.json +0 -0
  207. /package/{lib/Radio → Radio}/sgds-radio.d.ts +0 -0
  208. /package/{lib/Radio → Radio}/sgds-radiogroup.d.ts +0 -0
  209. /package/{lib/Sidenav → Sidenav}/index.d.ts +0 -0
  210. /package/{lib/Sidenav → Sidenav}/index.js +0 -0
  211. /package/{lib/Sidenav → Sidenav}/index.js.map +0 -0
  212. /package/{lib/Sidenav → Sidenav}/package.json +0 -0
  213. /package/{lib/Sidenav → Sidenav}/sgds-sidenav-item.d.ts +0 -0
  214. /package/{lib/Sidenav → Sidenav}/sgds-sidenav-link.d.ts +0 -0
  215. /package/{lib/Sidenav → Sidenav}/sgds-sidenav.d.ts +0 -0
  216. /package/{lib/Tab → Tab}/index.d.ts +0 -0
  217. /package/{lib/Tab → Tab}/index.js +0 -0
  218. /package/{lib/Tab → Tab}/index.js.map +0 -0
  219. /package/{lib/Tab → Tab}/package.json +0 -0
  220. /package/{lib/Tab → Tab}/sgds-tab.d.ts +0 -0
  221. /package/{lib/Tab → Tab}/sgds-tabgroup.d.ts +0 -0
  222. /package/{lib/Tab → Tab}/sgds-tabpanel.d.ts +0 -0
  223. /package/{lib/Textarea → Textarea}/index.d.ts +0 -0
  224. /package/{lib/Textarea → Textarea}/index.js +0 -0
  225. /package/{lib/Textarea → Textarea}/index.js.map +0 -0
  226. /package/{lib/Textarea → Textarea}/package.json +0 -0
  227. /package/{lib/Textarea → Textarea}/sgds-textarea.d.ts +0 -0
  228. /package/{lib/index.d.ts → index.d.ts} +0 -0
  229. /package/{lib/index.js → index.js} +0 -0
  230. /package/{lib/index.js.map → index.js.map} +0 -0
  231. /package/{lib/umd → umd}/index.js +0 -0
  232. /package/{lib/umd → umd}/index.js.map +0 -0
  233. /package/{lib/utils → utils}/animate.d.ts +0 -0
  234. /package/{lib/utils → utils}/animation-registry.d.ts +0 -0
  235. /package/{lib/utils → utils}/breakpoints.d.ts +0 -0
  236. /package/{lib/utils → utils}/card-element.d.ts +0 -0
  237. /package/{lib/utils → utils}/defaultvalue.d.ts +0 -0
  238. /package/{lib/utils → utils}/dropdown-element.d.ts +0 -0
  239. /package/{lib/utils → utils}/event.d.ts +0 -0
  240. /package/{lib/utils → utils}/form.d.ts +0 -0
  241. /package/{lib/utils → utils}/generateId.d.ts +0 -0
  242. /package/{lib/utils → utils}/link-element.d.ts +0 -0
  243. /package/{lib/utils → utils}/mergeDeep.d.ts +0 -0
  244. /package/{lib/utils → utils}/modal.d.ts +0 -0
  245. /package/{lib/utils → utils}/object.d.ts +0 -0
  246. /package/{lib/utils → utils}/offset.d.ts +0 -0
  247. /package/{lib/utils → utils}/scroll.d.ts +0 -0
  248. /package/{lib/utils → utils}/sgds-element.d.ts +0 -0
  249. /package/{lib/utils → utils}/slot.d.ts +0 -0
  250. /package/{lib/utils → utils}/tabbable.d.ts +0 -0
  251. /package/{lib/utils → utils}/watch.d.ts +0 -0
@@ -1,181 +0,0 @@
1
- import { SgdsFooter, ColumnLinks } from "../src/Footer";
2
- import "../src/Footer/sgds-footer";
3
- import { fixture, assert, expect } from "@open-wc/testing";
4
- import { html } from "lit";
5
-
6
- describe("button-element", () => {
7
- it("is defined", () => {
8
- const el = document.createElement("sgds-footer");
9
- assert.instanceOf(el, SgdsFooter);
10
- });
11
- it("renders with default values", async () => {
12
- const el = await fixture(html`<sgds-footer></sgds-footer>`);
13
- assert.shadowDom.equal(
14
- el,
15
- `
16
- <footer class="sgds footer">
17
- <section class="footer-top" part="footer-top">
18
- <div class="container-fluid">
19
- <div class="row footer-header">
20
- <div class="col col-lg-6 col-md-12">
21
- <div class="title"></div>
22
- <div class="description"></div>
23
- </div>
24
- </div>
25
- <div class="row footer-items">
26
- </div>
27
- <div class="row footer-contact-links">
28
- <div class="col">
29
- <div class="d-flex justify-content-lg-end">
30
- <ul>
31
- <li><a href="#">Contact</a></li>
32
- <li><a href="#">Feedback</a></li>
33
- <li>
34
- <a
35
- href="https://www.reach.gov.sg/"
36
- target="_blank"
37
- rel="noopener noreferrer"
38
- >Reach.gov.sg</a
39
- >
40
- </li>
41
- </ul>
42
- </div>
43
- </div>
44
- </div>
45
- </div>
46
- </section>
47
- <section class="footer-bottom" part="footer-bottom">
48
- <div class="container-fluid">
49
- <div class="row footer-mandatory-links">
50
- <div class="col">
51
- <ul>
52
- <li>
53
- <a
54
- href="#"
55
- target="_blank"
56
- rel="noopener noreferrer"
57
- >Report Vulnerability</a
58
- >
59
- </li>
60
- <li><a href="#">Privacy Statement</a></li>
61
- <li><a href="#">Terms of use</a></li>
62
- </ul>
63
- </div>
64
- </div>
65
- <div class="row footer-copyrights">
66
- <div class="col">
67
- <div class="d-flex justify-content-lg-end text-end">
68
- © ${new Date().getFullYear()} Government of Singapore<br />
69
- Last Updated
70
- </div>
71
- </div>
72
- </div>
73
- </div>
74
- </section>
75
- </footer>
76
- `
77
- );
78
- });
79
-
80
- it("description prop forward to .description class", async () => {
81
- const el = await fixture(
82
- html`<sgds-footer description="test description"></sgds-footer>`
83
- );
84
- expect(el.shadowRoot?.querySelector(".description")?.textContent).to.equal(
85
- "test description"
86
- );
87
- });
88
-
89
- it("title prop forward to approriate .title class", async () => {
90
- const el = await fixture(
91
- html`<sgds-footer title="test title"></sgds-footer>`
92
- );
93
- expect(el.shadowRoot?.querySelector(".title")?.textContent).to.equal(
94
- "test title"
95
- );
96
- });
97
- it("lastUpdatedDate prop forward to approriate div el", async () => {
98
- const el = await fixture(
99
- html`<sgds-footer lastUpdatedDate="08 Feb 2022"></sgds-footer>`
100
- );
101
- expect(
102
- el.shadowRoot?.querySelector(".footer-copyrights>div.col>div")
103
- ?.textContent
104
- ).to.contain("08 Feb 2022");
105
- });
106
-
107
- it("contactHref prop forward to contact's href attr", async () => {
108
- const el = await fixture(
109
- html`<sgds-footer contactHref="test"></sgds-footer>`
110
- );
111
- expect(
112
- el.shadowRoot?.querySelector("a[href='test']")?.textContent
113
- ).to.contain("Contact");
114
- });
115
-
116
- it("feedbackHref prop forward to feedback's href attr", async () => {
117
- const el = await fixture(
118
- html`<sgds-footer feedbackHref="test"></sgds-footer>`
119
- );
120
- expect(
121
- el.shadowRoot?.querySelector("a[href='test']")?.textContent
122
- ).to.contain("Feedback");
123
- });
124
- it("vulnerabilityHref prop forward to Report Vulnerability's href attr", async () => {
125
- const el = await fixture(
126
- html`<sgds-footer vulnerabilityHref="test"></sgds-footer>`
127
- );
128
- expect(
129
- el.shadowRoot?.querySelector("a[href='test']")?.textContent
130
- ).to.contain("Report Vulnerability");
131
- });
132
- it("privacyHref prop forward to Privacy Statement's href attr", async () => {
133
- const el = await fixture(
134
- html`<sgds-footer privacyHref="test"></sgds-footer>`
135
- );
136
- expect(
137
- el.shadowRoot?.querySelector("a[href='test']")?.textContent
138
- ).to.contain("Privacy Statement");
139
- });
140
- it("termsOfUseHref prop forward to Terms of use's href attr", async () => {
141
- const el = await fixture(
142
- html`<sgds-footer termsOfUseHref="test"></sgds-footer>`
143
- );
144
- expect(
145
- el.shadowRoot?.querySelector("a[href='test']")?.textContent
146
- ).to.contain("Terms of use");
147
- });
148
-
149
-
150
- it("links prop accepts an array", async () => {
151
- const linkArray: ColumnLinks[] = [
152
- {
153
- title: "test-1",
154
- links: [
155
- { href: "test-href-1", label: "test-label-1" },
156
- { href: "test-href-2", label: "test-label-2" },
157
- ],
158
- },
159
- {
160
- title: "test-2",
161
- links: [
162
- { href: "test-href-1", label: "test-label-1" },
163
- { href: "test-href-2", label: "test-label-2" },
164
- ],
165
- },
166
- ];
167
- const el = await fixture(
168
- html`<sgds-footer .links=${linkArray}></sgds-footer>`
169
- );
170
-
171
- expect(el.shadowRoot?.querySelectorAll('.footer-items>div').length).to.equal(2)
172
- expect(el.shadowRoot?.querySelectorAll('.footer-items>div')[0].textContent).to.contain('test-1')
173
- expect(el.shadowRoot?.querySelectorAll('.footer-items>div')[1].textContent).to.contain('test-2')
174
- expect(el.shadowRoot?.querySelectorAll('ul.links>li>a').length).to.equal(4)
175
- expect(el.shadowRoot?.querySelectorAll('li>a[href="test-href-1"]').length).to.equal(2)
176
- expect(el.shadowRoot?.querySelectorAll('li>a[href="test-href-1"]')[0].textContent).to.equal('test-label-1')
177
- expect(el.shadowRoot?.querySelectorAll('li>a[href="test-href-2"]').length).to.equal(2)
178
- expect(el.shadowRoot?.querySelectorAll('li>a[href="test-href-2"]')[0].textContent).to.equal('test-label-2')
179
-
180
- });
181
- });
@@ -1,18 +0,0 @@
1
- import generateId from "../src/utils/generateId";
2
- import { expect } from "@open-wc/testing";
3
- import sinon from "sinon";
4
-
5
- describe("generateId function", () => {
6
- sinon.stub(Math, "random").returns(1234567);
7
-
8
- it("returns a string", () => {
9
- expect(typeof generateId()).to.equal("string");
10
- });
11
- it("returns an id with the correct structure", () => {
12
- expect(generateId()).to.equal("id-3456-sgds--");
13
- });
14
-
15
- it("when suffix specified , should return with suffix", () => {
16
- expect(generateId("test", 'test')).to.equal("id-3456-sgds-test-test");
17
- });
18
- });
@@ -1,316 +0,0 @@
1
- import { SgdsInput } from "../src/Input/sgds-input";
2
- import type SgdsButton from "../src/Button/sgds-button";
3
- import "../src/Input";
4
- import "../src/Button";
5
- import {
6
- expect,
7
- fixture,
8
- html,
9
- oneEvent,
10
- waitUntil,
11
- assert,
12
- elementUpdated,
13
- } from "@open-wc/testing";
14
- import sinon from "sinon";
15
- import { sendKeys } from "@web/test-runner-commands";
16
-
17
- describe("sgds-input", () => {
18
- it("is defined", () => {
19
- const el = document.createElement("sgds-input");
20
- assert.instanceOf(el, SgdsInput);
21
- });
22
- it("renders with default values", async () => {
23
- const el = await fixture(
24
- html`<sgds-input inputId="test-id" label="label"></sgds-input>`
25
- );
26
- assert.shadowDom.equal(
27
- el,
28
- `
29
- <label class="form-label" for="test-id">label</label>
30
- <input type="text" class="form-control " id="test-id" placeholder="Placeholder" aria-invalid="false">
31
- <div class="invalid-feedback" id="test-id-invalid">default feedback</div>
32
- `
33
- );
34
- });
35
-
36
- it("should be disabled with the disabled attribute", async () => {
37
- const el = await fixture<SgdsInput>(
38
- html` <sgds-input disabled></sgds-input> `
39
- );
40
- const input = el.shadowRoot!.querySelector<HTMLInputElement>("input")!;
41
-
42
- expect(input.disabled).to.be.true;
43
- });
44
-
45
- // Labels
46
- it("should replace label value the if updated", async () => {
47
- const el = await fixture(html`<sgds-input></sgds-input>`);
48
- el.setAttribute("label", "Enter your name");
49
- await elementUpdated(el);
50
- const labelText = el.shadowRoot?.querySelector(".form-label");
51
- expect(labelText?.textContent).to.contain("Enter your name");
52
- });
53
-
54
- // Hint Text
55
- it("should render hint text element if hintText attribute is defined", async () => {
56
- const el = await fixture(html`<sgds-input hintText="hint"></sgds-input>`);
57
- const hintText = el.shadowRoot?.querySelector(".form-text");
58
- el.setAttribute("hintText", "hint");
59
- await elementUpdated(el);
60
- expect(hintText?.textContent).to.equal("hint");
61
- expect(hintText).to.exist;
62
- });
63
-
64
- // Icon
65
- it("should render with fom-control-group if iconName attribute is defined", async () => {
66
- const el = await fixture(
67
- html`<sgds-input iconName="search" inputId="defaultID"></sgds-input>`
68
- );
69
- assert.shadowDom.equal(
70
- el,
71
- `
72
- <div class="sgds form-control-group">
73
- <span class="form-control-icon">
74
- <sl-icon name="search"></sl-icon>
75
- </span>
76
- <input type="text" class="form-control " id="defaultID" placeholder="Placeholder" aria-invalid="false">
77
- <div class="invalid-feedback" id="defaultID-invalid">default feedback</div>
78
- </div>
79
- `
80
- );
81
- });
82
-
83
- it("updates the iconName attribute value to 'stack'", async () => {
84
- const el = await fixture(html`<sgds-input iconName="search"></sgds-input>`);
85
- const iconElement = el.shadowRoot?.querySelector("sl-icon");
86
- iconElement?.setAttribute("name", "stack");
87
- await elementUpdated(el);
88
- expect(iconElement?.getAttribute("name")).to.equal("stack");
89
- });
90
-
91
- //Name
92
- it("updates the name attribute value to 'Hello'", async () => {
93
- const el = await fixture(html`<sgds-input></sgds-input>`);
94
- el?.setAttribute("name", "Hello");
95
- await elementUpdated(el);
96
- const name = el.shadowRoot?.querySelector(".form-control");
97
- expect(name?.getAttribute("name")).to.equal("Hello");
98
- });
99
-
100
- //Placeholder
101
- it("updates the default placeholder value to 'Hello'", async () => {
102
- const el = await fixture(html`<sgds-input></sgds-input>`);
103
- el?.setAttribute("placeholder", "Hello");
104
- await elementUpdated(el);
105
- const placeHolder = el.shadowRoot?.querySelector(".form-control");
106
- expect(placeHolder?.getAttribute("placeholder")).to.equal("Hello");
107
- });
108
-
109
- it("should focus the input when clicking on the label", async () => {
110
- const el = await fixture<SgdsInput>(
111
- html` <sgds-input label="Name"></sgds-input> `
112
- );
113
- const label = el.shadowRoot?.querySelector("label")!;
114
- const submitHandler = sinon.spy();
115
-
116
- el.addEventListener("sgds-focus", submitHandler);
117
- (label as HTMLElement).click();
118
- await waitUntil(() => submitHandler.calledOnce);
119
-
120
- expect(submitHandler).to.have.been.calledOnce;
121
- });
122
- });
123
- describe("when using constraint validation", () => {
124
- it("by default, invalid and valid should be false", async () => {
125
- const el = await fixture<SgdsInput>(html` <sgds-input></sgds-input> `);
126
- expect(el.invalid).to.be.false;
127
- expect(el.valid).to.be.false;
128
- expect(el.reportValidity()).to.be.true;
129
- });
130
- it("when required, validation occurs upon typing ", async () => {
131
- const el = await fixture<SgdsInput>(
132
- html` <sgds-input required></sgds-input> `
133
- );
134
- expect(el.invalid).to.be.false;
135
- expect(el.valid).to.be.false;
136
-
137
- el.focus()
138
- await sendKeys({ type: "s" });
139
- await el.updateComplete;
140
-
141
- expect(el.value).to.equal('s')
142
- expect(el.invalid).to.be.false;
143
- expect(el.valid).to.be.true;
144
- expect(el.reportValidity()).to.be.true;
145
-
146
- await sendKeys({press: 'Backspace'})
147
- await el.updateComplete;
148
- expect(el.value).to.equal('')
149
-
150
- expect(el.invalid).to.be.true;
151
- expect(el.valid).to.be.false;
152
- expect(el.reportValidity()).to.be.false;
153
- });
154
-
155
- it('should be invalid when the pattern does not match', async () => {
156
- const el = await fixture<SgdsInput>(html` <sgds-input pattern="failtest" value="fail"></sgds-input> `);
157
- expect(el.invalid).to.be.false;
158
- expect(el.valid).to.be.false;
159
- expect(el.reportValidity()).to.be.false;
160
-
161
- await sendKeys({type: 'tes'})
162
- await el.updateComplete
163
- expect(el.value).to.equal('failtes')
164
- expect(el.invalid).to.be.true;
165
- expect(el.valid).to.be.false;
166
- expect(el.reportValidity()).to.be.false;
167
-
168
- await sendKeys({type: 't'})
169
- await el.updateComplete
170
- expect(el.value).to.equal('failtest')
171
- expect(el.invalid).to.be.false;
172
- expect(el.valid).to.be.true;
173
- expect(el.reportValidity()).to.be.true;
174
-
175
- await sendKeys({press: 'Backspace'})
176
- await el.updateComplete
177
- expect(el.value).to.equal('failtes')
178
- expect(el.invalid).to.be.true;
179
- expect(el.valid).to.be.false;
180
- expect(el.reportValidity()).to.be.false;
181
-
182
- });
183
-
184
- it("should be invalid when required and disabled is removed", async () => {
185
- const el = await fixture<SgdsInput>(
186
- html` <sgds-input disabled required></sgds-input> `
187
- );
188
- el.disabled = false;
189
- await el.updateComplete;
190
- expect(el.invalid).to.be.true;
191
- });
192
- });
193
-
194
- describe("when calling HTMLFormElement.reportValidity()", () => {
195
- it("should be invalid when the input is empty and form.reportValidity() is called", async () => {
196
- const form = await fixture<HTMLFormElement>(html`
197
- <form>
198
- <sgds-input required value=""></sgds-input>
199
- </form>
200
- `);
201
-
202
- expect(form.reportValidity()).to.be.false;
203
- });
204
-
205
- it("should be valid when the input is empty, reportValidity() is called, and the form has novalidate", async () => {
206
- const form = await fixture<HTMLFormElement>(html`
207
- <form novalidate>
208
- <sgds-input required value=""></sgds-input>
209
- </form>
210
- `);
211
-
212
- expect(form.reportValidity()).to.be.true;
213
- });
214
-
215
- it("fires sgds-input event when value is entered", async () => {
216
- const el = await fixture<SgdsInput>(html` <sgds-input></sgds-input> `);
217
- const inputHandler = sinon.spy();
218
- el.focus();
219
- el.addEventListener("sgds-input", inputHandler);
220
- await sendKeys({ press: "A" });
221
- waitUntil(() => inputHandler.calledOnce);
222
- expect(inputHandler).to.have.been.calledOnce;
223
- });
224
- });
225
-
226
- describe("when submitting a form", () => {
227
- it("should submit the form when pressing enter in a form without a submit button", async () => {
228
- const form = await fixture<HTMLFormElement>(
229
- html` <form><sgds-input></sgds-input></form> `
230
- );
231
- const input = form.querySelector<SgdsInput>("sgds-input")!;
232
- const submitHandler = sinon.spy((event: SubmitEvent) =>
233
- event.preventDefault()
234
- );
235
-
236
- form.addEventListener("submit", submitHandler);
237
- input.focus();
238
- await sendKeys({ press: "Enter" });
239
- await waitUntil(() => submitHandler.calledOnce);
240
-
241
- expect(submitHandler).to.have.been.calledOnce;
242
- });
243
-
244
- it("should submit the form when pressing enter in a form with a submit button", async () => {
245
- const form = await fixture<HTMLFormElement>(html`
246
- <form>
247
- <sgds-input></sgds-input>
248
- <sgds-button type="submit"></sgds-button>
249
- </form>
250
- `);
251
- const input = form.querySelector<SgdsInput>("sgds-input")!;
252
- const submitButton = form.querySelector<SgdsButton>("sgds-button")!;
253
- const submitHandler = sinon.spy((event: SubmitEvent) =>
254
- event.preventDefault()
255
- );
256
-
257
- form.addEventListener("submit", submitHandler);
258
- submitButton.click();
259
- await waitUntil(() => submitHandler.calledOnce);
260
- expect(submitHandler).to.have.been.calledOnce;
261
- });
262
-
263
- it("should prevent submission when pressing enter in an input and canceling the keydown event", async () => {
264
- const form = await fixture<HTMLFormElement>(
265
- html` <form><sgds-input></sgds-input></form> `
266
- );
267
- const input = form.querySelector<SgdsInput>("sgds-input")!;
268
- const submitHandler = sinon.spy((event: SubmitEvent) =>
269
- event.preventDefault()
270
- );
271
- const keydownHandler = sinon.spy((event: KeyboardEvent) => {
272
- if (event.key === "Enter") {
273
- event.preventDefault();
274
- }
275
- });
276
-
277
- form.addEventListener("submit", submitHandler);
278
- input.addEventListener("keydown", keydownHandler);
279
- input.focus();
280
- await sendKeys({ press: "Enter" });
281
- await waitUntil(() => keydownHandler.calledOnce);
282
-
283
- expect(keydownHandler).to.have.been.calledOnce;
284
- expect(submitHandler).to.not.have.been.called;
285
- });
286
- });
287
-
288
- describe("when resetting a form", () => {
289
- it("should reset the element to its initial value", async () => {
290
- const form = await fixture<HTMLFormElement>(html`
291
- <form>
292
- <sgds-input name="a" value="test"></sgds-input>
293
- <sgds-button type="reset">Reset</sgds-button>
294
- </form>
295
- `);
296
- const button = form.querySelector<SgdsButton>("sgds-button")!;
297
- const input = form.querySelector<SgdsInput>("sgds-input")!;
298
- input.value = "1234";
299
-
300
- await input.updateComplete;
301
-
302
- setTimeout(() => button.click());
303
- await oneEvent(form, "reset");
304
- await input.updateComplete;
305
-
306
- expect(input.value).to.equal("test");
307
-
308
- input.defaultValue = "";
309
-
310
- setTimeout(() => button.click());
311
- await oneEvent(form, "reset");
312
- await input.updateComplete;
313
-
314
- expect(input.value).to.equal("");
315
- });
316
- });
@@ -1,38 +0,0 @@
1
- import "../mocks/link";
2
- import { MockLink } from "../mocks/link";
3
- import { fixture, assert, expect } from "@open-wc/testing";
4
- import { html } from "lit";
5
-
6
- describe("link-element", () => {
7
- it("renders with default values", async () => {
8
- const el = await fixture<MockLink>(html`<mock-link></mock-link>`);
9
- assert.shadowDom.equal(
10
- el,
11
- ` <li>
12
- <a
13
- aria-disabled="false"
14
- class="nav-link"
15
- href=""
16
- >
17
- <slot>
18
- </slot>
19
- </a>
20
- </li>
21
- `
22
- );
23
- });
24
- it("href prop is forwarded to a tag href attr", async () => {
25
- const el = await fixture(html`<mock-link href="#">test</mock-link>`);
26
- expect(el.shadowRoot?.querySelector("a")).to.have.attribute("href", "#");
27
- });
28
- it("active prop is forwarded to <a> class", async () => {
29
- const el = await fixture(html`<mock-link active>test</mock-link>`);
30
- expect(el.shadowRoot?.querySelector("a")).to.have.class("active");
31
- });
32
- it('disabled prop apply disable props and attr to anchor element', async() => {
33
- const el = await fixture(html`<mock-link disabled>test</mock-link>`);
34
- expect(el.shadowRoot?.querySelector("a")).to.have.class("disabled");
35
- expect(el.shadowRoot?.querySelector("a")).to.have.attribute("disabled");
36
- expect(el.shadowRoot?.querySelector("a")).to.have.attribute("aria-disabled", "true");
37
- })
38
- });