@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,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadsmart/loadsmart-ui",
3
- "version": "5.13.0",
3
+ "version": "5.13.1",
4
4
  "description": "Miranda UI, a React UI library",
5
5
  "main": "dist",
6
6
  "files": [
@@ -1,11 +1,4 @@
1
- /* eslint-disable */
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 (!queries.queryByTestId(searchContainer, 'select-trigger-loading')) {
57
+ if (!within(searchContainer).queryByTestId('select-trigger-loading')) {
64
58
  return
65
59
  }
66
60
 
67
61
  await waitForElementToBeRemoved(
68
- () => queries.queryByTestId(searchContainer, 'select-trigger-loading'),
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
- await act(async () => {
92
- userEvent.click(triggerHandle)
93
- await waitFor(() => {
94
- expect(isSelectMenuExpanded(input)).toBe(true)
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
- await act(async () => {
112
- userEvent.click(triggerHandle)
104
+ userEvent.click(triggerHandle)
113
105
 
114
- await waitFor(() => {
115
- expect(isSelectMenuExpanded(input)).toBe(false)
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 act(async () => {
133
- const optionElement = await queries.findByLabelText(menuContainer, option)
123
+ const optionElement = await within(menuContainer).findByLabelText(option)
134
124
 
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
- })
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 act(async () => {
158
- const optionElement = await queries.findByLabelText(menuContainer, option)
146
+ const optionElement = await within(menuContainer).findByLabelText(option)
159
147
 
160
- // ensures that the option exists and IS selected
161
- if (optionElement && optionElement.getAttribute('aria-selected') == 'true') {
162
- userEvent.click(optionElement)
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
- await act(async () => {
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
- await act(async () => {
199
- fireEvent.change(input, { target: { value: query } })
185
+ fireEvent.change(input, { target: { value: query } })
200
186
 
201
- await queries.findAllByRole(selectContainer, 'option')
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 = queries.queryAllByRole(menuContainer, 'option')
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 queries.findAllByRole(menuContainer, 'option', {
219
+ selectedOptions = await within(menuContainer).findAllByRole('option', {
234
220
  selected: true,
235
221
  })
236
222
  } catch (err) {