@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.
@@ -1,4 +1,11 @@
1
- import { fireEvent, waitFor, within, waitForElementToBeRemoved } from '@testing-library/react'
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 (!within(searchContainer).queryByTestId('select-trigger-loading')) {
63
+ if (!queries.queryByTestId(searchContainer, 'select-trigger-loading')) {
58
64
  return
59
65
  }
60
66
 
61
67
  await waitForElementToBeRemoved(
62
- () => within(searchContainer).queryByTestId('select-trigger-loading'),
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
- userEvent.click(triggerHandle)
86
-
87
- await waitFor(async () => {
88
- expect(await within(getSelectContainer(input)).findByRole('listbox')).toBeInTheDocument()
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
- userEvent.click(triggerHandle)
111
+ await act(async () => {
112
+ userEvent.click(triggerHandle)
105
113
 
106
- await waitFor(() => {
107
- expect(within(getSelectContainer(input)).queryByRole('listbox')).not.toBeInTheDocument()
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
- const optionElement = await within(menuContainer).findByLabelText(option)
132
+ await act(async () => {
133
+ const optionElement = await queries.findByLabelText(menuContainer, option)
124
134
 
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
- }
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
- const optionElement = await within(menuContainer).findByLabelText(option)
157
+ await act(async () => {
158
+ const optionElement = await queries.findByLabelText(menuContainer, option)
147
159
 
148
- // ensures that the option exists and IS selected
149
- if (optionElement && optionElement.getAttribute('aria-selected') == 'true') {
150
- userEvent.click(optionElement)
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
- const clearButton = within(searchContainer).getByTestId('select-trigger-clear')
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
- fireEvent.change(input, { target: { value: query } })
198
+ await act(async () => {
199
+ fireEvent.change(input, { target: { value: query } })
186
200
 
187
- await within(selectContainer).findAllByRole('option')
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 = within(menuContainer).queryAllByRole('option')
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 within(menuContainer).findAllByRole('option', {
233
+ selectedOptions = await queries.findAllByRole(menuContainer, 'option', {
220
234
  selected: true,
221
235
  })
222
236
  } catch (err) {