@leaflink/dom-testing-utils 0.0.0-PR-143--9f87d72 → 0.0.0-PR-156--f926899
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/README.md +74 -65
- package/dist/mocks/IntersectionObserverMock.d.ts +3 -2
- package/dist/setup-env.spec.js +2 -2
- package/dist/setup-env.spec.js.map +1 -1
- package/package.json +14 -6
- package/dist/utils/__tests__/assertSelectElementItems.spec.d.ts +0 -1
- package/dist/utils/__tests__/assertSelectElementItems.spec.js +0 -68
- package/dist/utils/__tests__/assertSelectElementItems.spec.js.map +0 -1
- package/dist/utils/__tests__/setSelectElementItems.spec.d.ts +0 -1
- package/dist/utils/__tests__/setSelectElementItems.spec.js +0 -59
- package/dist/utils/__tests__/setSelectElementItems.spec.js.map +0 -1
- package/dist/utils/__tests__/setSelectElementRandomItems.spec.d.ts +0 -1
- package/dist/utils/__tests__/setSelectElementRandomItems.spec.js +0 -48
- package/dist/utils/__tests__/setSelectElementRandomItems.spec.js.map +0 -1
- package/dist/utils/assertSelectElementItems.d.ts +0 -46
- package/dist/utils/assertSelectElementItems.js +0 -43
- package/dist/utils/assertSelectElementItems.js.map +0 -1
- package/dist/utils/getRandomItemsFromArray.d.ts +0 -8
- package/dist/utils/getRandomItemsFromArray.js +0 -23
- package/dist/utils/getRandomItemsFromArray.js.map +0 -1
- package/dist/utils/getSelectElementByLabel.d.ts +0 -8
- package/dist/utils/getSelectElementByLabel.js +0 -38
- package/dist/utils/getSelectElementByLabel.js.map +0 -1
- package/dist/utils/getSelectElementItems.d.ts +0 -18
- package/dist/utils/getSelectElementItems.js +0 -19
- package/dist/utils/getSelectElementItems.js.map +0 -1
- package/dist/utils/getSelectElementOptions.d.ts +0 -24
- package/dist/utils/getSelectElementOptions.js +0 -38
- package/dist/utils/getSelectElementOptions.js.map +0 -1
- package/dist/utils/getSelectElementValues.d.ts +0 -14
- package/dist/utils/getSelectElementValues.js +0 -23
- package/dist/utils/getSelectElementValues.js.map +0 -1
- package/dist/utils/setSelectElementItems.d.ts +0 -21
- package/dist/utils/setSelectElementItems.js +0 -32
- package/dist/utils/setSelectElementItems.js.map +0 -1
- package/dist/utils/setSelectElementRandomItems.d.ts +0 -21
- package/dist/utils/setSelectElementRandomItems.js +0 -41
- package/dist/utils/setSelectElementRandomItems.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,28 +11,31 @@
|
|
|
11
11
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
12
12
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
13
13
|
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
- [@leaflink/dom-testing-utils](#leaflinkdom-testing-utils)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Setup file](#setup-file)
|
|
18
|
+
- [Global setup](#global-setup)
|
|
19
|
+
- [Utilities](#utilities)
|
|
20
|
+
- [`cleanupNoty`](#cleanupnoty)
|
|
21
|
+
- [`waitForLoading`](#waitforloading)
|
|
22
|
+
- [`cleanupDropdowns`](#cleanupdropdowns)
|
|
23
|
+
- [`assertAndDismissNoty`](#assertanddismissnoty)
|
|
24
|
+
- [`getByDescriptionTerm`](#getbydescriptionterm)
|
|
25
|
+
- [`getAllByDescriptionTerm`](#getallbydescriptionterm)
|
|
26
|
+
- [`getSelectedOption`](#getselectedoption)
|
|
27
|
+
- [`getSelectedOptions`](#getselectedoptions)
|
|
28
|
+
- [`createFixtureGenerator`](#createfixturegenerator)
|
|
29
|
+
- [Mocking API Endpoints](#mocking-api-endpoints)
|
|
29
30
|
|
|
30
31
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
31
32
|
|
|
32
33
|
## Installation
|
|
33
34
|
|
|
35
|
+
**Requirements:** Node.js >= 24
|
|
36
|
+
|
|
34
37
|
```sh
|
|
35
|
-
|
|
38
|
+
pnpm add -D @leaflink/dom-testing-utils
|
|
36
39
|
```
|
|
37
40
|
|
|
38
41
|
## Usage
|
|
@@ -71,7 +74,7 @@ setupFiles: ['tests/setup-env.js'],
|
|
|
71
74
|
setupFilesAfterEnv: ['<rootDir>/tests/setup-env.js']
|
|
72
75
|
```
|
|
73
76
|
|
|
74
|
-
This will be run once before
|
|
77
|
+
This will be run once before _each_ test file. See <https://vitest.dev/config/#setupfiles>.
|
|
75
78
|
|
|
76
79
|
### Global setup
|
|
77
80
|
|
|
@@ -85,7 +88,7 @@ globalSetup: ['node_modules/@leaflink/dom-testing-utils/dist/global-setup.js'],
|
|
|
85
88
|
globalSetup: ['<rootDir>/node_modules/@leaflink/dom-testing-utils/dist/global-setup.js']
|
|
86
89
|
```
|
|
87
90
|
|
|
88
|
-
This will run once
|
|
91
|
+
This will run once _before everything_. See <https://vitest.dev/config/#globalsetup>.
|
|
89
92
|
|
|
90
93
|
## Utilities
|
|
91
94
|
|
|
@@ -101,11 +104,11 @@ Helper method to remove all noty alerts from the DOM.
|
|
|
101
104
|
|
|
102
105
|
Utility that waits for all loading elements to be removed from the DOM. The `data-test` argument defaults to `ll-loading` **or** `loading-spinner` if `testId` is not specified.
|
|
103
106
|
|
|
104
|
-
| **Parameters** | **Type** | **Default**
|
|
105
|
-
|
|
|
106
|
-
| testId
|
|
107
|
-
| timeout
|
|
108
|
-
| failIfNull
|
|
107
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
108
|
+
| -------------- | -------- | --------------------------------- | --------------------------------------------------- |
|
|
109
|
+
| testId | `string` | `ll-loading` && `loading-spinner` | The data test ID to target. |
|
|
110
|
+
| timeout | number | 2000 | How long to wait for loading elements to be removed |
|
|
111
|
+
| failIfNull | boolean | false | Throws an error if no loading elements are found |
|
|
109
112
|
|
|
110
113
|
**Returns**: `Promise<void>`
|
|
111
114
|
|
|
@@ -123,11 +126,11 @@ Helper method to remove all floating Stash Dropdown elements from the DOM.
|
|
|
123
126
|
|
|
124
127
|
### `assertAndDismissNoty`
|
|
125
128
|
|
|
126
|
-
Helper to assert and manually dismiss a notification.
|
|
129
|
+
Helper to assert and manually dismiss a notification. This is useful in scenarios where cleanupNoty() does not work as expected, such as when validating error messages in test suites.
|
|
127
130
|
|
|
128
|
-
| **Parameters** | **Type** | **Default** | **Summary**
|
|
129
|
-
|
|
|
130
|
-
| text
|
|
131
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
132
|
+
| -------------- | -------- | ----------- | --------------------------- |
|
|
133
|
+
| text | `string` | _Required_ | Expected notification text. |
|
|
131
134
|
|
|
132
135
|
**Returns**: `void`
|
|
133
136
|
|
|
@@ -135,46 +138,43 @@ Helper to assert and manually dismiss a notification. This is useful in scenari
|
|
|
135
138
|
|
|
136
139
|
Finds the first HTML element with the role "definition" (DD) that matches the specified text for the description term.
|
|
137
140
|
|
|
138
|
-
| **Parameters** | **Type**
|
|
139
|
-
|
|
|
140
|
-
| text
|
|
141
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
142
|
+
| -------------- | ------------------ | ----------- | --------------------------------------- |
|
|
143
|
+
| text | `string \| RegExp` | _Required_ | Expected description term text or regex |
|
|
141
144
|
|
|
142
145
|
**Returns**: `HTMLElement | undefined` - The first matching description detail element or undefined if no match is found.
|
|
143
146
|
|
|
144
|
-
|
|
145
147
|
### `getAllByDescriptionTerm`
|
|
146
148
|
|
|
147
149
|
Queries and returns an array of HTML elements with the role "definition" (DD) that matches the specified text of a description term.
|
|
148
150
|
|
|
149
|
-
| **Parameters** | **Type**
|
|
150
|
-
|
|
|
151
|
-
| textMatch
|
|
151
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
152
|
+
| -------------- | ------------------ | ----------- | --------------------------------------------------------------------------------------- |
|
|
153
|
+
| textMatch | `string \| RegExp` | _Required_ | The text to match within the HTML elements. It can be a string or a regular expression. |
|
|
152
154
|
|
|
153
155
|
**Returns**: `HTMLElement[]` - An array of HTML description detail elements that match the given text.
|
|
154
156
|
|
|
155
|
-
|
|
156
157
|
### `getSelectedOption`
|
|
157
158
|
|
|
158
159
|
Finds the first selected HTML element with the role "definition" (LI) "listitem" inside the specified select element.
|
|
159
160
|
|
|
160
|
-
| **Parameters** | **Type**
|
|
161
|
-
|
|
|
162
|
-
| element
|
|
163
|
-
| selectedClass
|
|
164
|
-
| options
|
|
161
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
162
|
+
| -------------- | ----------------- | ------------- | ---------------------------------------------------------- |
|
|
163
|
+
| element | HTMLSelectElement | _Required_ | Stash Select element to be checked. |
|
|
164
|
+
| selectedClass | string | 'is-selected' | Selected class added on selected items |
|
|
165
|
+
| options | ByRoleOptions | null | `getAllByRole()` options values using `ByRoleOptions` type |
|
|
165
166
|
|
|
166
167
|
**Returns**: `HTMLElement | undefined` - The first selected HTML listitem element or undefined if no match is found.
|
|
167
168
|
|
|
168
|
-
|
|
169
169
|
### `getSelectedOptions`
|
|
170
170
|
|
|
171
171
|
Finds all the selected HTML elements with the role "definition" (LI) "listitem" inside the specified select element.
|
|
172
172
|
|
|
173
|
-
| **Parameters** | **Type**
|
|
174
|
-
|
|
|
175
|
-
| element
|
|
176
|
-
| selectedClass
|
|
177
|
-
| options
|
|
173
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
174
|
+
| -------------- | ----------------- | ------------- | ---------------------------------------------------------- |
|
|
175
|
+
| element | HTMLSelectElement | _Required_ | Stash Select element to be checked. |
|
|
176
|
+
| selectedClass | string | 'is-selected' | Selected class added on selected items |
|
|
177
|
+
| options | ByRoleOptions | null | `getAllByRole()` options values using `ByRoleOptions` type |
|
|
178
178
|
|
|
179
179
|
**Returns**: `HTMLElement[]` - An array of selected HTML listitem elements.
|
|
180
180
|
|
|
@@ -182,9 +182,9 @@ Finds all the selected HTML elements with the role "definition" (LI) "listitem"
|
|
|
182
182
|
|
|
183
183
|
Higher order function that takes a method whose responsibility is to create a **single** data fixture object and returns a new generator function that allows you to create 1 or more of those fixtures. Fixture generator function that's returned supports passing optional `num` and `overrides` params.
|
|
184
184
|
|
|
185
|
-
| **Parameters** | **Type**
|
|
186
|
-
|
|
|
187
|
-
| `fixtureFn`
|
|
185
|
+
| **Parameters** | **Type** | **Default** | **Summary** |
|
|
186
|
+
| -------------- | ---------- | ----------- | ------------------------------------------------------- |
|
|
187
|
+
| `fixtureFn` | `function` | _Required_ | Method that generates and returns a single data object. |
|
|
188
188
|
|
|
189
189
|
**Returns**
|
|
190
190
|
|
|
@@ -206,25 +206,30 @@ When calling the returned function, you'll get an array OR object of fixture dat
|
|
|
206
206
|
Quick example:
|
|
207
207
|
|
|
208
208
|
```ts
|
|
209
|
-
const generateInvoice = (overrides) => ({
|
|
209
|
+
const generateInvoice = (overrides) => ({
|
|
210
|
+
id: uuid(),
|
|
211
|
+
balance: 15799,
|
|
212
|
+
classification: 'Adult Use',
|
|
213
|
+
...overrides,
|
|
214
|
+
});
|
|
210
215
|
const generateInvoices = createFixtureGenerator(generateInvoice);
|
|
211
216
|
|
|
212
|
-
generateInvoices()
|
|
217
|
+
generateInvoices();
|
|
213
218
|
// => Single invoice object
|
|
214
219
|
|
|
215
|
-
generateInvoices(1)
|
|
220
|
+
generateInvoices(1);
|
|
216
221
|
// => Single invoice object
|
|
217
222
|
|
|
218
|
-
generateInvoices(1, { foo: 'bar' })
|
|
223
|
+
generateInvoices(1, { foo: 'bar' });
|
|
219
224
|
// => Single invoice object, override `foo` to equal `'bar'`
|
|
220
225
|
|
|
221
|
-
generateInvoices({ foo: 'bar' })
|
|
226
|
+
generateInvoices({ foo: 'bar' });
|
|
222
227
|
// => Single invoice object, override `foo` to equal `'bar'`
|
|
223
228
|
|
|
224
|
-
generateInvoices(10)
|
|
229
|
+
generateInvoices(10);
|
|
225
230
|
// => Array of 10 invoice objects
|
|
226
231
|
|
|
227
|
-
generateInvoices(10, { foo: 'bar' })
|
|
232
|
+
generateInvoices(10, { foo: 'bar' });
|
|
228
233
|
// => Array of 10 invoice objects, override `foo` to equal `'bar'` in each
|
|
229
234
|
```
|
|
230
235
|
|
|
@@ -249,7 +254,7 @@ export default createFixtureGenerator(generateProduct);
|
|
|
249
254
|
import generateProducts from '@/tests/fixtures/products';
|
|
250
255
|
|
|
251
256
|
// ...
|
|
252
|
-
const mockProducts = generateProducts(10, { cases: 25 })
|
|
257
|
+
const mockProducts = generateProducts(10, { cases: 25 });
|
|
253
258
|
// ...
|
|
254
259
|
```
|
|
255
260
|
|
|
@@ -270,20 +275,24 @@ const {
|
|
|
270
275
|
```
|
|
271
276
|
|
|
272
277
|
There are two flavors of mocking utility functions:
|
|
278
|
+
|
|
273
279
|
1. mock{VERB}Data - mocks response with a singular data object
|
|
274
280
|
2. mock{VERB}Endpoint - mocks a response endpoint with a function like msw's [Response Resolver](https://mswjs.io/docs/getting-started/mocks/rest-api#response-resolver)
|
|
275
281
|
|
|
276
282
|
To mock an endpoint with simple return data
|
|
283
|
+
|
|
277
284
|
```ts
|
|
278
|
-
|
|
285
|
+
mockGetData('/relative-url', myMockObj);
|
|
279
286
|
```
|
|
287
|
+
|
|
280
288
|
or you can customize the response
|
|
289
|
+
|
|
281
290
|
```ts
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
291
|
+
mockGetEndpoint('/relative-url', (req, res, ctx) => {
|
|
292
|
+
if (someConditional()) {
|
|
293
|
+
HttpResponse.json({ foo: 'bar' });
|
|
294
|
+
} else {
|
|
295
|
+
HttpResponse.json({ foo: 'baz' });
|
|
296
|
+
}
|
|
297
|
+
});
|
|
289
298
|
```
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface IntersectionObserverMockInterface extends IntersectionObserver {
|
|
2
2
|
target: Element | null;
|
|
3
3
|
scrollCallback: IntersectionObserverCallback;
|
|
4
4
|
onScroll(e: Event): void;
|
|
5
5
|
}
|
|
6
|
-
export declare class IntersectionObserverMock implements
|
|
6
|
+
export declare class IntersectionObserverMock implements IntersectionObserverMockInterface {
|
|
7
7
|
root: IntersectionObserver['root'];
|
|
8
8
|
rootMargin: IntersectionObserver['rootMargin'];
|
|
9
9
|
thresholds: IntersectionObserver['thresholds'];
|
|
@@ -13,6 +13,7 @@ export declare class IntersectionObserverMock implements IntersectionObserverMoc
|
|
|
13
13
|
takeRecords: IntersectionObserver['takeRecords'];
|
|
14
14
|
unobserve: IntersectionObserver['unobserve'];
|
|
15
15
|
scrollCallback: IntersectionObserverCallback;
|
|
16
|
+
onScroll(e: Event): void;
|
|
16
17
|
constructor(callback: IntersectionObserverCallback);
|
|
17
18
|
}
|
|
18
19
|
export declare function mockIntersectionObserver(): void;
|
package/dist/setup-env.spec.js
CHANGED
|
@@ -13,10 +13,10 @@ it('should stub fetch method', async () => {
|
|
|
13
13
|
await fetch(url);
|
|
14
14
|
expect(fetchSpy).toHaveBeenCalledWith(url);
|
|
15
15
|
});
|
|
16
|
-
it.each([
|
|
16
|
+
it.each(['disconnect', 'observe', 'takeRecords', 'unobserve'])('should stub intersection observer %s method', (method) => {
|
|
17
17
|
const observer = new globalThis.IntersectionObserver(() => ({}), {});
|
|
18
18
|
const methodSpy = vi.spyOn(observer, method);
|
|
19
|
-
observer[method]();
|
|
19
|
+
observer[method](document.createElement('div'));
|
|
20
20
|
expect(methodSpy).toHaveBeenCalled();
|
|
21
21
|
});
|
|
22
22
|
//# sourceMappingURL=setup-env.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-env.spec.js","sourceRoot":"src/","sources":["setup-env.spec.ts"],"names":[],"mappings":";AAAA,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;IACxC,MAAM,GAAG,GAAG,QAAQ,CAAC;IAErB,MA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ErB,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAE/C,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAExC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjB,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,IAAI,CAAyD,CAAC,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CACpH,6CAA6C,EAC7C,CAAC,MAA8D,EAAE,EAAE;IACjE,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAErE,MAAM,SAAS,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE7C,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhD,MAAM,CAAC,SAAS,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACvC,CAAC,CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leaflink/dom-testing-utils",
|
|
3
|
-
"version": "0.0.0-PR-
|
|
3
|
+
"version": "0.0.0-PR-156--f926899",
|
|
4
4
|
"description": "Frontend DOM testing utilities",
|
|
5
|
+
"packageManager": "pnpm@10.12.2",
|
|
5
6
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
7
|
-
"
|
|
7
|
+
"node": ">=24",
|
|
8
|
+
"pnpm": ">=10"
|
|
8
9
|
},
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
],
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build": "tsc",
|
|
36
|
-
"fix": "
|
|
37
|
+
"fix": "pnpm lint --fix",
|
|
37
38
|
"lint": "eslint .",
|
|
38
39
|
"lint:commits": "commitlint",
|
|
39
40
|
"test": "vitest --reporter verbose"
|
|
@@ -43,15 +44,17 @@
|
|
|
43
44
|
"msw": "^2.7.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
47
|
+
"@leaflink/eslint-config": "^4.4.2",
|
|
46
48
|
"@vitest/coverage-v8": "^3.0.9",
|
|
47
|
-
"
|
|
48
|
-
"eslint
|
|
49
|
+
"commitlint": "^20.3.1",
|
|
50
|
+
"eslint": "^9.39.2",
|
|
49
51
|
"jsdom": "^22.1.0",
|
|
50
52
|
"typescript": "^5.8.2",
|
|
51
53
|
"vite": "^6.2.2",
|
|
52
54
|
"vitest": "^3.0.9"
|
|
53
55
|
},
|
|
54
56
|
"peerDependencies": {
|
|
57
|
+
"@testing-library/dom": "^7 || ^8 || ^9 || ^10",
|
|
55
58
|
"@testing-library/jest-dom": "^5 || ^6",
|
|
56
59
|
"@testing-library/user-event": "^12 || ^13 || ^14",
|
|
57
60
|
"@testing-library/vue": "^7 || ^8",
|
|
@@ -62,5 +65,10 @@
|
|
|
62
65
|
"extends": [
|
|
63
66
|
"leaflink"
|
|
64
67
|
]
|
|
68
|
+
},
|
|
69
|
+
"commitlint": {
|
|
70
|
+
"extends": [
|
|
71
|
+
"@leaflink/eslint-config/commitlint"
|
|
72
|
+
]
|
|
65
73
|
}
|
|
66
74
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import userEvent from '@testing-library/user-event';
|
|
2
|
-
import { render, screen } from '@testing-library/vue';
|
|
3
|
-
import assertSelectElementItems from '../assertSelectElementItems';
|
|
4
|
-
// single-select template
|
|
5
|
-
const singleTemplate = `
|
|
6
|
-
<div>
|
|
7
|
-
<label for="color-select">Color</label>
|
|
8
|
-
<select id="color-select">
|
|
9
|
-
<option value="apple">Apple</option>
|
|
10
|
-
<option value="banana">Banana</option>
|
|
11
|
-
<option value="cherry">Cherry</option>
|
|
12
|
-
</select>
|
|
13
|
-
</div>
|
|
14
|
-
`;
|
|
15
|
-
const multipleTemplate = `
|
|
16
|
-
<div>
|
|
17
|
-
<label for="fruit-select">Fruits</label>
|
|
18
|
-
<select id="fruit-select" multiple>
|
|
19
|
-
<option value="apple">Apple</option>
|
|
20
|
-
<option value="banana">Banana</option>
|
|
21
|
-
<option value="cherry">Cherry</option>
|
|
22
|
-
</select>
|
|
23
|
-
</div>
|
|
24
|
-
`;
|
|
25
|
-
it('asserts a selected option for a single-select element by label', async () => {
|
|
26
|
-
const { container } = render({ template: singleTemplate });
|
|
27
|
-
const selectSingle = screen.getByLabelText('Color');
|
|
28
|
-
await userEvent.selectOptions(selectSingle, 'banana');
|
|
29
|
-
// should not throw
|
|
30
|
-
assertSelectElementItems({
|
|
31
|
-
label: 'Color',
|
|
32
|
-
values: 'banana',
|
|
33
|
-
withinElement: container,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it('asserts a single selected option by label', async () => {
|
|
37
|
-
const { container } = render({ template: singleTemplate });
|
|
38
|
-
const select = screen.getByLabelText('Fruits');
|
|
39
|
-
await userEvent.selectOptions(select, 'banana');
|
|
40
|
-
// should not throw
|
|
41
|
-
assertSelectElementItems({
|
|
42
|
-
label: 'Fruits',
|
|
43
|
-
values: 'banana',
|
|
44
|
-
withinElement: container,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it('asserts multiple selected options by element', async () => {
|
|
48
|
-
const { container } = render({ template: multipleTemplate });
|
|
49
|
-
const select = screen.getByLabelText('Fruits');
|
|
50
|
-
await userEvent.selectOptions(select, ['apple', 'cherry']);
|
|
51
|
-
// should not throw
|
|
52
|
-
assertSelectElementItems({
|
|
53
|
-
element: select,
|
|
54
|
-
values: ['apple', 'cherry'],
|
|
55
|
-
withinElement: container,
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
it('throws when selected values do not match expected', async () => {
|
|
59
|
-
const { container } = render({ template: multipleTemplate });
|
|
60
|
-
const select = screen.getByLabelText('Fruits');
|
|
61
|
-
await userEvent.selectOptions(select, 'apple');
|
|
62
|
-
expect(() => assertSelectElementItems({
|
|
63
|
-
label: 'Fruits',
|
|
64
|
-
values: ['banana'],
|
|
65
|
-
withinElement: container,
|
|
66
|
-
})).toThrow();
|
|
67
|
-
});
|
|
68
|
-
//# sourceMappingURL=assertSelectElementItems.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertSelectElementItems.spec.js","sourceRoot":"src/","sources":["utils/__tests__/assertSelectElementItems.spec.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,wBAAwB,MAAM,6BAA6B,CAAC;AAEnE,yBAAyB;AACzB,MAAM,cAAc,GAAG;;;;;;;;;CAStB,CAAC;AAEF,MAAM,gBAAgB,GAAG;;;;;;;;;GAStB,CAAC;AAEJ,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;IAC9E,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3D,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAoB,OAAO,CAAC,CAAC;IACvE,MAAM,SAAS,CAAC,aAAa,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAEtD,mBAAmB;IACnB,wBAAwB,CAAC;QACvB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,aAAa,EAAE,SAAwB;KACxC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;IACzD,MAAM,EAAE,SAAS,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AClB,aAAa,EAAE,SAAwB;KACxC,CAAC,CACH,CAAC,OAAO,EAAE,CAAC;AACd,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/vue';
|
|
2
|
-
import getSelectElementItems from '../getSelectElementItems';
|
|
3
|
-
import setSelectElementItems from '../setSelectElementItems';
|
|
4
|
-
const singleTemplate = `
|
|
5
|
-
<div>
|
|
6
|
-
<label for="color-select">Color</label>
|
|
7
|
-
<select id="color-select">
|
|
8
|
-
<option value="apple">Apple</option>
|
|
9
|
-
<option value="banana">Banana</option>
|
|
10
|
-
<option value="cherry">Cherry</option>
|
|
11
|
-
</select>
|
|
12
|
-
</div>
|
|
13
|
-
`;
|
|
14
|
-
const multipleTemplate = `
|
|
15
|
-
<div>
|
|
16
|
-
<label for="fruit-select">Fruits</label>
|
|
17
|
-
<select id="fruit-select" multiple>
|
|
18
|
-
<option value="apple">Apple</option>
|
|
19
|
-
<option value="banana">Banana</option>
|
|
20
|
-
<option value="cherry">Cherry</option>
|
|
21
|
-
</select>
|
|
22
|
-
</div>
|
|
23
|
-
`;
|
|
24
|
-
it('sets a single-select option by label', async () => {
|
|
25
|
-
const { container } = render({ template: singleTemplate });
|
|
26
|
-
await setSelectElementItems({
|
|
27
|
-
label: 'Color',
|
|
28
|
-
selectedOptionValues: ['apple'],
|
|
29
|
-
withinElement: container,
|
|
30
|
-
});
|
|
31
|
-
const select = screen.getByLabelText('Color');
|
|
32
|
-
expect(getSelectElementItems({ element: select, withinElement: container })).toEqual(['apple']);
|
|
33
|
-
});
|
|
34
|
-
it('sets multiple-select options by element', async () => {
|
|
35
|
-
const { container } = render({ template: multipleTemplate });
|
|
36
|
-
const select = screen.getByLabelText('Fruits');
|
|
37
|
-
await setSelectElementItems({
|
|
38
|
-
element: select,
|
|
39
|
-
selectedOptionValues: ['apple', 'cherry'],
|
|
40
|
-
withinElement: container,
|
|
41
|
-
});
|
|
42
|
-
expect(getSelectElementItems({ element: select, withinElement: container })).toEqual([
|
|
43
|
-
'apple',
|
|
44
|
-
'cherry',
|
|
45
|
-
]);
|
|
46
|
-
});
|
|
47
|
-
it('throws when selecting multiple values on a single-select', async () => {
|
|
48
|
-
const { container } = render({ template: singleTemplate });
|
|
49
|
-
await expect(setSelectElementItems({
|
|
50
|
-
label: 'Color',
|
|
51
|
-
selectedOptionValues: ['apple', 'banana'],
|
|
52
|
-
withinElement: container,
|
|
53
|
-
})).rejects.toThrow(/Cannot select multiple options on a single-select element/);
|
|
54
|
-
});
|
|
55
|
-
it('throws when neither element nor label is provided', async () => {
|
|
56
|
-
const { container } = render({ template: singleTemplate });
|
|
57
|
-
await expect(setSelectElementItems({ selectedOptionValues: ['apple'], withinElement: container })).rejects.toThrow(/a select element or its associated label is required/);
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=setSelectElementItems.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setSelectElementItems.spec.js","sourceRoot":"src/","sources":["utils/__tests__/setSelectElementItems.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAC7D,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAE7D,MAAM,cAAc,GAAG;;;;;;;;;CAStB,CAAC;AAEF,MAAM,gBAAgB,GAAG;;;;;;;;;CASxB,CAAC;AAEF,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;IACpD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3D,MAAM,qBAAqB,CAAC;QAC1B,KAAK,EAAE,OAAO;QACd,oBAAoB,EAAE,CAAC,OAAO,CAAC;QAC/B,aAAa,EAAE,SAAwB;KACxC,CAAC,CA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AAE,GAAG,MAAM,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC;IAC3D,MAAM,MAAM,CACV,qBAAqB,CAAC,EAAE,oBAAoB,EAAE,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,SAAwB,EAAE,CAAC,CACpG,CAAC,OAAO,CAAC,OAAO,CAAC,sDAAsD,CAAC,CAAC;AAC5E,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/vue';
|
|
2
|
-
import getSelectElementItems from '../getSelectElementItems';
|
|
3
|
-
import setSelectElementRandomItems from '../setSelectElementRandomItems';
|
|
4
|
-
const template = `
|
|
5
|
-
<div>
|
|
6
|
-
<label for="fruit-select">Fruits</label>
|
|
7
|
-
<select id="fruit-select" multiple>
|
|
8
|
-
<option value="apple">Apple</option>
|
|
9
|
-
<option value="banana">Banana</option>
|
|
10
|
-
<option value="cherry">Cherry</option>
|
|
11
|
-
</select>
|
|
12
|
-
</div>
|
|
13
|
-
`;
|
|
14
|
-
it('selects random options by label', async () => {
|
|
15
|
-
const { container } = render({ template });
|
|
16
|
-
const select = screen.getByLabelText('Fruits');
|
|
17
|
-
const selected = await setSelectElementRandomItems({
|
|
18
|
-
label: 'Fruits',
|
|
19
|
-
numOfItems: 2,
|
|
20
|
-
withinElement: container,
|
|
21
|
-
});
|
|
22
|
-
expect(getSelectElementItems({ element: select, withinElement: container })).toEqual(expect.arrayContaining(selected));
|
|
23
|
-
expect(selected).toHaveLength(2);
|
|
24
|
-
});
|
|
25
|
-
it('selects random options by element', async () => {
|
|
26
|
-
const { container } = render({ template });
|
|
27
|
-
const select = screen.getByLabelText('Fruits');
|
|
28
|
-
const selected = await setSelectElementRandomItems({
|
|
29
|
-
element: select,
|
|
30
|
-
numOfItems: 1,
|
|
31
|
-
withinElement: container,
|
|
32
|
-
});
|
|
33
|
-
expect(getSelectElementItems({ element: select, withinElement: container })).toEqual(expect.arrayContaining(selected));
|
|
34
|
-
expect(selected).toHaveLength(1);
|
|
35
|
-
});
|
|
36
|
-
it('throws when requesting more items than available', async () => {
|
|
37
|
-
const { container } = render({ template });
|
|
38
|
-
await expect(setSelectElementRandomItems({
|
|
39
|
-
label: 'Fruits',
|
|
40
|
-
numOfItems: 5,
|
|
41
|
-
withinElement: container,
|
|
42
|
-
})).rejects.toThrow();
|
|
43
|
-
});
|
|
44
|
-
it('throws when neither element nor label is provided', async () => {
|
|
45
|
-
const { container } = render({ template });
|
|
46
|
-
await expect(setSelectElementRandomItems({ numOfItems: 1, withinElement: container })).rejects.toThrow();
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=setSelectElementRandomItems.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setSelectElementRandomItems.spec.js","sourceRoot":"src/","sources":["utils/__tests__/setSelectElementRandomItems.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAC7D,OAAO,2BAA2B,MAAM,gCAAgC,CAAC;AAEzE,MAAM,QAAQ,GAAG;;;;;;;;;CAShB,CAAC;AAEF,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;IAC/C,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAoB,QAAQ,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,MAAM,2BAA2B,CAAC;QACjD,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,CAAC;QACb,aAAa,EAAE,SAAwB;KACxC,CAAC,CAAC;IAEH,MAAM,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAwB,EAAE,CAA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BAA2B,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,aAAa,EAAE,SAAwB,EAAE,CAAC,CACxF,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AACtB,CAAC,CAAC,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export interface AssertSelectElementItemsArgs {
|
|
2
|
-
/** The select element to check. If omitted, `label` is used to find it. */
|
|
3
|
-
element?: HTMLSelectElement;
|
|
4
|
-
/** Accessible name of the select element; used when `element` is not provided. */
|
|
5
|
-
label?: string;
|
|
6
|
-
/** Expected selected value or array of values. */
|
|
7
|
-
values: string | string[];
|
|
8
|
-
/** Root container to scope the query; defaults to document.body. */
|
|
9
|
-
withinElement?: HTMLElement;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Asserts that the selected values of a <select> element match the expected values.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* // single value
|
|
17
|
-
* assertSelectElementItems({
|
|
18
|
-
* label: 'Fruits',
|
|
19
|
-
* values: 'apple',
|
|
20
|
-
* withinElement: container,
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
* // multiple values
|
|
24
|
-
* assertSelectElementItems({
|
|
25
|
-
* label: 'Fruits',
|
|
26
|
-
* values: ['apple', 'banana'],
|
|
27
|
-
* withinElement: container,
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* // using element directly
|
|
31
|
-
* const select = container.querySelector<HTMLSelectElement>('#fruit-select');
|
|
32
|
-
* assertSelectElementItems({
|
|
33
|
-
* element: selectElement,
|
|
34
|
-
* values: ['apple', 'banana'],
|
|
35
|
-
* withinElement: container,
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @param options Options for assertion.
|
|
40
|
-
* @param [options.element] The select element to check. If omitted, `label` is used to find it.
|
|
41
|
-
* @param [options.label] Accessible name of the select element; used when `element` is not provided.
|
|
42
|
-
* @param options.values Expected selected value or array of values.
|
|
43
|
-
* @param [options.withinElement] Root container to scope the query; defaults to document.body.
|
|
44
|
-
* @returns void
|
|
45
|
-
*/
|
|
46
|
-
export default function assertSelectElementItems({ element, label, values, withinElement, }: AssertSelectElementItemsArgs): void;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import getSelectElementItems from './getSelectElementItems';
|
|
2
|
-
/**
|
|
3
|
-
* Asserts that the selected values of a <select> element match the expected values.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* // single value
|
|
8
|
-
* assertSelectElementItems({
|
|
9
|
-
* label: 'Fruits',
|
|
10
|
-
* values: 'apple',
|
|
11
|
-
* withinElement: container,
|
|
12
|
-
* });
|
|
13
|
-
*
|
|
14
|
-
* // multiple values
|
|
15
|
-
* assertSelectElementItems({
|
|
16
|
-
* label: 'Fruits',
|
|
17
|
-
* values: ['apple', 'banana'],
|
|
18
|
-
* withinElement: container,
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* // using element directly
|
|
22
|
-
* const select = container.querySelector<HTMLSelectElement>('#fruit-select');
|
|
23
|
-
* assertSelectElementItems({
|
|
24
|
-
* element: selectElement,
|
|
25
|
-
* values: ['apple', 'banana'],
|
|
26
|
-
* withinElement: container,
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param options Options for assertion.
|
|
31
|
-
* @param [options.element] The select element to check. If omitted, `label` is used to find it.
|
|
32
|
-
* @param [options.label] Accessible name of the select element; used when `element` is not provided.
|
|
33
|
-
* @param options.values Expected selected value or array of values.
|
|
34
|
-
* @param [options.withinElement] Root container to scope the query; defaults to document.body.
|
|
35
|
-
* @returns void
|
|
36
|
-
*/
|
|
37
|
-
export default function assertSelectElementItems({ element, label, values, withinElement, }) {
|
|
38
|
-
const selectedValues = getSelectElementItems({ element, label, withinElement });
|
|
39
|
-
const expectedValues = typeof values === 'string' ? [values] : values;
|
|
40
|
-
// Assert the selectedOptions match exactly
|
|
41
|
-
expect(selectedValues).toEqual(expectedValues);
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=assertSelectElementItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertSelectElementItems.js","sourceRoot":"src/","sources":["utils/assertSelectElementItems.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAa5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,EAC/C,OAAO,EACP,KAAK,EACL,MAAM,EACN,aAAa,GACgB;IAC7B,MAAM,cAAc,GAAG,qBAAqB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IAChF,MAAM,cAAc,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAEtE,2CAA2C;IAC3C,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves multiple items from an array without selecting the same element twice.
|
|
3
|
-
*
|
|
4
|
-
* @param arr The array to pick items from.
|
|
5
|
-
* @param numOfItemsToSelect Number of unique items to select.
|
|
6
|
-
* @returns An array of selected items.
|
|
7
|
-
*/
|
|
8
|
-
export default function getRandomItemsFromArray<T>(arr: T[], numOfItemsToSelect: number): T[];
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves multiple items from an array without selecting the same element twice.
|
|
3
|
-
*
|
|
4
|
-
* @param arr The array to pick items from.
|
|
5
|
-
* @param numOfItemsToSelect Number of unique items to select.
|
|
6
|
-
* @returns An array of selected items.
|
|
7
|
-
*/
|
|
8
|
-
export default function getRandomItemsFromArray(arr, numOfItemsToSelect) {
|
|
9
|
-
if (arr.length < numOfItemsToSelect) {
|
|
10
|
-
throw new Error(`Cannot select ${numOfItemsToSelect} unique items from an array that only has ${arr.length} items`);
|
|
11
|
-
}
|
|
12
|
-
const copiedArray = [...arr];
|
|
13
|
-
const selectedItems = [];
|
|
14
|
-
while (selectedItems.length < numOfItemsToSelect) {
|
|
15
|
-
// Get a random index
|
|
16
|
-
const index = Math.floor(Math.random() * copiedArray.length);
|
|
17
|
-
// Remove the item from the array so we don't select it again
|
|
18
|
-
const itemSelected = copiedArray.splice(index, 1);
|
|
19
|
-
selectedItems.push(itemSelected[0]);
|
|
20
|
-
}
|
|
21
|
-
return selectedItems;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=getRandomItemsFromArray.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRandomItemsFromArray.js","sourceRoot":"src/","sources":["utils/getRandomItemsFromArray.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAI,GAAQ,EAAE,kBAA0B;IACrF,IAAI,GAAG,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,iBAAiB,kBAAkB,6CAA6C,GAAG,CAAC,MAAM,QAAQ,CAAC,CAAC;IACtH,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;IAE7B,MAAM,aAAa,GAAQ,EAAE,CAAC;IAC9B,OAAO,aAAa,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;QACjD,qBAAqB;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAE7D,6DAA6D;QAC7D,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAClD,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves a <select> element by its associated label text.
|
|
3
|
-
*
|
|
4
|
-
* @param label The text of the label to find the select element.
|
|
5
|
-
* @param [withinElement] Root container to scope the query; defaults to document body.
|
|
6
|
-
* @returns The matched select element or null.
|
|
7
|
-
*/
|
|
8
|
-
export default function getSelectElementByLabel(label: string, withinElement?: HTMLElement): HTMLSelectElement | null;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { within } from '@testing-library/vue';
|
|
2
|
-
/**
|
|
3
|
-
* Retrieves a <select> element by its associated label text.
|
|
4
|
-
*
|
|
5
|
-
* @param label The text of the label to find the select element.
|
|
6
|
-
* @param [withinElement] Root container to scope the query; defaults to document body.
|
|
7
|
-
* @returns The matched select element or null.
|
|
8
|
-
*/
|
|
9
|
-
export default function getSelectElementByLabel(label, withinElement) {
|
|
10
|
-
if (!label) {
|
|
11
|
-
throw new Error('A select element or its associated label is required.');
|
|
12
|
-
}
|
|
13
|
-
let selectElement;
|
|
14
|
-
const scope = {
|
|
15
|
-
...within(withinElement || document.body),
|
|
16
|
-
element: withinElement || document.body,
|
|
17
|
-
};
|
|
18
|
-
if (scope.queryAllByLabelText(label, { selector: 'select', exact: false }).length === 1) {
|
|
19
|
-
selectElement = scope.queryByLabelText(label, { selector: 'select', exact: false });
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
// Escapes metacharacters in the provided regular expression
|
|
23
|
-
const escapedLabel = label.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').trim();
|
|
24
|
-
// Multiple elements could have the label (like a placeholder)
|
|
25
|
-
const elementsWithLabelText = scope.getAllByText(new RegExp(`^${escapedLabel.replace(/\s/g, '\\s')}$`, 'i'));
|
|
26
|
-
// Find the label within the matching elements
|
|
27
|
-
const selectLabel = elementsWithLabelText.find((e) => e.tagName.toLowerCase() === 'label');
|
|
28
|
-
if (!selectLabel) {
|
|
29
|
-
throw new Error(`Could not find label with text ${label}`);
|
|
30
|
-
}
|
|
31
|
-
const labelFor = selectLabel.getAttribute('for');
|
|
32
|
-
// LL Select is a huge pain to get selected correctly. Using query selectors for now
|
|
33
|
-
// eslint-disable-next-line testing-library/no-node-access
|
|
34
|
-
selectElement = scope.element.querySelector(`#${labelFor}`);
|
|
35
|
-
}
|
|
36
|
-
return selectElement;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=getSelectElementByLabel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSelectElementByLabel.js","sourceRoot":"src/","sources":["utils/getSelectElementByLabel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,KAAa,EAAE,aAA2B;IACxF,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,aAAuC,CAAC;IAE5C,MAAM,KAAK,GAAG;QACZ,GAAG,MAAM,CAAC,aAAa,IAAI,QAAQ,CAAC,IAAI,CAAC;QACzC,OAAO,EAAE,aAAa,IAAI,QAAQ,CAAC,IAAI;KACxC,CAAC;IAEF,IAAI,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxF,aAAa,GAAG,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACtF,CAAC;SAAM,CAAC;QACN,4DAA4D;QAC5D,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAEzE,8DAA8D;QAC9D,MAAM,qBAAqB,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAE7G,8CAA8C;QAC9C,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,CAAC;QAE3F,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,QAAQ,GAAG,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAEjD,qFAAqF;QACrF,0DAA0D;QAC1D,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAoB,IAAI,QAAQ,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface GetSelectElementItemsArgs {
|
|
2
|
-
/** The select element to query. */
|
|
3
|
-
element?: HTMLSelectElement;
|
|
4
|
-
/** Accessible name to find the select element. */
|
|
5
|
-
label?: string;
|
|
6
|
-
/** Root container to scope the query; defaults to document.body. */
|
|
7
|
-
withinElement?: HTMLElement;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Returns the selected option values from a <select> element.
|
|
11
|
-
*
|
|
12
|
-
* @param args Options for retrieving selected items.
|
|
13
|
-
* @param [args.element] The select element to query.
|
|
14
|
-
* @param [args.label] Accessible name to find the select element.
|
|
15
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
16
|
-
* @returns The array of selected option values.
|
|
17
|
-
*/
|
|
18
|
-
export default function getSelectElementItems({ element, label, withinElement }: GetSelectElementItemsArgs): string[];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import getSelectElementOptions from './getSelectElementOptions';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the selected option values from a <select> element.
|
|
4
|
-
*
|
|
5
|
-
* @param args Options for retrieving selected items.
|
|
6
|
-
* @param [args.element] The select element to query.
|
|
7
|
-
* @param [args.label] Accessible name to find the select element.
|
|
8
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
9
|
-
* @returns The array of selected option values.
|
|
10
|
-
*/
|
|
11
|
-
export default function getSelectElementItems({ element, label, withinElement }) {
|
|
12
|
-
const options = getSelectElementOptions({
|
|
13
|
-
element,
|
|
14
|
-
label,
|
|
15
|
-
withinElement,
|
|
16
|
-
});
|
|
17
|
-
return options.filter(({ selected }) => Boolean(selected)).map(({ value }) => value);
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=getSelectElementItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSelectElementItems.js","sourceRoot":"src/","sources":["utils/getSelectElementItems.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAWhE;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAA6B;IACxG,MAAM,OAAO,GAAG,uBAAuB,CAAC;QACtC,OAAO;QACP,KAAK;QACL,aAAa;KACd,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface GetSelectElementOptionsArgs {
|
|
2
|
-
/** Accessible name to find the select element. */
|
|
3
|
-
label?: string;
|
|
4
|
-
/** The select element to query. */
|
|
5
|
-
element?: HTMLSelectElement;
|
|
6
|
-
/** Root container to scope the query; defaults to document.body. */
|
|
7
|
-
withinElement?: HTMLElement;
|
|
8
|
-
/** Exclude disabled options if true. */
|
|
9
|
-
excludeDisabled?: boolean;
|
|
10
|
-
/** Exclude empty-value options if true. */
|
|
11
|
-
excludeEmpty?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Returns the array of <option> elements from a <select> element.
|
|
15
|
-
*
|
|
16
|
-
* @param args Options for retrieving select element options.
|
|
17
|
-
* @param [args.element] The select element to query.
|
|
18
|
-
* @param [args.label] Accessible name to find the select element.
|
|
19
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
20
|
-
* @param [args.excludeDisabled] Exclude disabled options if true.
|
|
21
|
-
* @param [args.excludeEmpty] Exclude empty-value options if true.
|
|
22
|
-
* @returns The array of option elements.
|
|
23
|
-
*/
|
|
24
|
-
export default function getSelectElementOptions({ element, label, withinElement, excludeDisabled, excludeEmpty, }?: GetSelectElementOptionsArgs): HTMLOptionElement[];
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { within } from '@testing-library/vue';
|
|
2
|
-
import getSelectElementByLabel from './getSelectElementByLabel';
|
|
3
|
-
/**
|
|
4
|
-
* Returns the array of <option> elements from a <select> element.
|
|
5
|
-
*
|
|
6
|
-
* @param args Options for retrieving select element options.
|
|
7
|
-
* @param [args.element] The select element to query.
|
|
8
|
-
* @param [args.label] Accessible name to find the select element.
|
|
9
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
10
|
-
* @param [args.excludeDisabled] Exclude disabled options if true.
|
|
11
|
-
* @param [args.excludeEmpty] Exclude empty-value options if true.
|
|
12
|
-
* @returns The array of option elements.
|
|
13
|
-
*/
|
|
14
|
-
export default function getSelectElementOptions({ element, label, withinElement, excludeDisabled = false, excludeEmpty = true, } = {}) {
|
|
15
|
-
let selectElement = null;
|
|
16
|
-
if (element) {
|
|
17
|
-
selectElement = element;
|
|
18
|
-
}
|
|
19
|
-
else if (label) {
|
|
20
|
-
selectElement = getSelectElementByLabel(label, withinElement);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
throw new Error('a select element or its associated label is required.');
|
|
24
|
-
}
|
|
25
|
-
if (!selectElement) {
|
|
26
|
-
throw new Error('Could not find select element');
|
|
27
|
-
}
|
|
28
|
-
const options = within(selectElement)
|
|
29
|
-
.getAllByRole('option')
|
|
30
|
-
.filter((opt) => {
|
|
31
|
-
if (excludeDisabled && opt.disabled) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return (excludeEmpty && opt.value !== '') || true;
|
|
35
|
-
});
|
|
36
|
-
return options;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=getSelectElementOptions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSelectElementOptions.js","sourceRoot":"src/","sources":["utils/getSelectElementOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAehE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,EAC9C,OAAO,EACP,KAAK,EACL,aAAa,EACb,eAAe,GAAG,KAAK,EACvB,YAAY,GAAG,IAAI,MACY,EAAE;IACjC,IAAI,aAAa,GAA6B,IAAI,CAAC;IAEnD,IAAI,OAAO,EAAE,CAAC;QACZ,aAAa,GAAG,OAAO,CAAC;IAC1B,CAAC;SAAM,IAAI,KAAK,EAAE,CAAC;QACjB,aAAa,GAAG,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC;SAClC,YAAY,CAAoB,QAAQ,CAAC;SACzC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QACd,IAAI,eAAe,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,CAAC,YAAY,IAAI,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,IAAI,IAAI,CAAC;IACpD,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type GetSelectElementOptionsArgs } from './getSelectElementOptions';
|
|
2
|
-
export type GetSelectElementValuesArgs = GetSelectElementOptionsArgs;
|
|
3
|
-
/**
|
|
4
|
-
* Returns the values of options from a <select> element.
|
|
5
|
-
*
|
|
6
|
-
* @param args Options for retrieving select element values.
|
|
7
|
-
* @param [args.element] The select element to query.
|
|
8
|
-
* @param [args.label] Accessible name to find the select element.
|
|
9
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
10
|
-
* @param [args.excludeDisabled] Exclude disabled options if true.
|
|
11
|
-
* @param [args.excludeEmpty] Exclude empty-value options if true.
|
|
12
|
-
* @returns The array of option values.
|
|
13
|
-
*/
|
|
14
|
-
export default function getSelectElementValues({ element, label, withinElement, excludeDisabled, excludeEmpty, }?: GetSelectElementValuesArgs): string[];
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import getSelectElementOptions from './getSelectElementOptions';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the values of options from a <select> element.
|
|
4
|
-
*
|
|
5
|
-
* @param args Options for retrieving select element values.
|
|
6
|
-
* @param [args.element] The select element to query.
|
|
7
|
-
* @param [args.label] Accessible name to find the select element.
|
|
8
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
9
|
-
* @param [args.excludeDisabled] Exclude disabled options if true.
|
|
10
|
-
* @param [args.excludeEmpty] Exclude empty-value options if true.
|
|
11
|
-
* @returns The array of option values.
|
|
12
|
-
*/
|
|
13
|
-
export default function getSelectElementValues({ element, label, withinElement, excludeDisabled = false, excludeEmpty = true, } = {}) {
|
|
14
|
-
const options = getSelectElementOptions({
|
|
15
|
-
element,
|
|
16
|
-
label,
|
|
17
|
-
withinElement,
|
|
18
|
-
excludeDisabled,
|
|
19
|
-
excludeEmpty,
|
|
20
|
-
});
|
|
21
|
-
return options.map(({ value }) => value);
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=getSelectElementValues.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSelectElementValues.js","sourceRoot":"src/","sources":["utils/getSelectElementValues.ts"],"names":[],"mappings":"AAAA,OAAO,uBAA6D,MAAM,2BAA2B,CAAC;AAItG;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAC7C,OAAO,EACP,KAAK,EACL,aAAa,EACb,eAAe,GAAG,KAAK,EACvB,YAAY,GAAG,IAAI,MACW,EAAE;IAChC,MAAM,OAAO,GAAG,uBAAuB,CAAC;QACtC,OAAO;QACP,KAAK;QACL,aAAa;QACb,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface SetSelectElementItemsArgs {
|
|
2
|
-
/** The select element to target. If omitted, `label` is used to find it. */
|
|
3
|
-
element?: HTMLSelectElement;
|
|
4
|
-
/** Accessible name of the select element; used when `element` is not provided. */
|
|
5
|
-
label?: string;
|
|
6
|
-
/** Array of values to select. */
|
|
7
|
-
selectedOptionValues: string[];
|
|
8
|
-
/** Root container to scope the query. */
|
|
9
|
-
withinElement?: HTMLElement;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Sets the selected option values on a <select> element.
|
|
13
|
-
*
|
|
14
|
-
* @param args Options for setting select items.
|
|
15
|
-
* @param [args.element] The select element to target. If omitted, `label` is used to find it.
|
|
16
|
-
* @param [args.label] Accessible name of the select element; used when `element` is not provided.
|
|
17
|
-
* @param args.selectedOptionValues Array of values to select.
|
|
18
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
19
|
-
* @returns Promise<void>
|
|
20
|
-
*/
|
|
21
|
-
export default function setSelectElementItems({ element, label, selectedOptionValues, withinElement, }: SetSelectElementItemsArgs): Promise<void>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import userEvent from '@testing-library/user-event';
|
|
2
|
-
import getSelectElementByLabel from './getSelectElementByLabel';
|
|
3
|
-
/**
|
|
4
|
-
* Sets the selected option values on a <select> element.
|
|
5
|
-
*
|
|
6
|
-
* @param args Options for setting select items.
|
|
7
|
-
* @param [args.element] The select element to target. If omitted, `label` is used to find it.
|
|
8
|
-
* @param [args.label] Accessible name of the select element; used when `element` is not provided.
|
|
9
|
-
* @param args.selectedOptionValues Array of values to select.
|
|
10
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
11
|
-
* @returns Promise<void>
|
|
12
|
-
*/
|
|
13
|
-
export default async function setSelectElementItems({ element, label, selectedOptionValues, withinElement, }) {
|
|
14
|
-
let selectElement = null;
|
|
15
|
-
if (element) {
|
|
16
|
-
selectElement = element;
|
|
17
|
-
}
|
|
18
|
-
else if (label) {
|
|
19
|
-
selectElement = getSelectElementByLabel(label, withinElement);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
throw new Error('A select element or its associated label is required.');
|
|
23
|
-
}
|
|
24
|
-
if (!selectElement) {
|
|
25
|
-
throw new Error('Could not find select element');
|
|
26
|
-
}
|
|
27
|
-
else if (!selectElement.multiple && selectedOptionValues.length > 1) {
|
|
28
|
-
throw new Error('Cannot select multiple options on a single-select element');
|
|
29
|
-
}
|
|
30
|
-
await userEvent.selectOptions(selectElement, selectedOptionValues);
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=setSelectElementItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setSelectElementItems.js","sourceRoot":"src/","sources":["utils/setSelectElementItems.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAEpD,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAahE;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,qBAAqB,CAAC,EAClD,OAAO,EACP,KAAK,EACL,oBAAoB,EACpB,aAAa,GACa;IAC1B,IAAI,aAAa,GAA6B,IAAI,CAAC;IAEnD,IAAI,OAAO,EAAE,CAAC;QACZ,aAAa,GAAG,OAAO,CAAC;IAC1B,CAAC;SAAM,IAAI,KAAK,EAAE,CAAC;QACjB,aAAa,GAAG,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;SAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,SAAS,CAAC,aAAa,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface SetSelectElementRandomItemsArgs {
|
|
2
|
-
/** The select element to target. If omitted, `label` is used to find it. */
|
|
3
|
-
element?: HTMLSelectElement;
|
|
4
|
-
/** Accessible name of the select element; used when element is not provided. */
|
|
5
|
-
label?: string;
|
|
6
|
-
/** Number of items to randomly select. */
|
|
7
|
-
numOfItems: number;
|
|
8
|
-
/** Root container to scope the query; defaults to document.body. */
|
|
9
|
-
withinElement?: HTMLElement;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Sets a random selection of options on a <select> element.
|
|
13
|
-
*
|
|
14
|
-
* @param args Options for random selection.
|
|
15
|
-
* @param [args.element] The select element to target. If omitted, `label` is used to find it.
|
|
16
|
-
* @param [args.label] Accessible name of the select element; used when element is not provided.
|
|
17
|
-
* @param args.numOfItems Number of items to randomly select.
|
|
18
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
19
|
-
* @returns The array of selected option values.
|
|
20
|
-
*/
|
|
21
|
-
export default function setSelectElementRandomItems({ element, label, numOfItems, withinElement, }: SetSelectElementRandomItemsArgs): Promise<string[]>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import userEvent from '@testing-library/user-event';
|
|
2
|
-
import getRandomItemsFromArray from './getRandomItemsFromArray';
|
|
3
|
-
import getSelectElementByLabel from './getSelectElementByLabel';
|
|
4
|
-
import getSelectElementOptions from './getSelectElementOptions';
|
|
5
|
-
/**
|
|
6
|
-
* Sets a random selection of options on a <select> element.
|
|
7
|
-
*
|
|
8
|
-
* @param args Options for random selection.
|
|
9
|
-
* @param [args.element] The select element to target. If omitted, `label` is used to find it.
|
|
10
|
-
* @param [args.label] Accessible name of the select element; used when element is not provided.
|
|
11
|
-
* @param args.numOfItems Number of items to randomly select.
|
|
12
|
-
* @param [args.withinElement] Root container to scope the query; defaults to document.body.
|
|
13
|
-
* @returns The array of selected option values.
|
|
14
|
-
*/
|
|
15
|
-
export default async function setSelectElementRandomItems({ element, label, numOfItems, withinElement, }) {
|
|
16
|
-
let selectElement = null;
|
|
17
|
-
if (element) {
|
|
18
|
-
selectElement = element;
|
|
19
|
-
}
|
|
20
|
-
else if (label) {
|
|
21
|
-
selectElement = getSelectElementByLabel(label, withinElement);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
throw new Error('A select element or its associated label is required.');
|
|
25
|
-
}
|
|
26
|
-
if (!selectElement) {
|
|
27
|
-
throw new Error('Could not find the select element');
|
|
28
|
-
}
|
|
29
|
-
// Clear the drop down
|
|
30
|
-
await userEvent.deselectOptions(selectElement, [...selectElement.selectedOptions].map(({ value }) => value));
|
|
31
|
-
// Exclude empty option from our available value choices
|
|
32
|
-
const availableOptions = getSelectElementOptions({ element, label, withinElement, excludeEmpty: true });
|
|
33
|
-
// Make sure we have enough options
|
|
34
|
-
if (availableOptions.length < numOfItems) {
|
|
35
|
-
throw new Error(`Not enough options to select ${numOfItems} from the select element`);
|
|
36
|
-
}
|
|
37
|
-
const selectedOptionValues = getRandomItemsFromArray(availableOptions, numOfItems);
|
|
38
|
-
await userEvent.selectOptions(selectElement, selectedOptionValues);
|
|
39
|
-
return selectedOptionValues.map(({ value }) => value);
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=setSelectElementRandomItems.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setSelectElementRandomItems.js","sourceRoot":"src/","sources":["utils/setSelectElementRandomItems.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAEpD,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAChE,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAChE,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAahE;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,2BAA2B,CAAC,EACxD,OAAO,EACP,KAAK,EACL,UAAU,EACV,aAAa,GACmB;IAChC,IAAI,aAAa,GAA6B,IAAI,CAAC;IAEnD,IAAI,OAAO,EAAE,CAAC;QACZ,aAAa,GAAG,OAA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