@api-client/ui 0.5.39 → 0.5.41
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/build/src/elements/contextual-menu/{internals/ContextualMenu.d.ts → ContextualMenu.d.ts} +11 -6
- package/build/src/elements/contextual-menu/ContextualMenu.d.ts.map +1 -0
- package/build/src/elements/contextual-menu/{internals/ContextualMenu.js → ContextualMenu.js} +25 -3
- package/build/src/elements/contextual-menu/ContextualMenu.js.map +1 -0
- package/build/src/elements/contextual-menu/internals/types.d.ts +16 -7
- package/build/src/elements/contextual-menu/internals/types.d.ts.map +1 -1
- package/build/src/elements/contextual-menu/internals/types.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
- package/src/elements/contextual-menu/{internals/ContextualMenu.ts → ContextualMenu.ts} +31 -7
- package/src/elements/contextual-menu/internals/types.ts +17 -7
- package/.aiexclude +0 -3
- package/.cursor/rules/html-and-css-best-practices.mdc +0 -63
- package/.cursor/rules/lit-best-practices.mdc +0 -89
- package/.editorconfig +0 -29
- package/.github/CONTRIBUTING.md +0 -24
- package/.github/instructions/html-and-css-best-practices.instructions.md +0 -70
- package/.github/instructions/lit-best-practices.instructions.md +0 -90
- package/.github/release.yml +0 -14
- package/.github/stale.yml +0 -23
- package/.github/workflows/auto-release.yml +0 -182
- package/.github/workflows/release.yml +0 -82
- package/.prettierrc.js +0 -14
- package/.vscode/settings.json +0 -18
- package/RELEASE.md +0 -163
- package/RELEASE_SETUP.md +0 -235
- package/build/src/demo/DemoPage.d.ts +0 -81
- package/build/src/demo/DemoPage.d.ts.map +0 -1
- package/build/src/demo/DemoPage.js +0 -175
- package/build/src/demo/DemoPage.js.map +0 -1
- package/build/src/demo/DemoStyles.d.ts +0 -3
- package/build/src/demo/DemoStyles.d.ts.map +0 -1
- package/build/src/demo/DemoStyles.js +0 -60
- package/build/src/demo/DemoStyles.js.map +0 -1
- package/build/src/elements/contextual-menu/internals/ContextualMenu.d.ts.map +0 -1
- package/build/src/elements/contextual-menu/internals/ContextualMenu.js.map +0 -1
- package/build/test/elements/navigation/Navigation.test.d.ts +0 -3
- package/build/test/elements/navigation/Navigation.test.d.ts.map +0 -1
- package/build/test/elements/navigation/Navigation.test.js +0 -113
- package/build/test/elements/navigation/Navigation.test.js.map +0 -1
- package/commitlint.config.cjs +0 -2
- package/demo/elements/authorization/AuthPlugin.js +0 -57
- package/demo/elements/authorization/AuthProxy.js +0 -215
- package/demo/elements/authorization/api-key.html +0 -27
- package/demo/elements/authorization/api-key.ts +0 -44
- package/demo/elements/authorization/basic.html +0 -27
- package/demo/elements/authorization/basic.ts +0 -43
- package/demo/elements/authorization/bearer.html +0 -27
- package/demo/elements/authorization/bearer.ts +0 -43
- package/demo/elements/authorization/env.js +0 -8
- package/demo/elements/authorization/index.html +0 -44
- package/demo/elements/authorization/ntlm.html +0 -27
- package/demo/elements/authorization/ntlm.ts +0 -43
- package/demo/elements/authorization/oauth-authorize.html +0 -75
- package/demo/elements/authorization/oauth-authorize.ts +0 -40
- package/demo/elements/authorization/oauth-error.html +0 -18
- package/demo/elements/authorization/oauth-error.ts +0 -10
- package/demo/elements/authorization/oauth-popup.html +0 -36
- package/demo/elements/authorization/oauth2.html +0 -27
- package/demo/elements/authorization/oauth2.ts +0 -100
- package/demo/elements/authorization/oidc.html +0 -27
- package/demo/elements/authorization/oidc.ts +0 -139
- package/demo/elements/authorization/private.crt +0 -31
- package/demo/elements/authorization/private.csr +0 -28
- package/demo/elements/authorization/private.key +0 -51
- package/demo/elements/authorization/private.pem +0 -31
- package/demo/elements/authorization/redirect.html +0 -20
- package/demo/elements/authorization/ssl-commands.sh +0 -30
- package/demo/elements/authorization/ssl.conf +0 -24
- package/demo/elements/autocomplete/index.html +0 -64
- package/demo/elements/autocomplete/index.ts +0 -171
- package/demo/elements/code-editor/CodeEditorDemo.ts +0 -173
- package/demo/elements/code-editor/index.html +0 -19
- package/demo/elements/context-menu/DemoIcons.ts +0 -21
- package/demo/elements/context-menu/basic.html +0 -25
- package/demo/elements/context-menu/basic.ts +0 -119
- package/demo/elements/context-menu/custom-data.html +0 -25
- package/demo/elements/context-menu/custom-data.ts +0 -62
- package/demo/elements/context-menu/demo.css +0 -28
- package/demo/elements/context-menu/enabled-state.html +0 -25
- package/demo/elements/context-menu/enabled-state.ts +0 -73
- package/demo/elements/context-menu/icons.html +0 -25
- package/demo/elements/context-menu/icons.ts +0 -64
- package/demo/elements/context-menu/index.html +0 -43
- package/demo/elements/context-menu/nested.html +0 -25
- package/demo/elements/context-menu/nestedt.ts +0 -152
- package/demo/elements/context-menu/no-execute.html +0 -25
- package/demo/elements/context-menu/no-execute.ts +0 -134
- package/demo/elements/context-menu/radio-menu.html +0 -25
- package/demo/elements/context-menu/radio-menu.ts +0 -83
- package/demo/elements/context-menu/separators.html +0 -25
- package/demo/elements/context-menu/separators.ts +0 -172
- package/demo/elements/currency/index.html +0 -91
- package/demo/elements/currency/index.ts +0 -352
- package/demo/elements/environment/environment-editor.html +0 -20
- package/demo/elements/environment/environment-editor.ts +0 -49
- package/demo/elements/environment/index.html +0 -33
- package/demo/elements/environment/server-editor.html +0 -20
- package/demo/elements/environment/server-editor.ts +0 -67
- package/demo/elements/environment/variables-editor.html +0 -20
- package/demo/elements/environment/variables-editor.ts +0 -94
- package/demo/elements/har/har-viewer.html +0 -20
- package/demo/elements/har/har-viewer.ts +0 -76
- package/demo/elements/har/har1.har +0 -3044
- package/demo/elements/har/har2.json +0 -439
- package/demo/elements/har/index.html +0 -26
- package/demo/elements/highlight/example.md +0 -27
- package/demo/elements/highlight/index.html +0 -31
- package/demo/elements/highlight/marked-highlight.html +0 -132
- package/demo/elements/highlight/marked-highlight.ts +0 -22
- package/demo/elements/highlight/prism-highlight.html +0 -62
- package/demo/elements/highlight/prism-highlight.ts +0 -17
- package/demo/elements/http/body-editor.html +0 -17
- package/demo/elements/http/body-editor.ts +0 -115
- package/demo/elements/http/headers.html +0 -17
- package/demo/elements/http/headers.ts +0 -59
- package/demo/elements/http/http-assertions.html +0 -20
- package/demo/elements/http/http-assertions.ts +0 -89
- package/demo/elements/http/http-flows.html +0 -23
- package/demo/elements/http/http-flows.ts +0 -89
- package/demo/elements/http/index.html +0 -45
- package/demo/elements/http/request-editor.html +0 -26
- package/demo/elements/http/request-editor.ts +0 -197
- package/demo/elements/http/request-log.html +0 -16
- package/demo/elements/http/request-log.ts +0 -136
- package/demo/elements/http/url-editing.html +0 -17
- package/demo/elements/http/url-editing.ts +0 -112
- package/demo/elements/icons/index.html +0 -81
- package/demo/elements/icons/index.ts +0 -52
- package/demo/elements/index.html +0 -72
- package/demo/elements/mention-textarea/index.html +0 -19
- package/demo/elements/mention-textarea/index.ts +0 -205
- package/demo/elements/navigation/navigation-item.html +0 -49
- package/demo/elements/navigation/navigation-item.ts +0 -131
- package/demo/elements/navigation/navigation.html +0 -20
- package/demo/elements/navigation/navigation.ts +0 -45
- package/demo/elements/project/index.html +0 -29
- package/demo/elements/project/project-run-report.html +0 -20
- package/demo/elements/project/project-run-report.ts +0 -132
- package/demo/elements/project/request-editor.html +0 -23
- package/demo/elements/project/request-editor.ts +0 -232
- package/demo/elements/user/user-avatar.html +0 -17
- package/demo/elements/user/user-avatar.ts +0 -60
- package/demo/env.js +0 -4
- package/demo/index.html +0 -34
- package/demo/layout/index.html +0 -94
- package/demo/layout/index.ts +0 -190
- package/demo/md/DemoStyles.ts +0 -61
- package/demo/md/UiDemoPage.ts +0 -6
- package/demo/md/buttons/button.html +0 -121
- package/demo/md/buttons/button.ts +0 -246
- package/demo/md/buttons/group.html +0 -36
- package/demo/md/buttons/group.ts +0 -171
- package/demo/md/checkbox/index.html +0 -39
- package/demo/md/checkbox/index.ts +0 -220
- package/demo/md/chip/chip.html +0 -70
- package/demo/md/chip/chip.ts +0 -219
- package/demo/md/chip/pawel6c9a.jpg +0 -0
- package/demo/md/collapse/CustomDetail.ts +0 -89
- package/demo/md/collapse/collapse.html +0 -21
- package/demo/md/collapse/collapse.ts +0 -78
- package/demo/md/date-picker/date-picker.ts +0 -336
- package/demo/md/date-picker/index.html +0 -171
- package/demo/md/dialog/confirm-dialog.html +0 -49
- package/demo/md/dialog/confirm-dialog.ts +0 -121
- package/demo/md/dialog/dialog.html +0 -25
- package/demo/md/dialog/dialog.ts +0 -468
- package/demo/md/dropdown-list/index.html +0 -31
- package/demo/md/dropdown-list/index.ts +0 -158
- package/demo/md/icon-button/index.html +0 -122
- package/demo/md/icon-button/index.ts +0 -132
- package/demo/md/index.html +0 -73
- package/demo/md/inputs/input.html +0 -73
- package/demo/md/inputs/input.ts +0 -278
- package/demo/md/inputs/radio.html +0 -39
- package/demo/md/inputs/radio.ts +0 -156
- package/demo/md/inputs/switch.html +0 -45
- package/demo/md/inputs/switch.ts +0 -144
- package/demo/md/list/list.html +0 -65
- package/demo/md/list/list.ts +0 -204
- package/demo/md/listbox/listbox.html +0 -31
- package/demo/md/listbox/listbox.ts +0 -27
- package/demo/md/menu/index.html +0 -19
- package/demo/md/menu/index.ts +0 -514
- package/demo/md/notification/snack.html +0 -21
- package/demo/md/notification/snack.ts +0 -70
- package/demo/md/progress/progress.html +0 -46
- package/demo/md/progress/progress.ts +0 -161
- package/demo/md/segmented-button/index.html +0 -21
- package/demo/md/segmented-button/index.ts +0 -55
- package/demo/md/select/index.html +0 -16
- package/demo/md/select/index.ts +0 -217
- package/demo/md/tabs/tabs.html +0 -40
- package/demo/md/tabs/tabs.ts +0 -214
- package/demo/oauth-popup.html +0 -36
- package/demo/page.css +0 -8
- package/demo/resources/calendar-month.png +0 -0
- package/demo/resources/favorite.png +0 -0
- package/demo/resources/fingerprint.png +0 -0
- package/demo/resources/home-work.png +0 -0
- package/demo/resources/mood.png +0 -0
- package/demo/resources/print.png +0 -0
- package/demo/resources/stars.png +0 -0
- package/demo/resources/theaters.png +0 -0
- package/demo/tsconfig.json +0 -4
- package/eslint.config.js +0 -97
- package/scripts/copy-assets.js +0 -21
- package/scripts/release.js +0 -66
- package/src/demo/DemoPage.ts +0 -169
- package/src/demo/DemoStyles.ts +0 -60
- package/test/README.md +0 -375
- package/test/contextual-menu/ContextMenu.test.ts +0 -760
- package/test/contextual-menu/ContextMenuElement.test.ts +0 -569
- package/test/core/activity.spec.ts +0 -413
- package/test/core/activity_manager.spec.ts +0 -544
- package/test/core/application.spec.ts +0 -218
- package/test/core/fragment.spec.ts +0 -565
- package/test/core/fragment_manager.spec.ts +0 -404
- package/test/core/live_data.spec.ts +0 -558
- package/test/core/renderer.spec.ts +0 -113
- package/test/dom-assertions.test.ts +0 -182
- package/test/elements/MonacoSetup.ts +0 -65
- package/test/elements/authorization/basic-method.test.ts +0 -177
- package/test/elements/authorization/bearer-method.test.ts +0 -143
- package/test/elements/authorization/ntlm-method.test.ts +0 -219
- package/test/elements/authorization/oauth2-client-credentials-method.test.ts +0 -334
- package/test/elements/authorization/oauth2-code-method.test.ts +0 -320
- package/test/elements/authorization/oauth2-custom-grant-method.test.ts +0 -255
- package/test/elements/authorization/oauth2-device-code-method.test.ts +0 -371
- package/test/elements/authorization/oauth2-implicit-method.test.ts +0 -407
- package/test/elements/authorization/oauth2-jwt-method.test.ts +0 -217
- package/test/elements/authorization/oauth2-password-method.test.ts +0 -275
- package/test/elements/authorization/openid-method.test.ts +0 -591
- package/test/elements/autocomplete/autocomplete-input.spec.ts +0 -646
- package/test/elements/code-editor/code-editor.accessibility.test.ts +0 -298
- package/test/elements/code-editor/code-editor.test.ts +0 -574
- package/test/elements/currency/CurrencyPicker.accessibility.test.ts +0 -328
- package/test/elements/currency/CurrencyPicker.core.test.ts +0 -318
- package/test/elements/currency/CurrencyPicker.integration.test.ts +0 -482
- package/test/elements/currency/CurrencyPicker.test.ts +0 -486
- package/test/elements/data-table/DataTable.browser.test.ts +0 -649
- package/test/elements/har/HarUtils.test.ts +0 -45
- package/test/elements/har/HarViewerElement.test.ts +0 -687
- package/test/elements/har/test-data/har1.har +0 -3044
- package/test/elements/highlight/MarkedHighlightElement.test.ts +0 -452
- package/test/elements/highlight/PrismHighlightElement.test.ts +0 -79
- package/test/elements/highlight/PrismHighlighter.test.ts +0 -94
- package/test/elements/highlight/remoteSanitization.md +0 -1
- package/test/elements/highlight/test.md +0 -3
- package/test/elements/highlight/test1.md +0 -3
- package/test/elements/highlight/test2.md +0 -1
- package/test/elements/http/BodyFormdataEditorElement.test.ts +0 -482
- package/test/elements/http/BodyMultipartEditorElement.test.ts +0 -658
- package/test/elements/http/BodyRawEditorElement.test.ts +0 -90
- package/test/elements/http/CertificateAdd.test.ts +0 -457
- package/test/elements/http/HttpAssertions.test.ts +0 -994
- package/test/elements/http/HttpFlows.test.ts +0 -502
- package/test/elements/http/UrlEncodeUtils.test.ts +0 -202
- package/test/elements/layout/SplitItem.test.ts +0 -440
- package/test/elements/layout/SplitLayoutManager.test.ts +0 -1501
- package/test/elements/layout/SplitPanel.test.ts +0 -1109
- package/test/elements/mention-textarea/MentionTextArea.basic.test.ts +0 -114
- package/test/elements/mention-textarea/MentionTextArea.test.ts +0 -613
- package/test/elements/navigation/Navigation.test.ts +0 -120
- package/test/env.ts +0 -15
- package/test/events/EventTypes.test.ts +0 -363
- package/test/events/EventsTestHelpers.ts +0 -16
- package/test/helpers/TestUtils.ts +0 -243
- package/test/helpers/UiMock.ts +0 -185
- package/test/lib/Dom.test.ts +0 -231
- package/test/md/button/UiButton.test.ts +0 -347
- package/test/md/button/UiIconButton.test.ts +0 -155
- package/test/md/chip/UiChip.test.ts +0 -219
- package/test/md/collapse/UiCollapse.test.ts +0 -250
- package/test/md/collapse/flex-layout.test.ts +0 -105
- package/test/md/date-time/DateTime.test.ts +0 -348
- package/test/md/dialog/UiConfirmDialog.test.ts +0 -131
- package/test/md/dialog/UiDialog.test.ts +0 -759
- package/test/md/menu/Menu.test.ts +0 -855
- package/test/md/menu/MenuIntegration.test.ts +0 -426
- package/test/md/menu/MenuItem.test.ts +0 -652
- package/test/md/menu/SubMenu.test.ts +0 -410
- package/test/md/progress/UiCircularProgressElement.test.ts +0 -481
- package/test/md/progress/UiProgressElement.test.ts +0 -117
- package/test/md/progress/UiRangeElement.test.ts +0 -156
- package/test/md/select/Select.test.ts +0 -925
- package/test/plugins/takeScreenshotPlugin.js +0 -35
- package/test/setup.test.ts +0 -217
- package/test/setup.ts +0 -117
- package/test/tsconfig.json +0 -7
- package/web-dev-server.config.js +0 -21
- package/web-test-runner.config.js +0 -90
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extended test utilities for the UI component library.
|
|
3
|
-
* Provides Jest-like matchers and additional testing helpers.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { expect } from '@open-wc/testing'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Custom matchers for better test assertions
|
|
10
|
-
*/
|
|
11
|
-
export const customMatchers = {
|
|
12
|
-
/**
|
|
13
|
-
* Check if an element has specific CSS classes
|
|
14
|
-
*/
|
|
15
|
-
toHaveClasses(received: Element, ...classes: string[]) {
|
|
16
|
-
const classList = Array.from(received.classList)
|
|
17
|
-
const missing = classes.filter((cls) => !classList.includes(cls))
|
|
18
|
-
|
|
19
|
-
if (missing.length === 0) {
|
|
20
|
-
return {
|
|
21
|
-
message: () => `Expected element not to have classes: ${classes.join(', ')}`,
|
|
22
|
-
pass: true,
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
return {
|
|
26
|
-
message: () => `Expected element to have classes: ${missing.join(', ')}`,
|
|
27
|
-
pass: false,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Check if an element is visible (not hidden by CSS)
|
|
34
|
-
*/
|
|
35
|
-
toBeVisible(received: Element) {
|
|
36
|
-
const style = window.getComputedStyle(received)
|
|
37
|
-
const isVisible = style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'
|
|
38
|
-
|
|
39
|
-
if (isVisible) {
|
|
40
|
-
return {
|
|
41
|
-
message: () => 'Expected element to be hidden',
|
|
42
|
-
pass: true,
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
return {
|
|
46
|
-
message: () => 'Expected element to be visible',
|
|
47
|
-
pass: false,
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Check if an element has a specific attribute value
|
|
54
|
-
*/
|
|
55
|
-
toHaveAttribute(received: Element, attribute: string, value?: string) {
|
|
56
|
-
const hasAttribute = received.hasAttribute(attribute)
|
|
57
|
-
|
|
58
|
-
if (!hasAttribute) {
|
|
59
|
-
return {
|
|
60
|
-
message: () => `Expected element to have attribute "${attribute}"`,
|
|
61
|
-
pass: false,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (value !== undefined) {
|
|
66
|
-
const actualValue = received.getAttribute(attribute)
|
|
67
|
-
if (actualValue !== value) {
|
|
68
|
-
return {
|
|
69
|
-
message: () => `Expected attribute "${attribute}" to be "${value}", but got "${actualValue}"`,
|
|
70
|
-
pass: false,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
message: () => `Expected element not to have attribute "${attribute}"${value ? ` with value "${value}"` : ''}`,
|
|
77
|
-
pass: true,
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Helper to demonstrate proper DOM element comparison
|
|
83
|
-
* Note: Always use assert.dom.equal() for DOM element comparison, not assert.equal()
|
|
84
|
-
*/
|
|
85
|
-
domElementsEqual(actual: Element, expected: Element): boolean {
|
|
86
|
-
// This is just a helper - in actual tests, use assert.dom.equal(actual, expected)
|
|
87
|
-
return actual === expected && actual.isEqualNode(expected)
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Test factory functions for common test scenarios
|
|
93
|
-
*/
|
|
94
|
-
export const testFactory = {
|
|
95
|
-
/**
|
|
96
|
-
* Create a test suite for a custom element
|
|
97
|
-
*/
|
|
98
|
-
createElementTestSuite(elementName: string, importPath: string) {
|
|
99
|
-
return {
|
|
100
|
-
async setup() {
|
|
101
|
-
await import(importPath)
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
async createElement(attributes: Record<string, string> = {}, content = '') {
|
|
105
|
-
const attrs = Object.entries(attributes)
|
|
106
|
-
.map(([key, value]) => `${key}="${value}"`)
|
|
107
|
-
.join(' ')
|
|
108
|
-
|
|
109
|
-
const element = document.createElement('div')
|
|
110
|
-
element.innerHTML = `<${elementName} ${attrs}>${content}</${elementName}>`
|
|
111
|
-
document.body.appendChild(element)
|
|
112
|
-
|
|
113
|
-
return element.firstElementChild as HTMLElement
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
cleanup() {
|
|
117
|
-
document.body.innerHTML = ''
|
|
118
|
-
},
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Create a test data factory
|
|
124
|
-
*/
|
|
125
|
-
createDataFactory<T>(defaults: T) {
|
|
126
|
-
return (overrides: Partial<T> = {}): T => ({
|
|
127
|
-
...defaults,
|
|
128
|
-
...overrides,
|
|
129
|
-
})
|
|
130
|
-
},
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Async test helpers
|
|
135
|
-
*/
|
|
136
|
-
export const asyncHelpers = {
|
|
137
|
-
/**
|
|
138
|
-
* Wait for multiple conditions to be true
|
|
139
|
-
*/
|
|
140
|
-
async waitForAll(conditions: (() => boolean)[], timeout = 5000): Promise<void> {
|
|
141
|
-
const promises = conditions.map((condition) => window.testUtils.waitForCondition(condition, timeout))
|
|
142
|
-
await Promise.all(promises)
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Wait for any of multiple conditions to be true
|
|
147
|
-
*/
|
|
148
|
-
async waitForAny(conditions: (() => boolean)[], timeout = 5000): Promise<number> {
|
|
149
|
-
return new Promise((resolve, reject) => {
|
|
150
|
-
const startTime = Date.now()
|
|
151
|
-
let resolved = false
|
|
152
|
-
|
|
153
|
-
function checkConditions() {
|
|
154
|
-
if (resolved) return
|
|
155
|
-
|
|
156
|
-
for (let i = 0; i < conditions.length; i++) {
|
|
157
|
-
try {
|
|
158
|
-
if (conditions[i]()) {
|
|
159
|
-
resolved = true
|
|
160
|
-
resolve(i)
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
} catch {
|
|
164
|
-
// Continue checking other conditions
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (Date.now() - startTime > timeout) {
|
|
169
|
-
resolved = true
|
|
170
|
-
reject(new Error(`None of the conditions met within ${timeout}ms`))
|
|
171
|
-
return
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
setTimeout(checkConditions, 50)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
checkConditions()
|
|
178
|
-
})
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Retry an async operation with exponential backoff
|
|
183
|
-
*/
|
|
184
|
-
async retry<T>(operation: () => Promise<T>, maxAttempts = 3, baseDelay = 100): Promise<T> {
|
|
185
|
-
let lastError: Error
|
|
186
|
-
|
|
187
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
188
|
-
try {
|
|
189
|
-
return await operation()
|
|
190
|
-
} catch (error) {
|
|
191
|
-
lastError = error as Error
|
|
192
|
-
|
|
193
|
-
if (attempt === maxAttempts) {
|
|
194
|
-
throw lastError
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const delay = baseDelay * Math.pow(2, attempt - 1)
|
|
198
|
-
await new Promise((resolve) => setTimeout(resolve, delay))
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
throw lastError!
|
|
203
|
-
},
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Performance testing utilities
|
|
208
|
-
*/
|
|
209
|
-
export const performanceHelpers = {
|
|
210
|
-
/**
|
|
211
|
-
* Measure the execution time of a function
|
|
212
|
-
*/
|
|
213
|
-
async measureTime<T>(fn: () => Promise<T> | T): Promise<{ result: T; duration: number }> {
|
|
214
|
-
const start = performance.now()
|
|
215
|
-
const result = await fn()
|
|
216
|
-
const duration = performance.now() - start
|
|
217
|
-
|
|
218
|
-
return { result, duration }
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Assert that an operation completes within a time limit
|
|
223
|
-
*/
|
|
224
|
-
async expectWithinTime<T>(operation: () => Promise<T> | T, maxDuration: number, message?: string): Promise<T> {
|
|
225
|
-
const { result, duration } = await this.measureTime(operation)
|
|
226
|
-
|
|
227
|
-
if (duration > maxDuration) {
|
|
228
|
-
const errorMessage = message || `Operation took ${duration.toFixed(2)}ms, expected < ${maxDuration}ms`
|
|
229
|
-
throw new Error(errorMessage)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return result
|
|
233
|
-
},
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Export all utilities
|
|
237
|
-
export { expect }
|
|
238
|
-
export default {
|
|
239
|
-
customMatchers,
|
|
240
|
-
testFactory,
|
|
241
|
-
asyncHelpers,
|
|
242
|
-
performanceHelpers,
|
|
243
|
-
}
|
package/test/helpers/UiMock.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { nextFrame } from '@open-wc/testing'
|
|
2
|
-
import { sendMouse } from '@web/test-runner-commands'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents a 2D point with x and y coordinates.
|
|
6
|
-
*/
|
|
7
|
-
export interface Point {
|
|
8
|
-
/** The x-coordinate of the point. */
|
|
9
|
-
x: number
|
|
10
|
-
/** The y-coordinate of the point. */
|
|
11
|
-
y: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A utility class for mocking user interface interactions in tests.
|
|
16
|
-
* It provides static methods to simulate keyboard and mouse events.
|
|
17
|
-
* This class is designed as a collection of static helpers, hence it has no constructor or instances.
|
|
18
|
-
*/
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
20
|
-
export class UiMock {
|
|
21
|
-
/**
|
|
22
|
-
* Dispatches a 'keydown' event on a given element.
|
|
23
|
-
*
|
|
24
|
-
* @param element The target element for the event.
|
|
25
|
-
* @param code The `code` value for the KeyboardEvent (e.g., 'Enter', 'KeyA').
|
|
26
|
-
* @param opts Additional options to pass to the KeyboardEvent constructor.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* UiMock.keyDown(document.body, 'Enter');
|
|
30
|
-
* UiMock.keyDown(myInputElement, 'KeyA', { ctrlKey: true });
|
|
31
|
-
*/
|
|
32
|
-
static keyDown(element: EventTarget, code: string, opts: KeyboardEventInit = {}): void {
|
|
33
|
-
const defaults: KeyboardEventInit = {
|
|
34
|
-
bubbles: true,
|
|
35
|
-
cancelable: true,
|
|
36
|
-
composed: true,
|
|
37
|
-
}
|
|
38
|
-
const options = { ...defaults, ...opts, ...{ code } }
|
|
39
|
-
const down = new KeyboardEvent('keydown', options)
|
|
40
|
-
element.dispatchEvent(down)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Dispatches a 'keyup' event on a given element.
|
|
45
|
-
*
|
|
46
|
-
* @param element The target element for the event.
|
|
47
|
-
* @param code The `code` value for the KeyboardEvent (e.g., 'Escape', 'KeyB').
|
|
48
|
-
* @param opts Additional options to pass to the KeyboardEvent constructor.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* UiMock.keyUp(document.body, 'Escape');
|
|
52
|
-
*/
|
|
53
|
-
static keyUp(element: EventTarget, code: string, opts: KeyboardEventInit = {}): void {
|
|
54
|
-
const defaults: KeyboardEventInit = {
|
|
55
|
-
bubbles: true,
|
|
56
|
-
cancelable: true,
|
|
57
|
-
composed: true,
|
|
58
|
-
}
|
|
59
|
-
const options = { ...defaults, ...opts, ...{ code } }
|
|
60
|
-
const down = new KeyboardEvent('keyup', options)
|
|
61
|
-
element.dispatchEvent(down)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Simulates a full key press by dispatching 'keydown' and 'keyup' events sequentially.
|
|
66
|
-
* It waits for the next animation frame between the two events.
|
|
67
|
-
*
|
|
68
|
-
* @param element The target element for the event.
|
|
69
|
-
* @param code The `code` value for the KeyboardEvent.
|
|
70
|
-
* @param opts Additional options to pass to the KeyboardEvent constructor.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* await UiMock.keyPress(myButton, 'Space');
|
|
74
|
-
*/
|
|
75
|
-
static async keyPress(element: EventTarget, code: string, opts?: KeyboardEventInit): Promise<void> {
|
|
76
|
-
this.keyDown(element, code, opts)
|
|
77
|
-
await nextFrame()
|
|
78
|
-
this.keyUp(element, code, opts)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Calculates the coordinates of the center of a given element.
|
|
83
|
-
*
|
|
84
|
-
* Note: This method mixes coordinate systems. `getBoundingClientRect` is viewport-relative,
|
|
85
|
-
* while `window.scrollY` is for document scrolling and `window.screenX` is for the
|
|
86
|
-
* screen position of the browser window. For use with `@web/test-runner-commands`'s `sendMouse`,
|
|
87
|
-
* which expects viewport-relative coordinates, the calculation should likely be:
|
|
88
|
-
* `x: Math.floor(x + width / 2)` and `y: Math.floor(y + height / 2)`.
|
|
89
|
-
*
|
|
90
|
-
* @param element The element to find the center of.
|
|
91
|
-
* @returns A `Point` object with the x and y coordinates of the element's center.
|
|
92
|
-
*/
|
|
93
|
-
static getMiddleOfElement(element: Element): Point {
|
|
94
|
-
const { x, y, width, height } = element.getBoundingClientRect()
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
x: Math.floor(x + window.screenX + width / 2),
|
|
98
|
-
y: Math.floor(y + window.scrollY + height / 2),
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Moves the mouse from a starting point to an ending point in a series of steps.
|
|
104
|
-
* This uses the `@web/test-runner-commands` `sendMouse` API, which means
|
|
105
|
-
* the mouse will actually move in the browser running the tests.
|
|
106
|
-
*
|
|
107
|
-
* @param from The starting {x, y} coordinates.
|
|
108
|
-
* @param to The ending {x, y} coordinates.
|
|
109
|
-
* @param steps The number of intermediate steps to take during the move. Defaults to 10.
|
|
110
|
-
*/
|
|
111
|
-
static async moveMouse(from: Point, to: Point, steps = 10): Promise<void> {
|
|
112
|
-
const dx = to.x - from.x
|
|
113
|
-
const dy = to.y - from.y
|
|
114
|
-
const ix = Math.round(dx / steps)
|
|
115
|
-
const iy = Math.round(dy / steps)
|
|
116
|
-
let currentX = from.x
|
|
117
|
-
let currentY = from.y
|
|
118
|
-
|
|
119
|
-
await sendMouse({ type: 'move', position: [from.x, from.y] })
|
|
120
|
-
// await executeServerCommand('take-screenshot', { name: 'move-start' });
|
|
121
|
-
for (let i = 0; i < steps; i++) {
|
|
122
|
-
currentX += ix
|
|
123
|
-
currentY += iy
|
|
124
|
-
await nextFrame()
|
|
125
|
-
await sendMouse({ type: 'move', position: [currentX, currentY] })
|
|
126
|
-
// await executeServerCommand('take-screenshot', { name: `pos${i}` });
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// just making sure that we are not off
|
|
130
|
-
await sendMouse({ type: 'move', position: [to.x, to.y] })
|
|
131
|
-
// await executeServerCommand('take-screenshot', { name: `move-end` });
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Performs a drag-and-drop operation from a source element to a target element.
|
|
136
|
-
* It simulates moving to the source, pressing the mouse down, moving to the target,
|
|
137
|
-
* and releasing the mouse.
|
|
138
|
-
*
|
|
139
|
-
* @param source The HTMLElement to drag.
|
|
140
|
-
* @param target The HTMLElement to drop onto.
|
|
141
|
-
* @param steps The number of mouse moves to simulate during the drag. Defaults to 10.
|
|
142
|
-
*/
|
|
143
|
-
static async dragAndDrop(source: HTMLElement, target: HTMLElement, steps = 10): Promise<void> {
|
|
144
|
-
const from = UiMock.getMiddleOfElement(source)
|
|
145
|
-
const to = UiMock.getMiddleOfElement(target)
|
|
146
|
-
|
|
147
|
-
await sendMouse({ type: 'move', position: [from.x, from.y] })
|
|
148
|
-
await sendMouse({ type: 'down' })
|
|
149
|
-
// await executeServerCommand('take-screenshot', { name: `after-down` });
|
|
150
|
-
await nextFrame()
|
|
151
|
-
await UiMock.moveMouse(from, to, steps)
|
|
152
|
-
await sendMouse({ type: 'up' })
|
|
153
|
-
// await executeServerCommand('take-screenshot', { name: `after-up` });
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Creates a `DragEvent` for simulating file drags (e.g., for a file drop zone).
|
|
158
|
-
*
|
|
159
|
-
* @param type The type of the drag event (e.g., 'dragenter', 'dragover', 'drop').
|
|
160
|
-
* @param opts Options, including an optional `File` object to include in the event.
|
|
161
|
-
* If no file is provided, a default 'test.txt' file is created.
|
|
162
|
-
* @returns A new `DragEvent` instance.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* const myFile = new File(['(⌐□_□)'], 'chucknorris.png', { type: 'image/png' });
|
|
166
|
-
* const dropEvent = UiMock.getFileDragEvent('drop', { file: myFile });
|
|
167
|
-
* dropZone.dispatchEvent(dropEvent);
|
|
168
|
-
*/
|
|
169
|
-
static getFileDragEvent(type: string, opts: { file?: File } = {}): DragEvent {
|
|
170
|
-
let file: File
|
|
171
|
-
if (opts.file) {
|
|
172
|
-
file = opts.file
|
|
173
|
-
} else {
|
|
174
|
-
file = new File(['test'], 'test.txt', { type: 'text/plain' })
|
|
175
|
-
}
|
|
176
|
-
const dt = new DataTransfer()
|
|
177
|
-
dt.items.add(file)
|
|
178
|
-
return new DragEvent(type, {
|
|
179
|
-
dataTransfer: dt,
|
|
180
|
-
cancelable: true,
|
|
181
|
-
composed: true,
|
|
182
|
-
bubbles: true,
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
}
|
package/test/lib/Dom.test.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { assert } from '@open-wc/testing'
|
|
2
|
-
import { findElementInShadowRoots } from '../../src/lib/Dom.js'
|
|
3
|
-
|
|
4
|
-
describe('lib', () => {
|
|
5
|
-
describe('Dom', () => {
|
|
6
|
-
describe('findElementInShadowRoots', () => {
|
|
7
|
-
let container: HTMLDivElement
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
container = document.createElement('div')
|
|
11
|
-
container.id = 'test-container'
|
|
12
|
-
document.body.appendChild(container)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
document.body.removeChild(container)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('finds element in document root', () => {
|
|
20
|
-
const element = document.createElement('div')
|
|
21
|
-
element.id = 'test-element'
|
|
22
|
-
container.appendChild(element)
|
|
23
|
-
|
|
24
|
-
const fromElement = document.createElement('div')
|
|
25
|
-
container.appendChild(fromElement)
|
|
26
|
-
|
|
27
|
-
const result = findElementInShadowRoots('test-element', fromElement)
|
|
28
|
-
assert.equal(result, element)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('returns null when element is not found', () => {
|
|
32
|
-
const fromElement = document.createElement('div')
|
|
33
|
-
container.appendChild(fromElement)
|
|
34
|
-
|
|
35
|
-
const result = findElementInShadowRoots('non-existent', fromElement)
|
|
36
|
-
assert.isNull(result)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('finds element in parent shadow root', () => {
|
|
40
|
-
// Create a custom element with shadow root
|
|
41
|
-
const shadowHost = document.createElement('div')
|
|
42
|
-
const shadowRoot = shadowHost.attachShadow({ mode: 'open' })
|
|
43
|
-
// Add target element to shadow root
|
|
44
|
-
const targetElement = document.createElement('div')
|
|
45
|
-
targetElement.id = 'shadow-element'
|
|
46
|
-
shadowRoot.appendChild(targetElement)
|
|
47
|
-
|
|
48
|
-
// Add shadow host to container
|
|
49
|
-
container.appendChild(shadowHost)
|
|
50
|
-
|
|
51
|
-
// Create a child element inside the shadow root to search from
|
|
52
|
-
const fromElement = document.createElement('div')
|
|
53
|
-
shadowRoot.appendChild(fromElement)
|
|
54
|
-
const result = findElementInShadowRoots('shadow-element', fromElement)
|
|
55
|
-
assert.ok(result)
|
|
56
|
-
assert.equal(result.id, 'shadow-element')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('finds element in nested shadow roots', () => {
|
|
60
|
-
// Create outer shadow host
|
|
61
|
-
const outerShadowHost = document.createElement('div')
|
|
62
|
-
outerShadowHost.id = 'outer-shadow-host'
|
|
63
|
-
const outerShadowRoot = outerShadowHost.attachShadow({ mode: 'open' })
|
|
64
|
-
|
|
65
|
-
// Create inner shadow host inside outer shadow root
|
|
66
|
-
const innerShadowHost = document.createElement('div')
|
|
67
|
-
innerShadowHost.id = 'inner-shadow-host'
|
|
68
|
-
const innerShadowRoot = innerShadowHost.attachShadow({ mode: 'open' })
|
|
69
|
-
outerShadowRoot.appendChild(innerShadowHost)
|
|
70
|
-
|
|
71
|
-
// Add target element to outer shadow root
|
|
72
|
-
const targetElement = document.createElement('div')
|
|
73
|
-
targetElement.id = 'nested-element'
|
|
74
|
-
outerShadowRoot.appendChild(targetElement)
|
|
75
|
-
|
|
76
|
-
// Add container to document
|
|
77
|
-
container.appendChild(outerShadowHost)
|
|
78
|
-
|
|
79
|
-
// Search from element in inner shadow root
|
|
80
|
-
const fromElement = document.createElement('div')
|
|
81
|
-
fromElement.id = 'search-from'
|
|
82
|
-
innerShadowRoot.appendChild(fromElement)
|
|
83
|
-
|
|
84
|
-
const result = findElementInShadowRoots('nested-element', fromElement)
|
|
85
|
-
assert.equal(result, targetElement)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('searches through multiple shadow root levels', () => {
|
|
89
|
-
// Create a deeply nested shadow structure
|
|
90
|
-
const level1Host = document.createElement('div')
|
|
91
|
-
const level1Shadow = level1Host.attachShadow({ mode: 'open' })
|
|
92
|
-
|
|
93
|
-
const level2Host = document.createElement('div')
|
|
94
|
-
const level2Shadow = level2Host.attachShadow({ mode: 'open' })
|
|
95
|
-
level1Shadow.appendChild(level2Host)
|
|
96
|
-
|
|
97
|
-
const level3Host = document.createElement('div')
|
|
98
|
-
const level3Shadow = level3Host.attachShadow({ mode: 'open' })
|
|
99
|
-
level2Shadow.appendChild(level3Host)
|
|
100
|
-
|
|
101
|
-
// Add target element at level 1
|
|
102
|
-
const targetElement = document.createElement('div')
|
|
103
|
-
targetElement.id = 'deep-element'
|
|
104
|
-
level1Shadow.appendChild(targetElement)
|
|
105
|
-
|
|
106
|
-
container.appendChild(level1Host)
|
|
107
|
-
|
|
108
|
-
// Search from deepest level
|
|
109
|
-
const fromElement = document.createElement('div')
|
|
110
|
-
level3Shadow.appendChild(fromElement)
|
|
111
|
-
|
|
112
|
-
const result = findElementInShadowRoots('deep-element', fromElement)
|
|
113
|
-
assert.equal(result, targetElement)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('prefers document element over shadow root element', () => {
|
|
117
|
-
// Create element in document
|
|
118
|
-
const documentElement = document.createElement('div')
|
|
119
|
-
documentElement.id = 'duplicate-id'
|
|
120
|
-
documentElement.textContent = 'document'
|
|
121
|
-
container.appendChild(documentElement)
|
|
122
|
-
|
|
123
|
-
// Create shadow host with element with same ID
|
|
124
|
-
const shadowHost = document.createElement('div')
|
|
125
|
-
const shadowRoot = shadowHost.attachShadow({ mode: 'open' })
|
|
126
|
-
|
|
127
|
-
const shadowElement = document.createElement('div')
|
|
128
|
-
shadowElement.id = 'duplicate-id'
|
|
129
|
-
shadowElement.textContent = 'shadow'
|
|
130
|
-
shadowRoot.appendChild(shadowElement)
|
|
131
|
-
|
|
132
|
-
container.appendChild(shadowHost)
|
|
133
|
-
|
|
134
|
-
const fromElement = document.createElement('div')
|
|
135
|
-
shadowRoot.appendChild(fromElement)
|
|
136
|
-
|
|
137
|
-
const result = findElementInShadowRoots('duplicate-id', fromElement)
|
|
138
|
-
assert.equal(result, documentElement)
|
|
139
|
-
assert.isNotNull(result)
|
|
140
|
-
assert.equal(result.textContent, 'document')
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('handles elements without parent', () => {
|
|
144
|
-
const isolatedElement = document.createElement('div')
|
|
145
|
-
|
|
146
|
-
const result = findElementInShadowRoots('test-id', isolatedElement)
|
|
147
|
-
assert.isNull(result)
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('handles shadow root host traversal', () => {
|
|
151
|
-
// Create a shadow host
|
|
152
|
-
const shadowHost = document.createElement('div')
|
|
153
|
-
const shadowRoot = shadowHost.attachShadow({ mode: 'open' })
|
|
154
|
-
container.appendChild(shadowHost)
|
|
155
|
-
|
|
156
|
-
// Add target element to container (outside shadow)
|
|
157
|
-
const targetElement = document.createElement('div')
|
|
158
|
-
targetElement.id = 'outside-shadow'
|
|
159
|
-
container.appendChild(targetElement)
|
|
160
|
-
|
|
161
|
-
// Search from inside shadow root
|
|
162
|
-
const fromElement = document.createElement('div')
|
|
163
|
-
shadowRoot.appendChild(fromElement)
|
|
164
|
-
|
|
165
|
-
const result = findElementInShadowRoots('outside-shadow', fromElement)
|
|
166
|
-
assert.equal(result, targetElement)
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
it('handles elements in current shadow root', () => {
|
|
170
|
-
const shadowHost = document.createElement('div')
|
|
171
|
-
const shadowRoot = shadowHost.attachShadow({ mode: 'open' })
|
|
172
|
-
container.appendChild(shadowHost)
|
|
173
|
-
|
|
174
|
-
// Add target element to same shadow root
|
|
175
|
-
const targetElement = document.createElement('div')
|
|
176
|
-
targetElement.id = 'same-shadow'
|
|
177
|
-
shadowRoot.appendChild(targetElement)
|
|
178
|
-
|
|
179
|
-
// Add search element to same shadow root
|
|
180
|
-
const fromElement = document.createElement('div')
|
|
181
|
-
shadowRoot.appendChild(fromElement)
|
|
182
|
-
|
|
183
|
-
const result = findElementInShadowRoots('same-shadow', fromElement)
|
|
184
|
-
assert.equal(result, targetElement)
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('handles complex shadow DOM structure with mixed content', () => {
|
|
188
|
-
// Create complex structure: document -> shadow1 -> regular div -> shadow2
|
|
189
|
-
const shadow1Host = document.createElement('div')
|
|
190
|
-
const shadow1Root = shadow1Host.attachShadow({ mode: 'open' })
|
|
191
|
-
container.appendChild(shadow1Host)
|
|
192
|
-
|
|
193
|
-
const regularDiv = document.createElement('div')
|
|
194
|
-
shadow1Root.appendChild(regularDiv)
|
|
195
|
-
|
|
196
|
-
const shadow2Host = document.createElement('div')
|
|
197
|
-
const shadow2Root = shadow2Host.attachShadow({ mode: 'open' })
|
|
198
|
-
regularDiv.appendChild(shadow2Host)
|
|
199
|
-
|
|
200
|
-
// Add target to shadow1
|
|
201
|
-
const targetElement = document.createElement('div')
|
|
202
|
-
targetElement.id = 'complex-target'
|
|
203
|
-
shadow1Root.appendChild(targetElement)
|
|
204
|
-
|
|
205
|
-
// Search from shadow2
|
|
206
|
-
const fromElement = document.createElement('div')
|
|
207
|
-
shadow2Root.appendChild(fromElement)
|
|
208
|
-
|
|
209
|
-
const result = findElementInShadowRoots('complex-target', fromElement)
|
|
210
|
-
assert.equal(result, targetElement)
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
it('returns null for invalid ID characters', () => {
|
|
214
|
-
const element = document.createElement('div')
|
|
215
|
-
element.id = 'valid-id'
|
|
216
|
-
container.appendChild(element)
|
|
217
|
-
|
|
218
|
-
const fromElement = document.createElement('div')
|
|
219
|
-
container.appendChild(fromElement)
|
|
220
|
-
|
|
221
|
-
// Test with empty string
|
|
222
|
-
const result1 = findElementInShadowRoots('', fromElement)
|
|
223
|
-
assert.isNull(result1)
|
|
224
|
-
|
|
225
|
-
// Test with whitespace
|
|
226
|
-
const result2 = findElementInShadowRoots(' ', fromElement)
|
|
227
|
-
assert.isNull(result2)
|
|
228
|
-
})
|
|
229
|
-
})
|
|
230
|
-
})
|
|
231
|
-
})
|