@api-client/ui 0.5.0 → 0.5.2

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 (35) hide show
  1. package/build/src/elements/highlight/MarkedHighlight.d.ts.map +1 -1
  2. package/build/src/elements/highlight/MarkedHighlight.js +2 -1
  3. package/build/src/elements/highlight/MarkedHighlight.js.map +1 -1
  4. package/build/src/md/button/internals/base.js +1 -1
  5. package/build/src/md/button/internals/base.js.map +1 -1
  6. package/build/src/md/dialog/internals/Dialog.d.ts +18 -0
  7. package/build/src/md/dialog/internals/Dialog.d.ts.map +1 -1
  8. package/build/src/md/dialog/internals/Dialog.js +60 -2
  9. package/build/src/md/dialog/internals/Dialog.js.map +1 -1
  10. package/build/src/md/input/Input.d.ts +4 -4
  11. package/build/src/md/input/Input.d.ts.map +1 -1
  12. package/build/src/md/input/Input.js +3 -11
  13. package/build/src/md/input/Input.js.map +1 -1
  14. package/build/src/md/text-area/internals/TextAreaElement.d.ts.map +1 -1
  15. package/build/src/md/text-area/internals/TextAreaElement.js +1 -2
  16. package/build/src/md/text-area/internals/TextAreaElement.js.map +1 -1
  17. package/build/src/md/text-field/internals/TextField.d.ts.map +1 -1
  18. package/build/src/md/text-field/internals/TextField.js +1 -2
  19. package/build/src/md/text-field/internals/TextField.js.map +1 -1
  20. package/demo/md/dialog/dialog.ts +135 -1
  21. package/package.json +2 -2
  22. package/src/elements/highlight/MarkedHighlight.ts +2 -1
  23. package/src/md/button/internals/base.ts +1 -1
  24. package/src/md/dialog/internals/Dialog.ts +54 -1
  25. package/src/md/input/Input.ts +4 -4
  26. package/src/md/text-area/internals/TextAreaElement.ts +1 -2
  27. package/src/md/text-field/internals/TextField.ts +4 -5
  28. package/test/README.md +372 -0
  29. package/test/dom-assertions.test.ts +182 -0
  30. package/test/helpers/TestUtils.ts +243 -0
  31. package/test/helpers/UiMock.ts +83 -13
  32. package/test/md/dialog/UiDialog.test.ts +169 -0
  33. package/test/setup.test.ts +217 -0
  34. package/test/setup.ts +117 -0
  35. package/.github/workflows/test.yml +0 -42
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Example test file demonstrating the test setup and utilities.
3
+ * This shows how to use the test infrastructure for UI components.
4
+ */
5
+
6
+ import { assert } from '@open-wc/testing'
7
+ import { testFactory, asyncHelpers, customMatchers } from './helpers/TestUtils.js'
8
+ import { UiMock } from './helpers/UiMock.js'
9
+
10
+ // Import the setup to ensure it runs
11
+ import './setup.js'
12
+
13
+ describe('Test Setup Example', () => {
14
+ describe('Basic Test Infrastructure', () => {
15
+ it('should have test utilities available globally', () => {
16
+ assert.exists(window.testUtils)
17
+ assert.isFunction(window.testUtils.waitForElement)
18
+ assert.isFunction(window.testUtils.waitForCondition)
19
+ })
20
+
21
+ it('should have custom matchers available', () => {
22
+ assert.exists(customMatchers.toHaveClasses)
23
+ assert.exists(customMatchers.toBeVisible)
24
+ assert.exists(customMatchers.toHaveAttribute)
25
+ })
26
+
27
+ it('should have async helpers available', () => {
28
+ assert.exists(asyncHelpers.waitForAll)
29
+ assert.exists(asyncHelpers.waitForAny)
30
+ assert.exists(asyncHelpers.retry)
31
+ })
32
+
33
+ it('should have UiMock utilities available', () => {
34
+ assert.exists(UiMock.keyDown)
35
+ assert.exists(UiMock.keyUp)
36
+ assert.exists(UiMock.keyPress)
37
+ assert.exists(UiMock.getMiddleOfElement)
38
+ assert.exists(UiMock.moveMouse)
39
+ assert.exists(UiMock.dragAndDrop)
40
+ assert.exists(UiMock.getFileDragEvent)
41
+ })
42
+ })
43
+
44
+ describe('Element Testing Example', () => {
45
+ let element: HTMLElement
46
+
47
+ beforeEach(() => {
48
+ // Clean setup is handled by global setup
49
+ element = document.createElement('div')
50
+ element.id = 'test-element'
51
+ element.className = 'test-class'
52
+ element.setAttribute('data-test', 'value')
53
+ document.body.appendChild(element)
54
+ })
55
+
56
+ afterEach(() => {
57
+ // Cleanup is handled by global setup
58
+ })
59
+
60
+ it('should test element classes using custom matcher', () => {
61
+ const result = customMatchers.toHaveClasses(element, 'test-class')
62
+ assert.isTrue(result.pass)
63
+ })
64
+
65
+ it('should test element visibility using custom matcher', () => {
66
+ const result = customMatchers.toBeVisible(element)
67
+ assert.isTrue(result.pass)
68
+ })
69
+
70
+ it('should test element attributes using custom matcher', () => {
71
+ const result = customMatchers.toHaveAttribute(element, 'data-test', 'value')
72
+ assert.isTrue(result.pass)
73
+ })
74
+
75
+ it('should wait for element to appear', async () => {
76
+ // Remove element temporarily
77
+ element.remove()
78
+
79
+ // Add it back after a delay
80
+ setTimeout(() => {
81
+ document.body.appendChild(element)
82
+ }, 10)
83
+
84
+ // Wait for it to appear
85
+ const foundElement = await window.testUtils.waitForElement('#test-element')
86
+ assert.dom.equal(foundElement, element)
87
+ })
88
+
89
+ it('should wait for condition to be true', async () => {
90
+ let conditionMet = false
91
+
92
+ // Set condition to true after delay
93
+ setTimeout(() => {
94
+ conditionMet = true
95
+ }, 100)
96
+
97
+ // Wait for condition
98
+ await window.testUtils.waitForCondition(() => conditionMet)
99
+ assert.isTrue(conditionMet)
100
+ })
101
+ })
102
+
103
+ describe('Async Helpers Example', () => {
104
+ it('should wait for all conditions', async () => {
105
+ let condition1 = false
106
+ let condition2 = false
107
+
108
+ setTimeout(() => {
109
+ condition1 = true
110
+ }, 50)
111
+ setTimeout(() => {
112
+ condition2 = true
113
+ }, 100)
114
+
115
+ await asyncHelpers.waitForAll([() => condition1, () => condition2])
116
+
117
+ assert.isTrue(condition1)
118
+ assert.isTrue(condition2)
119
+ })
120
+
121
+ it('should wait for any condition', async () => {
122
+ let condition1 = false
123
+ let condition2 = false
124
+
125
+ setTimeout(() => {
126
+ condition1 = true
127
+ }, 50)
128
+ setTimeout(() => {
129
+ condition2 = true
130
+ }, 100)
131
+
132
+ const index = await asyncHelpers.waitForAny([() => condition1, () => condition2])
133
+
134
+ assert.equal(index, 0) // First condition should be met first
135
+ assert.isTrue(condition1)
136
+ })
137
+
138
+ it('should retry failed operations', async () => {
139
+ let attempts = 0
140
+
141
+ const operation = async () => {
142
+ attempts++
143
+ if (attempts < 3) {
144
+ throw new Error('Not ready yet')
145
+ }
146
+ return 'success'
147
+ }
148
+
149
+ const result = await asyncHelpers.retry(operation, 5, 10)
150
+ assert.equal(result, 'success')
151
+ assert.equal(attempts, 3)
152
+ })
153
+ })
154
+
155
+ describe('Test Factory Example', () => {
156
+ it('should create data factory', () => {
157
+ const userFactory = testFactory.createDataFactory({
158
+ id: 1,
159
+ name: 'Test User',
160
+ email: 'test@example.com',
161
+ })
162
+
163
+ const user1 = userFactory()
164
+ assert.equal(user1.name, 'Test User')
165
+
166
+ const user2 = userFactory({ name: 'Custom User' })
167
+ assert.equal(user2.name, 'Custom User')
168
+ assert.equal(user2.email, 'test@example.com') // Keeps default
169
+ })
170
+ })
171
+
172
+ describe('UI Interaction Example', () => {
173
+ let button: HTMLButtonElement
174
+
175
+ beforeEach(() => {
176
+ button = document.createElement('button')
177
+ button.textContent = 'Click me'
178
+ button.style.width = '100px'
179
+ button.style.height = '40px'
180
+ button.style.position = 'absolute'
181
+ button.style.top = '100px'
182
+ button.style.left = '100px'
183
+ document.body.appendChild(button)
184
+ })
185
+
186
+ it('should simulate keyboard interaction', async () => {
187
+ let keyPressed = false
188
+
189
+ button.addEventListener('keydown', (e) => {
190
+ if (e.code === 'Enter') {
191
+ keyPressed = true
192
+ }
193
+ })
194
+
195
+ await UiMock.keyPress(button, 'Enter')
196
+ assert.isTrue(keyPressed)
197
+ })
198
+
199
+ it('should get element center position', () => {
200
+ const center = UiMock.getMiddleOfElement(button)
201
+ assert.isNumber(center.x)
202
+ assert.isNumber(center.y)
203
+ assert.isAbove(center.x, 0)
204
+ assert.isAbove(center.y, 0)
205
+ })
206
+
207
+ it('should create file drag event', () => {
208
+ const file = new File(['test content'], 'test.txt', { type: 'text/plain' })
209
+ const dragEvent = UiMock.getFileDragEvent('drop', { file })
210
+
211
+ assert.equal(dragEvent.type, 'drop')
212
+ assert.exists(dragEvent.dataTransfer)
213
+ assert.equal(dragEvent.dataTransfer!.files.length, 1)
214
+ assert.equal(dragEvent.dataTransfer!.files[0].name, 'test.txt')
215
+ })
216
+ })
217
+ })
package/test/setup.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Test setup configuration for the UI component library.
3
+ * This file is imported by all test files to ensure consistent test environment.
4
+ */
5
+
6
+ // // Global test setup
7
+ // before(() => {
8
+ // // Set up global test configuration
9
+ // // eslint-disable-next-line no-console
10
+ // console.log('Setting up test environment...')
11
+ // })
12
+
13
+ // beforeEach(() => {
14
+ // // Clean up DOM before each test
15
+ // document.body.innerHTML = ''
16
+
17
+ // // Reset any global state
18
+ // if (window.localStorage) {
19
+ // window.localStorage.clear()
20
+ // }
21
+ // if (window.sessionStorage) {
22
+ // window.sessionStorage.clear()
23
+ // }
24
+ // })
25
+
26
+ afterEach(() => {
27
+ // Clean up after each test
28
+ // document.body.innerHTML = ''
29
+
30
+ // Clear any pending timers
31
+ const highestTimeoutId = window.setTimeout(() => {}, 0)
32
+ for (let i = 0; i < highestTimeoutId; i++) {
33
+ window.clearTimeout(i)
34
+ }
35
+
36
+ // Clear any pending intervals
37
+ const highestIntervalId = window.setInterval(() => {}, 9999)
38
+ for (let i = 0; i < highestIntervalId; i++) {
39
+ window.clearInterval(i)
40
+ }
41
+ })
42
+
43
+ // after(() => {
44
+ // // eslint-disable-next-line no-console
45
+ // console.log('Test environment cleanup complete.')
46
+ // })
47
+
48
+ // Global test utilities
49
+ declare global {
50
+ interface Window {
51
+ testUtils: {
52
+ waitForElement: (selector: string, timeout?: number) => Promise<Element>
53
+ waitForCondition: (condition: () => boolean, timeout?: number) => Promise<void>
54
+ }
55
+ }
56
+ }
57
+
58
+ // Add test utilities to global scope
59
+ window.testUtils = {
60
+ /**
61
+ * Wait for an element to appear in the DOM
62
+ */
63
+ async waitForElement(selector: string, timeout = 5000): Promise<Element> {
64
+ return new Promise((resolve, reject) => {
65
+ const startTime = Date.now()
66
+
67
+ function checkElement() {
68
+ const element = document.querySelector(selector)
69
+ if (element) {
70
+ resolve(element)
71
+ return
72
+ }
73
+
74
+ if (Date.now() - startTime > timeout) {
75
+ reject(new Error(`Element with selector "${selector}" not found within ${timeout}ms`))
76
+ return
77
+ }
78
+
79
+ setTimeout(checkElement, 50)
80
+ }
81
+
82
+ checkElement()
83
+ })
84
+ },
85
+
86
+ /**
87
+ * Wait for a condition to be true
88
+ */
89
+ async waitForCondition(condition: () => boolean, timeout = 5000): Promise<void> {
90
+ return new Promise((resolve, reject) => {
91
+ const startTime = Date.now()
92
+
93
+ function checkCondition() {
94
+ try {
95
+ if (condition()) {
96
+ resolve()
97
+ return
98
+ }
99
+ } catch {
100
+ // Condition threw an error, continue waiting
101
+ }
102
+
103
+ if (Date.now() - startTime > timeout) {
104
+ reject(new Error(`Condition not met within ${timeout}ms`))
105
+ return
106
+ }
107
+
108
+ setTimeout(checkCondition, 50)
109
+ }
110
+
111
+ checkCondition()
112
+ })
113
+ },
114
+ }
115
+
116
+ // Export setup for explicit imports
117
+ export {}
@@ -1,42 +0,0 @@
1
- name: Test
2
-
3
- on:
4
- pull_request:
5
- branches:
6
- - main
7
- push:
8
- branches:
9
- - main
10
-
11
- env:
12
- FORCE_COLOR: 1
13
-
14
- jobs:
15
- test:
16
- name: Test
17
- runs-on: ubuntu-latest
18
- steps:
19
- - name: Checkout code
20
- uses: actions/checkout@v4
21
- with:
22
- fetch-depth: 0
23
-
24
- - name: Setup Node.js
25
- uses: actions/setup-node@v4
26
- with:
27
- node-version: 24
28
- cache: 'npm'
29
-
30
- - uses: google/wireit@setup-github-actions-caching/v2
31
-
32
- - name: Install dependencies
33
- run: npm ci
34
-
35
- - name: Install playwright browsers
36
- run: npx playwright install --with-deps
37
-
38
- - name: Run tests
39
- run: npm test
40
-
41
- - name: Run linting
42
- run: npm run lint