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