@api-client/ui 0.5.38 → 0.5.40

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 (299) hide show
  1. package/build/src/md/list/internals/ListItem.d.ts +24 -15
  2. package/build/src/md/list/internals/ListItem.d.ts.map +1 -1
  3. package/build/src/md/list/internals/ListItem.js +85 -59
  4. package/build/src/md/list/internals/ListItem.js.map +1 -1
  5. package/build/src/md/list/internals/ListItem.styles.js +11 -11
  6. package/build/src/md/list/internals/ListItem.styles.js.map +1 -1
  7. package/build/src/md/select/internals/Option.d.ts +4 -14
  8. package/build/src/md/select/internals/Option.d.ts.map +1 -1
  9. package/build/src/md/select/internals/Option.js +13 -28
  10. package/build/src/md/select/internals/Option.js.map +1 -1
  11. package/build/src/md/select/internals/Select.d.ts +1 -1
  12. package/build/src/md/select/internals/Select.d.ts.map +1 -1
  13. package/build/src/md/select/internals/Select.js +15 -5
  14. package/build/src/md/select/internals/Select.js.map +1 -1
  15. package/build/tsconfig.tsbuildinfo +1 -0
  16. package/package.json +1 -1
  17. package/src/md/list/internals/ListItem.styles.ts +11 -11
  18. package/src/md/list/internals/ListItem.ts +68 -43
  19. package/src/md/select/internals/Option.ts +14 -26
  20. package/src/md/select/internals/Select.ts +15 -5
  21. package/.aiexclude +0 -3
  22. package/.cursor/rules/html-and-css-best-practices.mdc +0 -63
  23. package/.cursor/rules/lit-best-practices.mdc +0 -89
  24. package/.editorconfig +0 -29
  25. package/.github/CONTRIBUTING.md +0 -24
  26. package/.github/instructions/html-and-css-best-practices.instructions.md +0 -70
  27. package/.github/instructions/lit-best-practices.instructions.md +0 -90
  28. package/.github/release.yml +0 -14
  29. package/.github/stale.yml +0 -23
  30. package/.github/workflows/auto-release.yml +0 -182
  31. package/.github/workflows/release.yml +0 -82
  32. package/.prettierrc.js +0 -14
  33. package/.vscode/settings.json +0 -18
  34. package/RELEASE.md +0 -163
  35. package/RELEASE_SETUP.md +0 -235
  36. package/build/src/demo/DemoPage.d.ts +0 -81
  37. package/build/src/demo/DemoPage.d.ts.map +0 -1
  38. package/build/src/demo/DemoPage.js +0 -175
  39. package/build/src/demo/DemoPage.js.map +0 -1
  40. package/build/src/demo/DemoStyles.d.ts +0 -3
  41. package/build/src/demo/DemoStyles.d.ts.map +0 -1
  42. package/build/src/demo/DemoStyles.js +0 -60
  43. package/build/src/demo/DemoStyles.js.map +0 -1
  44. package/build/test/elements/navigation/Navigation.test.d.ts +0 -3
  45. package/build/test/elements/navigation/Navigation.test.d.ts.map +0 -1
  46. package/build/test/elements/navigation/Navigation.test.js +0 -113
  47. package/build/test/elements/navigation/Navigation.test.js.map +0 -1
  48. package/commitlint.config.cjs +0 -2
  49. package/demo/elements/authorization/AuthPlugin.js +0 -57
  50. package/demo/elements/authorization/AuthProxy.js +0 -215
  51. package/demo/elements/authorization/api-key.html +0 -27
  52. package/demo/elements/authorization/api-key.ts +0 -44
  53. package/demo/elements/authorization/basic.html +0 -27
  54. package/demo/elements/authorization/basic.ts +0 -43
  55. package/demo/elements/authorization/bearer.html +0 -27
  56. package/demo/elements/authorization/bearer.ts +0 -43
  57. package/demo/elements/authorization/env.js +0 -8
  58. package/demo/elements/authorization/index.html +0 -44
  59. package/demo/elements/authorization/ntlm.html +0 -27
  60. package/demo/elements/authorization/ntlm.ts +0 -43
  61. package/demo/elements/authorization/oauth-authorize.html +0 -75
  62. package/demo/elements/authorization/oauth-authorize.ts +0 -40
  63. package/demo/elements/authorization/oauth-error.html +0 -18
  64. package/demo/elements/authorization/oauth-error.ts +0 -10
  65. package/demo/elements/authorization/oauth-popup.html +0 -36
  66. package/demo/elements/authorization/oauth2.html +0 -27
  67. package/demo/elements/authorization/oauth2.ts +0 -100
  68. package/demo/elements/authorization/oidc.html +0 -27
  69. package/demo/elements/authorization/oidc.ts +0 -139
  70. package/demo/elements/authorization/private.crt +0 -31
  71. package/demo/elements/authorization/private.csr +0 -28
  72. package/demo/elements/authorization/private.key +0 -51
  73. package/demo/elements/authorization/private.pem +0 -31
  74. package/demo/elements/authorization/redirect.html +0 -20
  75. package/demo/elements/authorization/ssl-commands.sh +0 -30
  76. package/demo/elements/authorization/ssl.conf +0 -24
  77. package/demo/elements/autocomplete/index.html +0 -64
  78. package/demo/elements/autocomplete/index.ts +0 -171
  79. package/demo/elements/code-editor/CodeEditorDemo.ts +0 -173
  80. package/demo/elements/code-editor/index.html +0 -19
  81. package/demo/elements/context-menu/DemoIcons.ts +0 -21
  82. package/demo/elements/context-menu/basic.html +0 -25
  83. package/demo/elements/context-menu/basic.ts +0 -119
  84. package/demo/elements/context-menu/custom-data.html +0 -25
  85. package/demo/elements/context-menu/custom-data.ts +0 -62
  86. package/demo/elements/context-menu/demo.css +0 -28
  87. package/demo/elements/context-menu/enabled-state.html +0 -25
  88. package/demo/elements/context-menu/enabled-state.ts +0 -73
  89. package/demo/elements/context-menu/icons.html +0 -25
  90. package/demo/elements/context-menu/icons.ts +0 -64
  91. package/demo/elements/context-menu/index.html +0 -43
  92. package/demo/elements/context-menu/nested.html +0 -25
  93. package/demo/elements/context-menu/nestedt.ts +0 -152
  94. package/demo/elements/context-menu/no-execute.html +0 -25
  95. package/demo/elements/context-menu/no-execute.ts +0 -134
  96. package/demo/elements/context-menu/radio-menu.html +0 -25
  97. package/demo/elements/context-menu/radio-menu.ts +0 -83
  98. package/demo/elements/context-menu/separators.html +0 -25
  99. package/demo/elements/context-menu/separators.ts +0 -172
  100. package/demo/elements/currency/index.html +0 -91
  101. package/demo/elements/currency/index.ts +0 -352
  102. package/demo/elements/environment/environment-editor.html +0 -20
  103. package/demo/elements/environment/environment-editor.ts +0 -49
  104. package/demo/elements/environment/index.html +0 -33
  105. package/demo/elements/environment/server-editor.html +0 -20
  106. package/demo/elements/environment/server-editor.ts +0 -67
  107. package/demo/elements/environment/variables-editor.html +0 -20
  108. package/demo/elements/environment/variables-editor.ts +0 -94
  109. package/demo/elements/har/har-viewer.html +0 -20
  110. package/demo/elements/har/har-viewer.ts +0 -76
  111. package/demo/elements/har/har1.har +0 -3044
  112. package/demo/elements/har/har2.json +0 -439
  113. package/demo/elements/har/index.html +0 -26
  114. package/demo/elements/highlight/example.md +0 -27
  115. package/demo/elements/highlight/index.html +0 -31
  116. package/demo/elements/highlight/marked-highlight.html +0 -132
  117. package/demo/elements/highlight/marked-highlight.ts +0 -22
  118. package/demo/elements/highlight/prism-highlight.html +0 -62
  119. package/demo/elements/highlight/prism-highlight.ts +0 -17
  120. package/demo/elements/http/body-editor.html +0 -17
  121. package/demo/elements/http/body-editor.ts +0 -115
  122. package/demo/elements/http/headers.html +0 -17
  123. package/demo/elements/http/headers.ts +0 -59
  124. package/demo/elements/http/http-assertions.html +0 -20
  125. package/demo/elements/http/http-assertions.ts +0 -89
  126. package/demo/elements/http/http-flows.html +0 -23
  127. package/demo/elements/http/http-flows.ts +0 -89
  128. package/demo/elements/http/index.html +0 -45
  129. package/demo/elements/http/request-editor.html +0 -26
  130. package/demo/elements/http/request-editor.ts +0 -197
  131. package/demo/elements/http/request-log.html +0 -16
  132. package/demo/elements/http/request-log.ts +0 -136
  133. package/demo/elements/http/url-editing.html +0 -17
  134. package/demo/elements/http/url-editing.ts +0 -112
  135. package/demo/elements/icons/index.html +0 -81
  136. package/demo/elements/icons/index.ts +0 -52
  137. package/demo/elements/index.html +0 -72
  138. package/demo/elements/mention-textarea/index.html +0 -19
  139. package/demo/elements/mention-textarea/index.ts +0 -205
  140. package/demo/elements/navigation/navigation-item.html +0 -49
  141. package/demo/elements/navigation/navigation-item.ts +0 -131
  142. package/demo/elements/navigation/navigation.html +0 -20
  143. package/demo/elements/navigation/navigation.ts +0 -45
  144. package/demo/elements/project/index.html +0 -29
  145. package/demo/elements/project/project-run-report.html +0 -20
  146. package/demo/elements/project/project-run-report.ts +0 -132
  147. package/demo/elements/project/request-editor.html +0 -23
  148. package/demo/elements/project/request-editor.ts +0 -232
  149. package/demo/elements/user/user-avatar.html +0 -17
  150. package/demo/elements/user/user-avatar.ts +0 -60
  151. package/demo/env.js +0 -4
  152. package/demo/index.html +0 -34
  153. package/demo/layout/index.html +0 -94
  154. package/demo/layout/index.ts +0 -190
  155. package/demo/md/DemoStyles.ts +0 -61
  156. package/demo/md/UiDemoPage.ts +0 -6
  157. package/demo/md/buttons/button.html +0 -121
  158. package/demo/md/buttons/button.ts +0 -246
  159. package/demo/md/buttons/group.html +0 -36
  160. package/demo/md/buttons/group.ts +0 -171
  161. package/demo/md/checkbox/index.html +0 -39
  162. package/demo/md/checkbox/index.ts +0 -220
  163. package/demo/md/chip/chip.html +0 -70
  164. package/demo/md/chip/chip.ts +0 -219
  165. package/demo/md/chip/pawel6c9a.jpg +0 -0
  166. package/demo/md/collapse/CustomDetail.ts +0 -89
  167. package/demo/md/collapse/collapse.html +0 -21
  168. package/demo/md/collapse/collapse.ts +0 -78
  169. package/demo/md/date-picker/date-picker.ts +0 -336
  170. package/demo/md/date-picker/index.html +0 -171
  171. package/demo/md/dialog/confirm-dialog.html +0 -49
  172. package/demo/md/dialog/confirm-dialog.ts +0 -121
  173. package/demo/md/dialog/dialog.html +0 -25
  174. package/demo/md/dialog/dialog.ts +0 -468
  175. package/demo/md/dropdown-list/index.html +0 -31
  176. package/demo/md/dropdown-list/index.ts +0 -158
  177. package/demo/md/icon-button/index.html +0 -122
  178. package/demo/md/icon-button/index.ts +0 -132
  179. package/demo/md/index.html +0 -73
  180. package/demo/md/inputs/input.html +0 -73
  181. package/demo/md/inputs/input.ts +0 -278
  182. package/demo/md/inputs/radio.html +0 -39
  183. package/demo/md/inputs/radio.ts +0 -156
  184. package/demo/md/inputs/switch.html +0 -45
  185. package/demo/md/inputs/switch.ts +0 -144
  186. package/demo/md/list/list.html +0 -65
  187. package/demo/md/list/list.ts +0 -204
  188. package/demo/md/listbox/listbox.html +0 -31
  189. package/demo/md/listbox/listbox.ts +0 -27
  190. package/demo/md/menu/index.html +0 -19
  191. package/demo/md/menu/index.ts +0 -514
  192. package/demo/md/notification/snack.html +0 -21
  193. package/demo/md/notification/snack.ts +0 -70
  194. package/demo/md/progress/progress.html +0 -46
  195. package/demo/md/progress/progress.ts +0 -161
  196. package/demo/md/segmented-button/index.html +0 -21
  197. package/demo/md/segmented-button/index.ts +0 -55
  198. package/demo/md/select/index.html +0 -16
  199. package/demo/md/select/index.ts +0 -207
  200. package/demo/md/tabs/tabs.html +0 -40
  201. package/demo/md/tabs/tabs.ts +0 -214
  202. package/demo/oauth-popup.html +0 -36
  203. package/demo/page.css +0 -8
  204. package/demo/resources/calendar-month.png +0 -0
  205. package/demo/resources/favorite.png +0 -0
  206. package/demo/resources/fingerprint.png +0 -0
  207. package/demo/resources/home-work.png +0 -0
  208. package/demo/resources/mood.png +0 -0
  209. package/demo/resources/print.png +0 -0
  210. package/demo/resources/stars.png +0 -0
  211. package/demo/resources/theaters.png +0 -0
  212. package/demo/tsconfig.json +0 -4
  213. package/eslint.config.js +0 -97
  214. package/scripts/copy-assets.js +0 -21
  215. package/scripts/release.js +0 -66
  216. package/src/demo/DemoPage.ts +0 -169
  217. package/src/demo/DemoStyles.ts +0 -60
  218. package/test/README.md +0 -375
  219. package/test/contextual-menu/ContextMenu.test.ts +0 -760
  220. package/test/contextual-menu/ContextMenuElement.test.ts +0 -569
  221. package/test/core/activity.spec.ts +0 -413
  222. package/test/core/activity_manager.spec.ts +0 -544
  223. package/test/core/application.spec.ts +0 -218
  224. package/test/core/fragment.spec.ts +0 -565
  225. package/test/core/fragment_manager.spec.ts +0 -404
  226. package/test/core/live_data.spec.ts +0 -558
  227. package/test/core/renderer.spec.ts +0 -113
  228. package/test/dom-assertions.test.ts +0 -182
  229. package/test/elements/MonacoSetup.ts +0 -65
  230. package/test/elements/authorization/basic-method.test.ts +0 -177
  231. package/test/elements/authorization/bearer-method.test.ts +0 -143
  232. package/test/elements/authorization/ntlm-method.test.ts +0 -219
  233. package/test/elements/authorization/oauth2-client-credentials-method.test.ts +0 -334
  234. package/test/elements/authorization/oauth2-code-method.test.ts +0 -320
  235. package/test/elements/authorization/oauth2-custom-grant-method.test.ts +0 -255
  236. package/test/elements/authorization/oauth2-device-code-method.test.ts +0 -371
  237. package/test/elements/authorization/oauth2-implicit-method.test.ts +0 -407
  238. package/test/elements/authorization/oauth2-jwt-method.test.ts +0 -217
  239. package/test/elements/authorization/oauth2-password-method.test.ts +0 -275
  240. package/test/elements/authorization/openid-method.test.ts +0 -591
  241. package/test/elements/autocomplete/autocomplete-input.spec.ts +0 -646
  242. package/test/elements/code-editor/code-editor.accessibility.test.ts +0 -298
  243. package/test/elements/code-editor/code-editor.test.ts +0 -574
  244. package/test/elements/currency/CurrencyPicker.accessibility.test.ts +0 -328
  245. package/test/elements/currency/CurrencyPicker.core.test.ts +0 -318
  246. package/test/elements/currency/CurrencyPicker.integration.test.ts +0 -482
  247. package/test/elements/currency/CurrencyPicker.test.ts +0 -486
  248. package/test/elements/data-table/DataTable.browser.test.ts +0 -649
  249. package/test/elements/har/HarUtils.test.ts +0 -45
  250. package/test/elements/har/HarViewerElement.test.ts +0 -687
  251. package/test/elements/har/test-data/har1.har +0 -3044
  252. package/test/elements/highlight/MarkedHighlightElement.test.ts +0 -452
  253. package/test/elements/highlight/PrismHighlightElement.test.ts +0 -79
  254. package/test/elements/highlight/PrismHighlighter.test.ts +0 -94
  255. package/test/elements/highlight/remoteSanitization.md +0 -1
  256. package/test/elements/highlight/test.md +0 -3
  257. package/test/elements/highlight/test1.md +0 -3
  258. package/test/elements/highlight/test2.md +0 -1
  259. package/test/elements/http/BodyFormdataEditorElement.test.ts +0 -482
  260. package/test/elements/http/BodyMultipartEditorElement.test.ts +0 -658
  261. package/test/elements/http/BodyRawEditorElement.test.ts +0 -90
  262. package/test/elements/http/CertificateAdd.test.ts +0 -457
  263. package/test/elements/http/HttpAssertions.test.ts +0 -994
  264. package/test/elements/http/HttpFlows.test.ts +0 -502
  265. package/test/elements/http/UrlEncodeUtils.test.ts +0 -202
  266. package/test/elements/layout/SplitItem.test.ts +0 -440
  267. package/test/elements/layout/SplitLayoutManager.test.ts +0 -1501
  268. package/test/elements/layout/SplitPanel.test.ts +0 -1109
  269. package/test/elements/mention-textarea/MentionTextArea.basic.test.ts +0 -114
  270. package/test/elements/mention-textarea/MentionTextArea.test.ts +0 -613
  271. package/test/elements/navigation/Navigation.test.ts +0 -120
  272. package/test/env.ts +0 -15
  273. package/test/events/EventTypes.test.ts +0 -363
  274. package/test/events/EventsTestHelpers.ts +0 -16
  275. package/test/helpers/TestUtils.ts +0 -243
  276. package/test/helpers/UiMock.ts +0 -185
  277. package/test/lib/Dom.test.ts +0 -231
  278. package/test/md/button/UiButton.test.ts +0 -347
  279. package/test/md/button/UiIconButton.test.ts +0 -155
  280. package/test/md/chip/UiChip.test.ts +0 -219
  281. package/test/md/collapse/UiCollapse.test.ts +0 -250
  282. package/test/md/collapse/flex-layout.test.ts +0 -105
  283. package/test/md/date-time/DateTime.test.ts +0 -348
  284. package/test/md/dialog/UiConfirmDialog.test.ts +0 -131
  285. package/test/md/dialog/UiDialog.test.ts +0 -759
  286. package/test/md/menu/Menu.test.ts +0 -855
  287. package/test/md/menu/MenuIntegration.test.ts +0 -426
  288. package/test/md/menu/MenuItem.test.ts +0 -652
  289. package/test/md/menu/SubMenu.test.ts +0 -410
  290. package/test/md/progress/UiCircularProgressElement.test.ts +0 -481
  291. package/test/md/progress/UiProgressElement.test.ts +0 -117
  292. package/test/md/progress/UiRangeElement.test.ts +0 -156
  293. package/test/md/select/Select.test.ts +0 -925
  294. package/test/plugins/takeScreenshotPlugin.js +0 -35
  295. package/test/setup.test.ts +0 -217
  296. package/test/setup.ts +0 -117
  297. package/test/tsconfig.json +0 -7
  298. package/web-dev-server.config.js +0 -21
  299. package/web-test-runner.config.js +0 -90
@@ -1,407 +0,0 @@
1
- import { html, fixture, assert, oneEvent, nextFrame, aTimeout } from '@open-wc/testing'
2
- import { spy } from 'sinon'
3
- import {
4
- EventTypes,
5
- IOAuth2Authorization,
6
- IRequestAuthorization,
7
- RequestAuthorizationKind,
8
- } from '@api-client/core/browser.js'
9
- import type OAuth2Authorization from '../../../src/elements/authorization/ui/OAuth2Authorization.js'
10
- import type Input from '../../../src/md/input/Input.js'
11
- import type UiButton from '../../../src/md/button/internals/button.js'
12
- import '../../../src/define/authorization/oauth2-authorization.js'
13
-
14
- describe('Authorization', () => {
15
- describe('<oauth2-authorization>', () => {
16
- describe('implicit', () => {
17
- const baseConfig: IOAuth2Authorization = {
18
- grantType: 'implicit',
19
- redirectUri: 'https://redirect.com/',
20
- clientId: 'test-client-id',
21
- authorizationUri: 'https://accounts.google.com/o/oauth2/v2/auth',
22
- scopes: ['email', 'profile'],
23
- }
24
-
25
- async function basicFixture(opts: IOAuth2Authorization = {}): Promise<OAuth2Authorization> {
26
- const auth: IRequestAuthorization = {
27
- config: opts,
28
- enabled: true,
29
- kind: RequestAuthorizationKind,
30
- type: 'oauth 2',
31
- valid: true,
32
- }
33
- return fixture(html`<oauth2-authorization .authorization="${auth}"></oauth2-authorization>`)
34
- }
35
-
36
- async function baseUriFixture(baseUri: string, opts: IOAuth2Authorization): Promise<OAuth2Authorization> {
37
- const auth: IRequestAuthorization = {
38
- config: opts,
39
- enabled: true,
40
- kind: RequestAuthorizationKind,
41
- type: 'oauth 2',
42
- valid: true,
43
- }
44
- return fixture(
45
- html`<oauth2-authorization .authorization="${auth}" .baseUri="${baseUri}"></oauth2-authorization>`
46
- )
47
- }
48
-
49
- describe('DOM rendering', () => {
50
- let element: OAuth2Authorization
51
- let form: HTMLFormElement
52
- beforeEach(async () => {
53
- element = await basicFixture({ ...baseConfig })
54
- form = element.shadowRoot!.querySelector('form')!
55
- })
56
-
57
- it('has form in the DOM', async () => {
58
- assert.ok(form)
59
- })
60
-
61
- it('has form has autocomplete', async () => {
62
- assert.equal(form.getAttribute('autocomplete'), 'on')
63
- })
64
-
65
- it(`has the clientId input`, async () => {
66
- const input = form.querySelector(`[name="clientId"]`) as Input
67
- assert.ok(input, 'has the input')
68
- })
69
-
70
- it(`has the authorizationUri input`, async () => {
71
- const input = form.querySelector(`[name="authorizationUri"]`) as Input
72
- assert.ok(input, 'has the input')
73
- })
74
-
75
- it('renders the redirect URI field', async () => {
76
- const section = element.shadowRoot!.querySelector('[name="redirectUri"]')
77
- assert.ok(section)
78
- })
79
-
80
- it('does not render token section when no token information', () => {
81
- const node = element.shadowRoot!.querySelector('.current-token')
82
- assert.notOk(node)
83
- })
84
-
85
- it('renders token section when token information is set', async () => {
86
- element.config.accessToken = 'test-token'
87
- element.requestUpdate()
88
- await element.updateComplete
89
- const node = element.shadowRoot!.querySelector('.current-token')!
90
- assert.ok(node)
91
- const label = node.querySelector('.token-value')!
92
- assert.equal(label.textContent!.trim(), 'test-token')
93
- })
94
-
95
- it('does not render the PKCE checkbox', async () => {
96
- const node = element.shadowRoot!.querySelector('[name="pkce"]')
97
- assert.notOk(node)
98
- })
99
- })
100
-
101
- describe('Data initialization', () => {
102
- let element: OAuth2Authorization
103
- beforeEach(async () => {
104
- element = await basicFixture({ ...baseConfig })
105
- })
106
-
107
- it(`has the clientId`, async () => {
108
- const input = element.shadowRoot!.querySelector(`[name="clientId"]`) as Input
109
- assert.equal(input.value, baseConfig.clientId)
110
- })
111
-
112
- it(`has the authorizationUri input`, async () => {
113
- const input = element.shadowRoot!.querySelector(`*[name="authorizationUri"]`) as Input
114
- assert.equal(input.value, baseConfig.authorizationUri)
115
- })
116
- })
117
-
118
- describe('Change notification', () => {
119
- let element: OAuth2Authorization
120
- beforeEach(async () => {
121
- element = await basicFixture({ ...baseConfig })
122
- })
123
-
124
- it(`notifies when clientId changes`, async () => {
125
- setTimeout(() => {
126
- const input = element.shadowRoot!.querySelector(`[name="clientId"]`) as Input
127
- input.value = 'changed'
128
- input.dispatchEvent(new CustomEvent('change'))
129
- })
130
- const e = await oneEvent(element, 'change')
131
- assert.ok(e)
132
- })
133
-
134
- it(`notifies when authorizationUri changes`, async () => {
135
- setTimeout(() => {
136
- const input = element.shadowRoot!.querySelector(`[name="authorizationUri"]`) as Input
137
- input.value = 'changed'
138
- input.dispatchEvent(new CustomEvent('change'))
139
- })
140
- const e = await oneEvent(element, 'change')
141
- assert.ok(e)
142
- })
143
- })
144
-
145
- describe('Data serialization', () => {
146
- let element: OAuth2Authorization
147
- beforeEach(async () => {
148
- element = await basicFixture({ ...baseConfig })
149
- })
150
-
151
- it(`serializes the clientId`, async () => {
152
- const result = element.serialize()
153
- assert.equal(result.clientId, baseConfig.clientId)
154
- })
155
-
156
- it(`serializes the authorizationUri`, async () => {
157
- const result = element.serialize()
158
- assert.equal(result.authorizationUri, baseConfig.authorizationUri)
159
- })
160
-
161
- it(`serializes the redirectUri`, async () => {
162
- const result = element.serialize()
163
- assert.equal(result.redirectUri, baseConfig.redirectUri)
164
- })
165
-
166
- it('has no pkce value', () => {
167
- element.config.pkce = true
168
- const result = element.serialize()
169
- assert.isUndefined(result.pkce)
170
- })
171
- })
172
-
173
- describe('authorization event', () => {
174
- let element: OAuth2Authorization
175
-
176
- beforeEach(async () => {
177
- element = await basicFixture({ ...baseConfig })
178
- })
179
-
180
- async function sendResponse(
181
- state?: string,
182
- tokenType?: string,
183
- e?: CustomEvent<IOAuth2Authorization>
184
- ): Promise<IOAuth2Authorization> {
185
- await aTimeout(1)
186
- return {
187
- accessToken: 'test-token',
188
- tokenType,
189
- state: state || e!.detail.state,
190
- }
191
- }
192
-
193
- function mockTokenRequest(state?: string, tokenType?: string): void {
194
- window.addEventListener(EventTypes.Authorization.OAuth2.authorize, function f(e) {
195
- window.removeEventListener(EventTypes.Authorization.OAuth2.authorize, f)
196
- e.preventDefault()
197
- const typed = e as CustomEvent<IOAuth2Authorization & { result?: unknown }>
198
- typed.detail.result = sendResponse(state, tokenType, typed)
199
- })
200
- }
201
-
202
- function mockTokenErrorRequest(message?: string): void {
203
- window.addEventListener(EventTypes.Authorization.OAuth2.authorize, function f(e) {
204
- window.removeEventListener(EventTypes.Authorization.OAuth2.authorize, f)
205
- e.preventDefault()
206
- const typed = e as CustomEvent<IOAuth2Authorization & { result?: unknown }>
207
- typed.detail.result = Promise.reject(new Error(message))
208
- })
209
- }
210
-
211
- it(`sets the serialized values onto the event`, async () => {
212
- const handler = spy()
213
- element.addEventListener(EventTypes.Authorization.OAuth2.authorize, handler)
214
- element.authorize()
215
- const { detail } = handler.args[0][0] as CustomEvent<IOAuth2Authorization & { result?: unknown }>
216
- delete detail.state
217
- delete detail.result
218
- assert.deepEqual(detail, element.serialize())
219
- })
220
-
221
- it('calls authorize() from button click', () => {
222
- const button = element.shadowRoot!.querySelector('.auth-button') as UiButton
223
- const handler = spy()
224
- element.addEventListener(EventTypes.Authorization.OAuth2.authorize, handler)
225
- button.click()
226
- assert.isTrue(handler.called)
227
- })
228
-
229
- it('sets the #authorizing flag', async () => {
230
- mockTokenRequest()
231
- const button = element.shadowRoot!.querySelector('.auth-button') as UiButton
232
- button.click()
233
- assert.isTrue(element.authorizing)
234
- })
235
-
236
- it('ignores authorization when did not pass validation', async () => {
237
- element.config.clientId = ''
238
- element.requestUpdate()
239
- await element.updateComplete
240
- element.authorize()
241
- assert.isFalse(element.authorizing)
242
- })
243
-
244
- it('resets the #authorizing flag when token response', async () => {
245
- mockTokenRequest()
246
- element.authorize()
247
- await aTimeout(2)
248
- await nextFrame()
249
- assert.isFalse(element.authorizing)
250
- })
251
-
252
- it('sets state on the event', async () => {
253
- const handler = spy()
254
- element.addEventListener(EventTypes.Authorization.OAuth2.authorize, handler)
255
- element.authorize()
256
- const { detail } = handler.args[0][0] as CustomEvent<IOAuth2Authorization & { result?: unknown }>
257
- const eventState = detail.state
258
- assert.typeOf(eventState, 'string', 'event state is set')
259
- })
260
-
261
- it('sets values from the response event with state', async () => {
262
- mockTokenRequest(undefined, 'other')
263
- element.authorize()
264
- await aTimeout(2)
265
- await nextFrame()
266
- assert.equal(element.config.accessToken, 'test-token')
267
- assert.equal(element.config.tokenType, 'other')
268
- })
269
-
270
- it('ignores events with different state', async () => {
271
- mockTokenRequest('unknown-state', 'other')
272
- element.authorize()
273
- await aTimeout(2)
274
- await nextFrame()
275
- assert.isUndefined(element.config.accessToken)
276
- })
277
-
278
- it('ignores the response event when token is already set', async () => {
279
- mockTokenRequest(undefined, 'token-value')
280
- element.authorize()
281
- element.config.accessToken = 'test-token'
282
- await aTimeout(2)
283
- await nextFrame()
284
- assert.equal(element.config.accessToken, 'test-token')
285
- })
286
-
287
- it('restores default token type from the response event', async () => {
288
- mockTokenRequest()
289
- element.authorize()
290
- element.config.tokenType = 'custom'
291
- element.requestUpdate()
292
- await element.updateComplete
293
- await aTimeout(2)
294
- await nextFrame()
295
- assert.equal(element.config.tokenType, 'Bearer')
296
- })
297
-
298
- it('dispatches change event when the token is received', async () => {
299
- mockTokenRequest()
300
- const handler = spy()
301
- element.addEventListener('change', handler)
302
- element.authorize()
303
- await aTimeout(2)
304
- await nextFrame()
305
- assert.isTrue(handler.called)
306
- })
307
-
308
- it('resets the #authorizing flag when token error', async () => {
309
- mockTokenErrorRequest()
310
- try {
311
- await element.authorize()
312
- } catch {
313
- // ..
314
- }
315
- await nextFrame()
316
- assert.isFalse(element.authorizing)
317
- })
318
-
319
- it('sets "lastErrorMessage" with event message', async () => {
320
- const message = 'Test error'
321
- mockTokenErrorRequest(message)
322
- await nextFrame()
323
- try {
324
- await element.authorize()
325
- } catch {
326
- // ..
327
- }
328
- await nextFrame()
329
- assert.equal(element.lastErrorMessage, message)
330
- })
331
-
332
- it('renders error message', async () => {
333
- mockTokenErrorRequest('This is an error')
334
- try {
335
- await element.authorize()
336
- } catch {
337
- // ...
338
- }
339
- await nextFrame()
340
- const node = element.shadowRoot!.querySelector('.error-message')
341
- assert.ok(node)
342
- })
343
-
344
- it('clears "lastErrorMessage" when requesting the token again', async () => {
345
- mockTokenErrorRequest('This is an error')
346
- try {
347
- await element.authorize()
348
- } catch {
349
- // ...
350
- }
351
- await nextFrame()
352
- await element.authorize()
353
- assert.isUndefined(element.lastErrorMessage)
354
- })
355
- })
356
-
357
- describe('#baseUri', () => {
358
- const baseUri = 'https://api.domain.com/auth'
359
-
360
- it('adds base URI to authorizationUri', async () => {
361
- const params = { ...baseConfig }
362
- params.authorizationUri = '/authorize'
363
- const element = await baseUriFixture(baseUri, params)
364
- const result = element.serialize()
365
- assert.equal(result.authorizationUri, 'https://api.domain.com/auth/authorize')
366
- })
367
-
368
- it('adds base URI to redirectUri', async () => {
369
- const params = { ...baseConfig }
370
- params.redirectUri = '/redirect'
371
-
372
- const element = await baseUriFixture(baseUri, params)
373
- const result = element.serialize()
374
- assert.equal(result.redirectUri, 'https://api.domain.com/auth/redirect')
375
- })
376
-
377
- it('ignores trailing slash', async () => {
378
- const uri = `${baseUri}/`
379
- const params = { ...baseConfig }
380
- params.redirectUri = '/redirect'
381
-
382
- const element = await baseUriFixture(uri, params)
383
- const result = element.serialize()
384
- assert.equal(result.redirectUri, 'https://api.domain.com/auth/redirect')
385
- })
386
-
387
- it('makes authorizationUri input text type', async () => {
388
- const element = await baseUriFixture(baseUri, { ...baseConfig })
389
- const node = element.shadowRoot!.querySelector('[name="authorizationUri"]') as Input
390
- assert.equal(node.type, 'string')
391
- })
392
- })
393
-
394
- describe('a11y', () => {
395
- let element: OAuth2Authorization
396
-
397
- beforeEach(async () => {
398
- element = await basicFixture({ ...baseConfig })
399
- })
400
-
401
- it('passes automated a11y tests', async () => {
402
- await assert.isAccessible(element)
403
- })
404
- })
405
- })
406
- })
407
- })
@@ -1,217 +0,0 @@
1
- import { html, fixture, assert, oneEvent, nextFrame } from '@open-wc/testing'
2
- import { spy } from 'sinon'
3
- import {
4
- EventTypes,
5
- IOAuth2Authorization,
6
- IRequestAuthorization,
7
- RequestAuthorizationKind,
8
- } from '@api-client/core/browser.js'
9
- import type OAuth2Authorization from '../../../src/elements/authorization/ui/OAuth2Authorization.js'
10
- import type Input from '../../../src/md/input/Input.js'
11
- import type UiButton from '../../../src/md/button/internals/button.js'
12
- import '../../../src/define/authorization/oauth2-authorization.js'
13
-
14
- describe('Authorization', () => {
15
- describe('<oauth2-authorization>', () => {
16
- describe('urn:ietf:params:oauth:grant-type:jwt-bearer', () => {
17
- const baseConfig: IOAuth2Authorization = {
18
- grantType: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
19
- redirectUri: 'https://redirect.com/',
20
- accessTokenUri: 'https://accounts.google.com/o/oauth2/v2/token',
21
- scopes: ['email', 'profile'],
22
- assertion: 'test-jwt',
23
- }
24
-
25
- async function basicFixture(opts: IOAuth2Authorization = {}): Promise<OAuth2Authorization> {
26
- const auth: IRequestAuthorization = {
27
- config: opts,
28
- enabled: true,
29
- kind: RequestAuthorizationKind,
30
- type: 'oauth 2',
31
- valid: true,
32
- }
33
- return fixture(html`<oauth2-authorization .authorization="${auth}"></oauth2-authorization>`)
34
- }
35
-
36
- async function baseUriFixture(baseUri: string, opts: IOAuth2Authorization): Promise<OAuth2Authorization> {
37
- const auth: IRequestAuthorization = {
38
- config: opts,
39
- enabled: true,
40
- kind: RequestAuthorizationKind,
41
- type: 'oauth 2',
42
- valid: true,
43
- }
44
- return fixture(
45
- html`<oauth2-authorization .authorization="${auth}" .baseUri="${baseUri}"></oauth2-authorization>`
46
- )
47
- }
48
-
49
- describe('DOM rendering', () => {
50
- let element: OAuth2Authorization
51
- let form: HTMLFormElement
52
- beforeEach(async () => {
53
- element = await basicFixture({ ...baseConfig })
54
- form = element.shadowRoot!.querySelector('form')!
55
- })
56
-
57
- it('has form in the DOM', async () => {
58
- assert.ok(form)
59
- })
60
-
61
- it(`has the accessTokenUri input`, async () => {
62
- const input = form.querySelector(`[name="accessTokenUri"]`) as Input
63
- assert.ok(input, 'has the input')
64
- })
65
-
66
- it(`has the assertion input`, async () => {
67
- const input = form.querySelector(`[name="assertion"]`) as Input
68
- assert.ok(input, 'has the input')
69
- })
70
-
71
- it('does not render redirect URI filed', async () => {
72
- const node = element.shadowRoot!.querySelector('[name="redirectUri"]')
73
- assert.notOk(node)
74
- })
75
-
76
- it('does not render token section when no token information', () => {
77
- const node = element.shadowRoot!.querySelector('.current-token')
78
- assert.notOk(node)
79
- })
80
-
81
- it('renders token section when token information is set', async () => {
82
- element.config.accessToken = 'test-token'
83
- element.requestUpdate()
84
- await element.updateComplete
85
- const node = element.shadowRoot!.querySelector('.current-token')!
86
- assert.ok(node)
87
- const label = node.querySelector('.token-value')!
88
- assert.equal(label.textContent!.trim(), 'test-token')
89
- })
90
- })
91
-
92
- describe('Data initialization', () => {
93
- let element: OAuth2Authorization
94
- beforeEach(async () => {
95
- element = await basicFixture({ ...baseConfig })
96
- })
97
-
98
- it(`has the accessTokenUri input`, async () => {
99
- const input = element.shadowRoot!.querySelector(`[name="accessTokenUri"]`) as Input
100
- assert.equal(input.value, baseConfig.accessTokenUri)
101
- })
102
-
103
- it(`has the assertion input`, async () => {
104
- const input = element.shadowRoot!.querySelector(`[name="assertion"]`) as Input
105
- assert.equal(input.value, baseConfig.assertion)
106
- })
107
- })
108
-
109
- describe('Change notification', () => {
110
- let element: OAuth2Authorization
111
- beforeEach(async () => {
112
- element = await basicFixture({ ...baseConfig })
113
- })
114
-
115
- it(`notifies when accessTokenUri changes`, async () => {
116
- setTimeout(() => {
117
- const input = element.shadowRoot!.querySelector(`[name="accessTokenUri"]`) as Input
118
- input.value = 'changed'
119
- input.dispatchEvent(new CustomEvent('change'))
120
- })
121
- const e = await oneEvent(element, 'change')
122
- assert.ok(e)
123
- })
124
-
125
- it(`notifies when assertion changes`, async () => {
126
- setTimeout(() => {
127
- const input = element.shadowRoot!.querySelector(`[name="assertion"]`) as Input
128
- input.value = 'changed'
129
- input.dispatchEvent(new CustomEvent('change'))
130
- })
131
- const e = await oneEvent(element, 'change')
132
- assert.ok(e)
133
- })
134
- })
135
-
136
- describe('Data serialization', () => {
137
- let element: OAuth2Authorization
138
- beforeEach(async () => {
139
- element = await basicFixture({ ...baseConfig })
140
- })
141
-
142
- it(`serializes the accessTokenUri`, async () => {
143
- const result = element.serialize()
144
- assert.equal(result.accessTokenUri, baseConfig.accessTokenUri)
145
- })
146
-
147
- it(`serializes the scopes`, async () => {
148
- const result = element.serialize()
149
- assert.deepEqual(result.scopes, baseConfig.scopes)
150
- })
151
-
152
- it(`serializes the assertion`, async () => {
153
- const result = element.serialize()
154
- assert.deepEqual(result.assertion, baseConfig.assertion)
155
- })
156
-
157
- it('deletes the client id', async () => {
158
- element.config.clientId = 'test'
159
- await nextFrame()
160
- const result = element.serialize()
161
- assert.isUndefined(result.clientId)
162
- })
163
- })
164
-
165
- describe('authorization event', () => {
166
- let element: OAuth2Authorization
167
-
168
- beforeEach(async () => {
169
- element = await basicFixture({ ...baseConfig })
170
- })
171
-
172
- it(`sets the serialized values onto the event`, async () => {
173
- const handler = spy()
174
- element.addEventListener(EventTypes.Authorization.OAuth2.authorize, handler)
175
- element.authorize()
176
- const { detail } = handler.args[0][0] as CustomEvent<IOAuth2Authorization & { result?: unknown }>
177
- delete detail.state
178
- delete detail.result
179
- assert.deepEqual(detail, element.serialize())
180
- })
181
-
182
- it('calls authorize() from button click', () => {
183
- const button = element.shadowRoot!.querySelector('.auth-button') as UiButton
184
- const handler = spy()
185
- element.addEventListener(EventTypes.Authorization.OAuth2.authorize, handler)
186
- button.click()
187
- assert.isTrue(handler.called)
188
- })
189
- })
190
-
191
- describe('#baseUri', () => {
192
- const baseUri = 'https://api.domain.com/auth'
193
-
194
- it('adds base URI to accessTokenUri', async () => {
195
- const params = { ...baseConfig }
196
- params.accessTokenUri = '/authorize'
197
- const element = await baseUriFixture(baseUri, params)
198
- await nextFrame()
199
- const result = element.serialize()
200
- assert.equal(result.accessTokenUri, 'https://api.domain.com/auth/authorize')
201
- })
202
- })
203
-
204
- describe('a11y', () => {
205
- let element: OAuth2Authorization
206
-
207
- beforeEach(async () => {
208
- element = await basicFixture({ ...baseConfig })
209
- })
210
-
211
- it('passes automated a11y tests', async () => {
212
- await assert.isAccessible(element)
213
- })
214
- })
215
- })
216
- })
217
- })