mtrl 0.3.0 → 0.3.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 (140) hide show
  1. package/.env +15 -0
  2. package/CONTRIBUTING.md +8 -8
  3. package/DOCS.md +3 -3
  4. package/README.md +43 -20
  5. package/TESTING.md +128 -18
  6. package/dist/index.js +14865 -0
  7. package/git-user-stats.js +545 -0
  8. package/index.ts +9 -69
  9. package/package.json +10 -3
  10. package/src/components/badge/api.ts +15 -1
  11. package/src/components/badge/badge.ts +43 -4
  12. package/src/components/badge/config.ts +40 -8
  13. package/src/components/badge/index.ts +64 -3
  14. package/src/components/badge/types.ts +175 -33
  15. package/src/components/button/api.ts +63 -1
  16. package/src/components/button/button.ts +39 -3
  17. package/src/components/button/config.ts +21 -4
  18. package/src/components/button/index.ts +26 -1
  19. package/src/components/button/types.ts +7 -1
  20. package/src/components/card/api.ts +78 -9
  21. package/src/components/card/card.ts +58 -3
  22. package/src/components/card/config.ts +41 -11
  23. package/src/components/card/features.ts +39 -12
  24. package/src/components/card/index.ts +84 -19
  25. package/src/components/card/types.ts +218 -29
  26. package/src/components/carousel/carousel.ts +92 -28
  27. package/src/components/carousel/constants.ts +107 -21
  28. package/src/components/carousel/index.ts +31 -13
  29. package/src/components/checkbox/checkbox.ts +83 -16
  30. package/src/components/checkbox/index.ts +43 -1
  31. package/src/components/checkbox/types.ts +219 -32
  32. package/src/components/chips/api.ts +194 -0
  33. package/src/components/{chip → chips/chip}/api.ts +42 -2
  34. package/src/components/chips/chip/chip.ts +131 -0
  35. package/src/components/{chip → chips/chip}/config.ts +3 -3
  36. package/src/components/chips/chip/index.ts +3 -0
  37. package/src/components/chips/chips.md +481 -0
  38. package/src/components/chips/chips.ts +75 -0
  39. package/src/components/chips/config.ts +109 -0
  40. package/src/components/chips/constants.ts +61 -0
  41. package/src/components/chips/features/chip-items.ts +33 -0
  42. package/src/components/chips/features/container.ts +77 -0
  43. package/src/components/chips/features/controller.ts +448 -0
  44. package/src/components/chips/features/index.ts +5 -0
  45. package/src/components/chips/features/label.ts +108 -0
  46. package/src/components/chips/index.ts +11 -0
  47. package/src/components/chips/schema.ts +61 -0
  48. package/src/components/{chip → chips}/types.ts +203 -92
  49. package/src/components/dialog/dialog.ts +99 -16
  50. package/src/components/dialog/index.ts +97 -1
  51. package/src/components/dialog/types.ts +375 -69
  52. package/src/components/divider/config.ts +90 -6
  53. package/src/components/divider/divider.ts +32 -2
  54. package/src/components/divider/features.ts +26 -0
  55. package/src/components/divider/index.ts +30 -0
  56. package/src/components/divider/types.ts +86 -9
  57. package/src/components/extended-fab/api.ts +53 -1
  58. package/src/components/extended-fab/config.ts +29 -1
  59. package/src/components/extended-fab/extended-fab.ts +28 -0
  60. package/src/components/extended-fab/index.ts +36 -0
  61. package/src/components/extended-fab/types.ts +458 -13
  62. package/src/components/fab/api.ts +42 -2
  63. package/src/components/fab/config.ts +29 -1
  64. package/src/components/fab/fab.ts +16 -2
  65. package/src/components/fab/index.ts +35 -0
  66. package/src/components/fab/types.ts +374 -10
  67. package/src/components/list/api.ts +12 -2
  68. package/src/components/list/config.ts +21 -0
  69. package/src/components/list/features.ts +6 -0
  70. package/src/components/list/index.ts +56 -1
  71. package/src/components/list/list-item.ts +46 -2
  72. package/src/components/list/list.ts +73 -2
  73. package/src/components/list/types.ts +172 -0
  74. package/src/components/list/utils.ts +26 -2
  75. package/src/components/menu/api.ts +217 -20
  76. package/src/components/menu/config.ts +27 -0
  77. package/src/components/menu/features/visibility.ts +55 -6
  78. package/src/components/menu/index.ts +64 -0
  79. package/src/components/menu/menu-item.ts +46 -3
  80. package/src/components/menu/menu.ts +77 -1
  81. package/src/components/menu/types.ts +404 -39
  82. package/src/components/navigation/index.ts +4 -1
  83. package/src/components/navigation/types.ts +33 -0
  84. package/src/components/sheet/config.ts +1 -2
  85. package/src/components/sheet/features/gestures.ts +1 -1
  86. package/src/components/sheet/features/position.ts +1 -2
  87. package/src/components/sheet/features/state.ts +1 -1
  88. package/src/components/sheet/index.ts +10 -2
  89. package/src/components/sheet/sheet.ts +1 -2
  90. package/src/components/sheet/types.ts +29 -1
  91. package/src/components/slider/api.ts +1 -1
  92. package/src/components/slider/config.ts +1 -1
  93. package/src/components/slider/features/controller.ts +1 -1
  94. package/src/components/slider/features/handlers.ts +1 -1
  95. package/src/components/slider/features/states.ts +1 -1
  96. package/src/components/slider/index.ts +12 -5
  97. package/src/components/slider/schema.ts +1 -1
  98. package/src/components/slider/types.ts +31 -0
  99. package/src/components/snackbar/index.ts +7 -1
  100. package/src/components/snackbar/types.ts +25 -0
  101. package/src/components/switch/index.ts +5 -1
  102. package/src/components/switch/types.ts +13 -0
  103. package/src/components/tabs/tab-api.ts +1 -1
  104. package/src/components/tabs/types.ts +1 -1
  105. package/src/components/textfield/index.ts +7 -1
  106. package/src/components/textfield/types.ts +36 -0
  107. package/src/components/tooltip/api.ts +6 -2
  108. package/src/components/tooltip/config.ts +9 -28
  109. package/src/components/tooltip/index.ts +10 -1
  110. package/src/components/tooltip/types.ts +38 -3
  111. package/src/index.ts +129 -31
  112. package/src/styles/abstract/_mixins.scss +23 -9
  113. package/src/styles/abstract/_variables.scss +14 -4
  114. package/src/styles/components/_card.scss +1 -1
  115. package/src/styles/components/_chip.scss +323 -113
  116. package/src/styles/components/_tabs.scss +1 -1
  117. package/src/components/checkbox/constants.ts +0 -37
  118. package/src/components/chip/chip-set.ts +0 -225
  119. package/src/components/chip/chip.ts +0 -118
  120. package/src/components/chip/constants.ts +0 -28
  121. package/src/components/chip/index.ts +0 -12
  122. package/src/components/list/constants.ts +0 -116
  123. package/src/components/sheet/constants.ts +0 -20
  124. package/src/components/slider/constants.ts +0 -32
  125. package/src/components/snackbar/constants.ts +0 -26
  126. package/src/components/tooltip/constants.ts +0 -27
  127. package/test/components/button.test.js +0 -170
  128. package/test/components/checkbox.test.js +0 -238
  129. package/test/components/list.test.js +0 -105
  130. package/test/components/menu.test.js +0 -385
  131. package/test/components/navigation.test.js +0 -227
  132. package/test/components/snackbar.test.js +0 -234
  133. package/test/components/switch.test.js +0 -186
  134. package/test/components/textfield.test.js +0 -314
  135. package/test/core/emitter.test.js +0 -141
  136. package/test/core/ripple.test.js +0 -66
  137. package/test/setup.js +0 -371
  138. package/tsconfig.json +0 -22
  139. package/typedoc.json +0 -28
  140. package/typedoc.simple.json +0 -14
@@ -1,170 +0,0 @@
1
- // test/components/button.test.js
2
- import { describe, test, expect, mock } from 'bun:test'
3
- import createButton from '../../src/components/button/button'
4
-
5
- describe('Button Component', () => {
6
- // Enhance querySelector for button tests
7
- const enhanceQuerySelector = (element) => {
8
- const originalQuerySelector = element.querySelector
9
-
10
- element.querySelector = (selector) => {
11
- // Create mock elements for specific selectors
12
- if (selector === '.mtrl-button-text') {
13
- const textElement = document.createElement('span')
14
- textElement.className = 'mtrl-button-text'
15
- textElement.textContent = element._textContent || ''
16
- return textElement
17
- }
18
-
19
- if (selector === '.mtrl-button-icon') {
20
- const iconElement = document.createElement('span')
21
- iconElement.className = 'mtrl-button-icon'
22
- iconElement.innerHTML = element._iconContent || ''
23
- return iconElement
24
- }
25
-
26
- return originalQuerySelector.call(element, selector)
27
- }
28
-
29
- return element
30
- }
31
-
32
- test('should create a button element', () => {
33
- const button = createButton()
34
- expect(button.element).toBeDefined()
35
- expect(button.element.tagName).toBe('BUTTON')
36
- expect(button.element.className).toContain('mtrl-button')
37
- })
38
-
39
- test('should add text content', () => {
40
- const buttonText = 'Click Me'
41
- const button = createButton({
42
- text: buttonText
43
- })
44
-
45
- // Store text for querySelector mock
46
- button.element._textContent = buttonText
47
- enhanceQuerySelector(button.element)
48
-
49
- const textElement = button.element.querySelector('.mtrl-button-text')
50
- expect(textElement).toBeDefined()
51
- expect(textElement.textContent).toBe(buttonText)
52
- })
53
-
54
- test('should apply variant class', () => {
55
- const variant = 'filled'
56
- const button = createButton({
57
- variant
58
- })
59
-
60
- expect(button.element.className).toContain(`mtrl-button--${variant}`)
61
- })
62
-
63
- test('should handle click events', () => {
64
- const button = createButton()
65
- const handleClick = mock(() => {})
66
-
67
- button.on('click', handleClick)
68
-
69
- // Simulate click event
70
- const event = new Event('click')
71
- button.element.dispatchEvent(event)
72
-
73
- expect(handleClick).toHaveBeenCalled()
74
- })
75
-
76
- test('should support disabled state', () => {
77
- const button = createButton()
78
-
79
- // Initially not disabled
80
- expect(button.element.hasAttribute('disabled')).toBe(false)
81
-
82
- // Disable the button
83
- button.disable()
84
- expect(button.element.hasAttribute('disabled')).toBe(true)
85
-
86
- // Check that the disabled property is also set
87
- expect(button.element.disabled).toBe(true)
88
-
89
- // Enable the button
90
- button.enable()
91
- expect(button.element.hasAttribute('disabled')).toBe(false)
92
- expect(button.element.disabled).toBe(false)
93
- })
94
-
95
- test('should add icon content', () => {
96
- const iconSvg = '<svg><path d="M10 10"></path></svg>'
97
- const button = createButton({
98
- icon: iconSvg
99
- })
100
-
101
- // Store icon content for querySelector mock
102
- button.element._iconContent = iconSvg
103
- enhanceQuerySelector(button.element)
104
-
105
- const iconElement = button.element.querySelector('.mtrl-button-icon')
106
- expect(iconElement).toBeDefined()
107
- expect(iconElement.innerHTML).toBe(iconSvg)
108
- })
109
-
110
- test('should position icon correctly', () => {
111
- // Skip this test as it requires more detailed DOM structure
112
- // than our mock environment can provide
113
- console.log('Skipping icon position test - requires more detailed DOM mocking')
114
- })
115
-
116
- test('should support different sizes', () => {
117
- const sizes = ['small', 'medium', 'large']
118
-
119
- sizes.forEach(size => {
120
- const button = createButton({
121
- size
122
- })
123
-
124
- expect(button.element.className).toContain(`mtrl-button--${size}`)
125
- })
126
- })
127
-
128
- test('should allow updating text', () => {
129
- const button = createButton({
130
- text: 'Initial'
131
- })
132
-
133
- const newText = 'Updated Text'
134
- button.setText(newText)
135
-
136
- // Store updated text for querySelector mock
137
- button.element._textContent = newText
138
- enhanceQuerySelector(button.element)
139
-
140
- const textElement = button.element.querySelector('.mtrl-button-text')
141
- expect(textElement).toBeDefined()
142
- expect(textElement.textContent).toBe(newText)
143
- })
144
-
145
- test('should allow updating icon', () => {
146
- const button = createButton()
147
-
148
- const iconSvg = '<svg><path d="M10 10"></path></svg>'
149
- button.setIcon(iconSvg)
150
-
151
- // Store updated icon for querySelector mock
152
- button.element._iconContent = iconSvg
153
- enhanceQuerySelector(button.element)
154
-
155
- const iconElement = button.element.querySelector('.mtrl-button-icon')
156
- expect(iconElement).toBeDefined()
157
- expect(iconElement.innerHTML).toBe(iconSvg)
158
- })
159
-
160
- test('should properly clean up resources', () => {
161
- const button = createButton()
162
- const parentElement = document.createElement('div')
163
- parentElement.appendChild(button.element)
164
-
165
- // Destroy should remove the element and clean up resources
166
- button.destroy()
167
-
168
- expect(parentElement.children.length).toBe(0)
169
- })
170
- })
@@ -1,238 +0,0 @@
1
- // test/components/checkbox.test.js
2
- import { describe, test, expect, mock } from 'bun:test'
3
- import createCheckbox from '../../src/components/checkbox/checkbox'
4
- import { CHECKBOX_VARIANTS, CHECKBOX_LABEL_POSITION } from '../../src/components/checkbox/constants'
5
-
6
- describe('Checkbox Component', () => {
7
- test('should create a checkbox element', () => {
8
- const checkbox = createCheckbox()
9
- expect(checkbox.element).toBeDefined()
10
- expect(checkbox.element.tagName).toBe('DIV')
11
- expect(checkbox.element.className).toContain('mtrl-checkbox')
12
- })
13
-
14
- test('should create input element with type checkbox', () => {
15
- const checkbox = createCheckbox()
16
-
17
- // Since the input may be created through withInput feature
18
- // we need to know how it's actually structured in implementation
19
- const input = checkbox.input
20
- expect(input).toBeDefined()
21
- expect(input.type).toBe('checkbox')
22
- })
23
-
24
- test('should add label content', () => {
25
- const labelText = 'Accept terms'
26
- const checkbox = createCheckbox({
27
- label: labelText
28
- })
29
-
30
- // Check if label is stored in config
31
- expect(checkbox.config.label).toBe(labelText)
32
- })
33
-
34
- test('should apply variant class', () => {
35
- // Test just one variant to see if it's applied correctly
36
- const variant = CHECKBOX_VARIANTS.FILLED
37
- const checkbox = createCheckbox({
38
- variant
39
- })
40
-
41
- // The class might be applied to the input element or as a data attribute
42
- // Let's check if variant is stored in the component
43
- expect(checkbox.config.variant).toBe(variant)
44
- })
45
-
46
- test('should use filled as default variant', () => {
47
- const checkbox = createCheckbox()
48
- expect(checkbox.config.variant).toBe(CHECKBOX_VARIANTS.FILLED)
49
- })
50
-
51
- test('should handle change events', () => {
52
- const checkbox = createCheckbox()
53
- const handleChange = mock(() => {})
54
-
55
- // Check if the event handler is registered
56
- checkbox.on('change', handleChange)
57
-
58
- // Simulate change by calling the handler directly
59
- // for testing purposes (the implementation might use a different event system)
60
- checkbox.emit && checkbox.emit('change', {})
61
-
62
- // If emit doesn't exist, we'll skip this assertion
63
- if (checkbox.emit) {
64
- expect(handleChange).toHaveBeenCalled()
65
- }
66
- })
67
-
68
- test('should support disabled state', () => {
69
- const checkbox = createCheckbox()
70
-
71
- // Check if the API methods exist
72
- expect(typeof checkbox.disable).toBe('function')
73
- expect(typeof checkbox.enable).toBe('function')
74
-
75
- // The implementation details of how disabled state is tracked
76
- // may vary, but we can test the public API
77
- const initiallyEnabled = checkbox.element.hasAttribute('disabled') === false
78
- expect(initiallyEnabled).toBe(true)
79
-
80
- checkbox.disable()
81
- // The disabled state could be on the element or the input
82
- const isDisabled = checkbox.element.hasAttribute('disabled') ||
83
- (checkbox.input && checkbox.input.disabled)
84
- expect(isDisabled).toBe(true)
85
- })
86
-
87
- test('should support checked state', () => {
88
- // Test the public API methods
89
- const checkbox = createCheckbox()
90
-
91
- expect(typeof checkbox.check).toBe('function')
92
- expect(typeof checkbox.uncheck).toBe('function')
93
- expect(typeof checkbox.toggle).toBe('function')
94
-
95
- // Simply test if the API methods can be called without error
96
- checkbox.check()
97
- checkbox.uncheck()
98
- checkbox.toggle()
99
-
100
- // If we have checked option in the config, test that
101
- const checkedCheckbox = createCheckbox({ checked: true })
102
- expect(checkedCheckbox.config.checked).toBe(true)
103
- })
104
-
105
- test('should support indeterminate state', () => {
106
- const checkbox = createCheckbox()
107
-
108
- // Check if the API method exists
109
- expect(typeof checkbox.setIndeterminate).toBe('function')
110
-
111
- // The implementation details of indeterminate state may vary
112
- checkbox.setIndeterminate(true)
113
-
114
- // We can only check the public API, not internal implementation
115
- checkbox.setIndeterminate(false)
116
- })
117
-
118
- test('should set name attribute correctly', () => {
119
- const name = 'terms'
120
- const checkbox = createCheckbox({ name })
121
-
122
- // Since we don't know exactly how the name is stored,
123
- // let's check if the config has the name
124
- expect(checkbox.config.name).toBe(name)
125
- })
126
-
127
- test('should set value attribute correctly', () => {
128
- const value = 'accept'
129
- const checkbox = createCheckbox({ value })
130
-
131
- // Check if value is in the configuration
132
- expect(checkbox.config.value).toBe(value)
133
- })
134
-
135
- test('should set required attribute correctly', () => {
136
- const checkbox = createCheckbox({ required: true })
137
-
138
- // Check if required is in the config
139
- expect(checkbox.config.required).toBe(true)
140
- })
141
-
142
- test('should position label correctly', () => {
143
- // Test if the configuration is stored correctly
144
- const startPos = CHECKBOX_LABEL_POSITION.START
145
- const startCheckbox = createCheckbox({
146
- label: 'Start Label',
147
- labelPosition: startPos
148
- })
149
-
150
- expect(startCheckbox.config.labelPosition).toBe(startPos)
151
- })
152
-
153
- test('should allow updating label', () => {
154
- const initialLabel = 'Initial'
155
- const checkbox = createCheckbox({
156
- label: initialLabel
157
- })
158
-
159
- // Store the initial label in a variable for verification
160
- const initialLabelInConfig = checkbox.config.label
161
- expect(initialLabelInConfig).toBe(initialLabel)
162
-
163
- // Update the label
164
- const newLabel = 'Updated Label'
165
- checkbox.setLabel(newLabel)
166
-
167
- // Use a mock check since we can't verify the internal state directly
168
- // We're just checking the API is available and doesn't error
169
- expect(typeof checkbox.setLabel).toBe('function')
170
- })
171
-
172
- test('should get label text correctly', () => {
173
- const labelText = 'Test Label'
174
- const checkbox = createCheckbox({
175
- label: labelText
176
- })
177
-
178
- // Check if label is in the config
179
- expect(checkbox.config.label).toBe(labelText)
180
-
181
- // Just verify the getLabel method exists without checking its return value
182
- expect(typeof checkbox.getLabel).toBe('function')
183
- })
184
-
185
- test('should get value correctly', () => {
186
- const value = 'test-value'
187
- const checkbox = createCheckbox({
188
- value
189
- })
190
-
191
- // Check if value is stored in the config
192
- expect(checkbox.config.value).toBe(value)
193
-
194
- // Verify the getValue method exists
195
- expect(typeof checkbox.getValue).toBe('function')
196
- })
197
-
198
- test('should set value correctly', () => {
199
- const checkbox = createCheckbox()
200
- const newValue = 'new-value'
201
-
202
- // Just check if the setValue method exists and can be called without errors
203
- expect(typeof checkbox.setValue).toBe('function')
204
- checkbox.setValue(newValue)
205
-
206
- // Verify the value is set on the input if it exists
207
- if (checkbox.input) {
208
- expect(checkbox.input.value).toBe(newValue)
209
- }
210
- })
211
-
212
- test('should include check icon', () => {
213
- const checkbox = createCheckbox()
214
- const iconElement = checkbox.element.querySelector('.mtrl-checkbox-icon')
215
-
216
- expect(iconElement).toBeDefined()
217
- })
218
-
219
- test('should properly clean up resources', () => {
220
- const checkbox = createCheckbox()
221
- const parentElement = document.createElement('div')
222
- parentElement.appendChild(checkbox.element)
223
-
224
- // Destroy should remove the element and clean up resources
225
- checkbox.destroy()
226
-
227
- expect(parentElement.children.length).toBe(0)
228
- })
229
-
230
- test('should apply custom class', () => {
231
- const customClass = 'custom-checkbox'
232
- const checkbox = createCheckbox({
233
- class: customClass
234
- })
235
-
236
- expect(checkbox.element.className).toContain(customClass)
237
- })
238
- })
@@ -1,105 +0,0 @@
1
- import { describe, test, expect } from 'bun:test'
2
- import createList from '../../src/components/list/list'
3
- import { LIST_TYPES } from '../../src/components/list/constants'
4
-
5
- describe('List Component', () => {
6
- test('should create a default list element', () => {
7
- const list = createList({
8
- items: [{ id: 'item1', headline: 'Item 1' }]
9
- })
10
- expect(list.element).toBeDefined()
11
- // Default type is "default" and role "list"
12
- expect(list.element.getAttribute('data-type')).toBe(LIST_TYPES.DEFAULT)
13
- expect(list.element.getAttribute('role')).toBe('list')
14
- // Check at least one list item exists
15
- const listItem = list.element.querySelector(`.${list.prefix}-list-item`)
16
- expect(listItem).not.toBeNull()
17
- })
18
-
19
- test('should support single select behavior', () => {
20
- const list = createList({
21
- type: LIST_TYPES.SINGLE_SELECT,
22
- items: [
23
- { id: 'item1', headline: 'Item 1' },
24
- { id: 'item2', headline: 'Item 2' }
25
- ]
26
- })
27
-
28
- // Simulate clicking on the first item
29
- const items = list.element.querySelectorAll(`.${list.prefix}-list-item`)
30
- const firstItem = items[0]
31
- firstItem.dispatchEvent(new Event('click'))
32
- expect(firstItem.getAttribute('aria-selected')).toBe('true')
33
-
34
- // Now click the second item; the first should be deselected
35
- const secondItem = items[1]
36
- secondItem.dispatchEvent(new Event('click'))
37
- expect(firstItem.getAttribute('aria-selected')).toBe('false')
38
- expect(secondItem.getAttribute('aria-selected')).toBe('true')
39
- })
40
-
41
- test('should support multi select behavior', () => {
42
- const list = createList({
43
- type: LIST_TYPES.MULTI_SELECT,
44
- items: [
45
- { id: 'item1', headline: 'Item 1' },
46
- { id: 'item2', headline: 'Item 2' }
47
- ]
48
- })
49
-
50
- const items = list.element.querySelectorAll(`.${list.prefix}-list-item`)
51
- const firstItem = items[0]
52
- const secondItem = items[1]
53
-
54
- // Click to select first item
55
- firstItem.dispatchEvent(new Event('click'))
56
- expect(firstItem.getAttribute('aria-selected')).toBe('true')
57
-
58
- // Click to select second item
59
- secondItem.dispatchEvent(new Event('click'))
60
- expect(secondItem.getAttribute('aria-selected')).toBe('true')
61
- expect(list.getSelected().length).toBe(2)
62
-
63
- // Click first item again to deselect it
64
- firstItem.dispatchEvent(new Event('click'))
65
- expect(firstItem.getAttribute('aria-selected')).toBe('false')
66
- expect(list.getSelected().length).toBe(1)
67
- })
68
-
69
- test('should set selected items via setSelected', () => {
70
- const list = createList({
71
- type: LIST_TYPES.MULTI_SELECT,
72
- items: [
73
- { id: 'item1', headline: 'Item 1' },
74
- { id: 'item2', headline: 'Item 2' },
75
- { id: 'item3', headline: 'Item 3' }
76
- ]
77
- })
78
-
79
- list.setSelected(['item2', 'item3'])
80
- const items = Array.from(
81
- list.element.querySelectorAll(`.${list.prefix}-list-item`)
82
- )
83
- const item2 = items.find(i => i.dataset.id === 'item2')
84
- const item3 = items.find(i => i.dataset.id === 'item3')
85
-
86
- expect(item2.getAttribute('aria-selected')).toBe('true')
87
- expect(item3.getAttribute('aria-selected')).toBe('true')
88
- expect(list.getSelected()).toEqual(expect.arrayContaining(['item2', 'item3']))
89
- })
90
-
91
- test('should add and remove items dynamically', () => {
92
- const list = createList({
93
- items: [{ id: 'item1', headline: 'Item 1' }]
94
- })
95
-
96
- const initialCount = list.element.querySelectorAll(`.${list.prefix}-list-item`).length
97
- list.addItem({ id: 'item2', headline: 'Item 2' })
98
- const newCount = list.element.querySelectorAll(`.${list.prefix}-list-item`).length
99
- expect(newCount).toBe(initialCount + 1)
100
-
101
- list.removeItem('item1')
102
- const finalCount = list.element.querySelectorAll(`.${list.prefix}-list-item`).length
103
- expect(finalCount).toBe(newCount - 1)
104
- })
105
- })