@loadsmart/loadsmart-ui 5.11.2-beta.1 → 5.12.1
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/dist/components/Select/Select.types.d.ts +10 -3
- package/dist/components/Select/index.d.ts +1 -1
- package/dist/index.js +65 -65
- package/dist/index.js.map +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/Banner/Banner.test.tsx +5 -4
- package/src/components/Checkbox/Checkbox.test.tsx +15 -18
- package/src/components/Dropdown/Dropdown.test.tsx +9 -9
- package/src/components/Radio/Radio.test.tsx +15 -18
- package/src/components/Select/Select.test.tsx +22 -3
- package/src/components/Select/Select.tsx +19 -17
- package/src/components/Select/Select.types.ts +13 -3
- package/src/components/Select/index.ts +4 -0
- package/src/components/Tag/Tag.test.tsx +4 -3
- package/src/components/TextField/TextField.test.tsx +9 -8
- package/src/components/Textarea/Textarea.test.tsx +3 -2
- package/src/hooks/useHeightExpansionToggler/useHeightExpansionToggler.test.tsx +12 -20
- package/src/testing/SelectEvent/SelectEvent.ts +42 -28
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import {
|
|
3
|
+
fireEvent,
|
|
4
|
+
queries,
|
|
5
|
+
waitFor,
|
|
6
|
+
within,
|
|
7
|
+
waitForElementToBeRemoved,
|
|
8
|
+
} from '@testing-library/dom'
|
|
2
9
|
import { act } from '@testing-library/react'
|
|
3
10
|
import userEvent from '@testing-library/user-event'
|
|
4
11
|
|
|
@@ -19,7 +26,6 @@ function getSelectMenu(input: HTMLElement): HTMLElement {
|
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
function getSelectTriggerHandle(input: HTMLElement): HTMLElement {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
29
|
return input.parentNode!.nextSibling!.nextSibling as HTMLElement
|
|
24
30
|
}
|
|
25
31
|
|
|
@@ -54,12 +60,12 @@ function isSelectMenuExpanded(input: HTMLElement): boolean {
|
|
|
54
60
|
async function waitForPendingQuery(input: HTMLElement) {
|
|
55
61
|
const searchContainer = getSelectSearchContainer(input)
|
|
56
62
|
|
|
57
|
-
if (!
|
|
63
|
+
if (!queries.queryByTestId(searchContainer, 'select-trigger-loading')) {
|
|
58
64
|
return
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
await waitForElementToBeRemoved(
|
|
62
|
-
() =>
|
|
68
|
+
() => queries.queryByTestId(searchContainer, 'select-trigger-loading'),
|
|
63
69
|
{ timeout: 2500 }
|
|
64
70
|
)
|
|
65
71
|
}
|
|
@@ -82,10 +88,11 @@ async function expand(input: HTMLElement): Promise<void> {
|
|
|
82
88
|
expect(triggerHandle).toBeEnabled()
|
|
83
89
|
})
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
await act(async () => {
|
|
92
|
+
userEvent.click(triggerHandle)
|
|
93
|
+
await waitFor(() => {
|
|
94
|
+
expect(isSelectMenuExpanded(input)).toBe(true)
|
|
95
|
+
})
|
|
89
96
|
})
|
|
90
97
|
}
|
|
91
98
|
|
|
@@ -101,10 +108,12 @@ async function collapse(input: HTMLElement): Promise<void> {
|
|
|
101
108
|
|
|
102
109
|
const triggerHandle = getSelectTriggerHandle(input)
|
|
103
110
|
|
|
104
|
-
|
|
111
|
+
await act(async () => {
|
|
112
|
+
userEvent.click(triggerHandle)
|
|
105
113
|
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
await waitFor(() => {
|
|
115
|
+
expect(isSelectMenuExpanded(input)).toBe(false)
|
|
116
|
+
})
|
|
108
117
|
})
|
|
109
118
|
}
|
|
110
119
|
|
|
@@ -120,12 +129,14 @@ async function select(option: string, input: HTMLElement): Promise<void> {
|
|
|
120
129
|
|
|
121
130
|
const menuContainer = getSelectMenu(input)
|
|
122
131
|
|
|
123
|
-
|
|
132
|
+
await act(async () => {
|
|
133
|
+
const optionElement = await queries.findByLabelText(menuContainer, option)
|
|
124
134
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
// click the option if exists; Select currently closes when an item is clicked.
|
|
136
|
+
if (optionElement && optionElement.getAttribute('aria-selected') == 'false') {
|
|
137
|
+
userEvent.click(optionElement)
|
|
138
|
+
}
|
|
139
|
+
})
|
|
129
140
|
|
|
130
141
|
// we collapse in the case the option was not clicked
|
|
131
142
|
await collapse(input)
|
|
@@ -143,12 +154,14 @@ async function unselect(option: string, input: HTMLElement): Promise<void> {
|
|
|
143
154
|
|
|
144
155
|
const menuContainer = getSelectMenu(input)
|
|
145
156
|
|
|
146
|
-
|
|
157
|
+
await act(async () => {
|
|
158
|
+
const optionElement = await queries.findByLabelText(menuContainer, option)
|
|
147
159
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
// ensures that the option exists and IS selected
|
|
161
|
+
if (optionElement && optionElement.getAttribute('aria-selected') == 'true') {
|
|
162
|
+
userEvent.click(optionElement)
|
|
163
|
+
}
|
|
164
|
+
})
|
|
152
165
|
|
|
153
166
|
// we collapse in the case the option was not clicked
|
|
154
167
|
await collapse(input)
|
|
@@ -164,9 +177,9 @@ async function clear(input: HTMLElement): Promise<void> {
|
|
|
164
177
|
|
|
165
178
|
const searchContainer = getSelectSearchContainer(input)
|
|
166
179
|
|
|
167
|
-
|
|
180
|
+
await act(async () => {
|
|
181
|
+
const clearButton = within(searchContainer).getByTestId('select-trigger-clear')
|
|
168
182
|
|
|
169
|
-
act(() => {
|
|
170
183
|
if (clearButton) {
|
|
171
184
|
userEvent.click(clearButton)
|
|
172
185
|
}
|
|
@@ -182,9 +195,11 @@ async function clear(input: HTMLElement): Promise<void> {
|
|
|
182
195
|
async function search(query: string, input: HTMLElement): Promise<void> {
|
|
183
196
|
const selectContainer = getSelectContainer(input)
|
|
184
197
|
|
|
185
|
-
|
|
198
|
+
await act(async () => {
|
|
199
|
+
fireEvent.change(input, { target: { value: query } })
|
|
186
200
|
|
|
187
|
-
|
|
201
|
+
await queries.findAllByRole(selectContainer, 'option')
|
|
202
|
+
})
|
|
188
203
|
}
|
|
189
204
|
|
|
190
205
|
/**
|
|
@@ -197,8 +212,7 @@ async function getOptions(input: HTMLElement): Promise<HTMLElement[]> {
|
|
|
197
212
|
|
|
198
213
|
const menuContainer = getSelectMenu(input)
|
|
199
214
|
|
|
200
|
-
const options =
|
|
201
|
-
|
|
215
|
+
const options = queries.queryAllByRole(menuContainer, 'option')
|
|
202
216
|
await collapse(input)
|
|
203
217
|
|
|
204
218
|
return options
|
|
@@ -216,7 +230,7 @@ async function getSelectedOptions(input: HTMLElement): Promise<HTMLElement[]> {
|
|
|
216
230
|
let selectedOptions: HTMLElement[] = []
|
|
217
231
|
|
|
218
232
|
try {
|
|
219
|
-
selectedOptions = await
|
|
233
|
+
selectedOptions = await queries.findAllByRole(menuContainer, 'option', {
|
|
220
234
|
selected: true,
|
|
221
235
|
})
|
|
222
236
|
} catch (err) {
|