@mtes-mct/monitor-ui 24.33.0 → 24.34.0
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/CHANGELOG.md +16 -0
- package/fields/DatePicker/index.d.ts +1 -1
- package/fields/DatePicker/index.d.ts.map +1 -1
- package/fields/DateRangePicker/index.d.ts +1 -1
- package/fields/DateRangePicker/index.d.ts.map +1 -1
- package/formiks/FormikDatePicker.d.ts +1 -0
- package/formiks/FormikDatePicker.d.ts.map +1 -1
- package/formiks/FormikDateRangePicker.d.ts +1 -0
- package/formiks/FormikDateRangePicker.d.ts.map +1 -1
- package/global.d.ts +48 -0
- package/icons/Settings.d.ts +3 -0
- package/icons/Settings.d.ts.map +1 -0
- package/icons/index.d.ts +2 -1
- package/icons/index.d.ts.map +1 -1
- package/index.js +15852 -30768
- package/package.json +3 -3
- package/stats.html +4 -0
- package/cypress/global.d.ts +0 -122
- package/cypress/index.js +0 -1145
package/cypress/index.js
DELETED
|
@@ -1,1145 +0,0 @@
|
|
|
1
|
-
// I have no idea why I have to add this dirty hack of setting an external variable
|
|
2
|
-
// instead of using a cleaner FP `.filter()`
|
|
3
|
-
// but real experience made me think it greatly improves results stability.
|
|
4
|
-
function findElementByText(selector, text, { fallbackSelector, index = 0, inElement } = {}) {
|
|
5
|
-
const trimmedText = text.trim();
|
|
6
|
-
if (inElement) {
|
|
7
|
-
let foundElement;
|
|
8
|
-
let foundElementIndex = 0;
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
10
|
-
Cypress.$(inElement).find(selector)// eslint-disable-next-line func-names
|
|
11
|
-
.each(function() {
|
|
12
|
-
if (!foundElement && Cypress.$(this).text().trim() === trimmedText) {
|
|
13
|
-
if (foundElementIndex < index) {
|
|
14
|
-
foundElementIndex += 1;
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
foundElement = this;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
if (!foundElement && fallbackSelector) {
|
|
21
|
-
cy.log(`⚠️ Using fallback selector: "${fallbackSelector}"`);
|
|
22
|
-
const foundElementByFallbackSelector = Cypress.$(inElement).find(fallbackSelector);
|
|
23
|
-
return foundElementByFallbackSelector;
|
|
24
|
-
}
|
|
25
|
-
return foundElement;
|
|
26
|
-
}
|
|
27
|
-
let foundElement;
|
|
28
|
-
let foundElementIndex = 0;
|
|
29
|
-
// eslint-disable-next-line func-names, @typescript-eslint/no-unused-expressions
|
|
30
|
-
Cypress.$(selector).each(function() {
|
|
31
|
-
if (!foundElement && Cypress.$(this).text().trim() === trimmedText) {
|
|
32
|
-
if (foundElementIndex < index) {
|
|
33
|
-
foundElementIndex += 1;
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
foundElement = this;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (!foundElement && fallbackSelector) {
|
|
40
|
-
// eslint-disable-next-line no-console
|
|
41
|
-
console.warn(`Using fallback selector: "${fallbackSelector}".`);
|
|
42
|
-
const foundElementByFallbackSelector = Cypress.$(fallbackSelector);
|
|
43
|
-
return foundElementByFallbackSelector;
|
|
44
|
-
}
|
|
45
|
-
return foundElement;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const RETRIES = 5;
|
|
49
|
-
function findButton(label, preSelector, { index, prevSubjectElement }) {
|
|
50
|
-
const buttonElement = findElementByText(`${preSelector}button`, label, {
|
|
51
|
-
index,
|
|
52
|
-
inElement: prevSubjectElement
|
|
53
|
-
});
|
|
54
|
-
if (buttonElement) {
|
|
55
|
-
return buttonElement;
|
|
56
|
-
}
|
|
57
|
-
const buttonElementByAriaLabel = prevSubjectElement ? prevSubjectElement.querySelectorAll(`${preSelector}button[aria-label="${label}"]`)[index] : Cypress.$(`${preSelector}button[aria-label="${label}"]`).get(index);
|
|
58
|
-
if (buttonElementByAriaLabel) {
|
|
59
|
-
return buttonElementByAriaLabel;
|
|
60
|
-
}
|
|
61
|
-
const buttonElementByTitle = prevSubjectElement ? prevSubjectElement.querySelectorAll(`${preSelector}button[title="${label}"]`)[index] : Cypress.$(`${preSelector}button[title="${label}"]`).get(index);
|
|
62
|
-
if (buttonElementByTitle) {
|
|
63
|
-
return buttonElementByTitle;
|
|
64
|
-
}
|
|
65
|
-
const buttonRoleElement = findElementByText(`${preSelector}[role="button"]`, label, {
|
|
66
|
-
index,
|
|
67
|
-
inElement: prevSubjectElement
|
|
68
|
-
});
|
|
69
|
-
if (buttonRoleElement) {
|
|
70
|
-
return buttonRoleElement;
|
|
71
|
-
}
|
|
72
|
-
const buttonRoleElementByAriaLabel = prevSubjectElement ? prevSubjectElement.querySelectorAll(`${preSelector}[role="button"][aria-label="${label}"]`)[index] : Cypress.$(`${preSelector}[role="button"][aria-label="${label}"]`).get(index);
|
|
73
|
-
if (buttonRoleElementByAriaLabel) {
|
|
74
|
-
return buttonRoleElementByAriaLabel;
|
|
75
|
-
}
|
|
76
|
-
const buttonRoleElementByTitle = prevSubjectElement ? prevSubjectElement.querySelectorAll(`${preSelector}[role="button"][title="${label}"]`)[index] : Cypress.$(`${preSelector}[role="button"][title="${label}"]`).get(index);
|
|
77
|
-
if (buttonRoleElementByTitle) {
|
|
78
|
-
return buttonRoleElementByTitle;
|
|
79
|
-
}
|
|
80
|
-
const menuItemRoleElement = findElementByText(`${preSelector}[role="menuitem"]`, label, {
|
|
81
|
-
index,
|
|
82
|
-
inElement: prevSubjectElement
|
|
83
|
-
});
|
|
84
|
-
if (menuItemRoleElement) {
|
|
85
|
-
return menuItemRoleElement;
|
|
86
|
-
}
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
function clickButton(prevSubjectElements, label, { index = 0, withinSelector, withoutScroll = false } = {}, leftRetries = RETRIES) {
|
|
90
|
-
const prevSubjectElement = prevSubjectElements ? prevSubjectElements[0] : undefined;
|
|
91
|
-
if (prevSubjectElements && !prevSubjectElements[0]) {
|
|
92
|
-
throw new Error('`prevSubjectElements[0]` is undefined.');
|
|
93
|
-
}
|
|
94
|
-
const preSelector = withinSelector ? `${withinSelector} ` : '';
|
|
95
|
-
const maybeButton = findButton(label, preSelector, {
|
|
96
|
-
index,
|
|
97
|
-
prevSubjectElement
|
|
98
|
-
});
|
|
99
|
-
if (maybeButton) {
|
|
100
|
-
return (withoutScroll ? cy.wrap(maybeButton).forceClick() : cy.wrap(maybeButton).scrollIntoView().forceClick()).wait(250);
|
|
101
|
-
}
|
|
102
|
-
if (leftRetries > 0) {
|
|
103
|
-
return cy.wait(250).then(()=>{
|
|
104
|
-
cy.log(`Retrying (${RETRIES - leftRetries + 1} / ${RETRIES})...`);
|
|
105
|
-
return clickButton(prevSubjectElements, label, {
|
|
106
|
-
index,
|
|
107
|
-
withinSelector,
|
|
108
|
-
withoutScroll
|
|
109
|
-
}, leftRetries - 1);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
throw new Error(`Unable to find button with label "${label}".`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function clickLink(linkText) {
|
|
116
|
-
return cy.get('a').contains(linkText).click();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @description
|
|
121
|
-
* Useful to close modals.
|
|
122
|
-
*/ function clickOutside(xPosition = 0, yPosition = 0) {
|
|
123
|
-
cy.log(`Click outside at position: ${xPosition}, ${yPosition}`);
|
|
124
|
-
cy.get('body').click(xPosition, yPosition, {
|
|
125
|
-
force: true
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const MAX_PARENT_INDEX = 100;
|
|
130
|
-
function findElementParentBySelector(element, parentSelector, index = 0) {
|
|
131
|
-
let currentParentElement = element;
|
|
132
|
-
let lastFoundParentIndex = 0;
|
|
133
|
-
let parentIndex = -1;
|
|
134
|
-
while(parentIndex < MAX_PARENT_INDEX){
|
|
135
|
-
parentIndex += 1;
|
|
136
|
-
currentParentElement = currentParentElement.parentElement;
|
|
137
|
-
if (!currentParentElement) {
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
if (currentParentElement.matches(parentSelector)) {
|
|
141
|
-
if (lastFoundParentIndex === index) {
|
|
142
|
-
return currentParentElement;
|
|
143
|
-
}
|
|
144
|
-
lastFoundParentIndex += 1;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function checkCheckbox(fieldElement, value, _label, force) {
|
|
151
|
-
Cypress.log({
|
|
152
|
-
consoleProps: ()=>({
|
|
153
|
-
'Applied to': fieldElement,
|
|
154
|
-
Elements: 1
|
|
155
|
-
}),
|
|
156
|
-
name: 'checkCheckbox'
|
|
157
|
-
});
|
|
158
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
159
|
-
offset: {
|
|
160
|
-
left: 0,
|
|
161
|
-
top: -100
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
if (value) {
|
|
165
|
-
cy.wrap(fieldElement).find('input[type="checkbox"]').check({
|
|
166
|
-
force
|
|
167
|
-
}).wait(250);
|
|
168
|
-
} else {
|
|
169
|
-
cy.wrap(fieldElement).find('input[type="checkbox"]').uncheck({
|
|
170
|
-
force
|
|
171
|
-
}).wait(250);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function checkMultiCheckboxOptions(fieldsetElement, values, _label, force) {
|
|
176
|
-
Cypress.log({
|
|
177
|
-
consoleProps: ()=>({
|
|
178
|
-
'Applied to': fieldsetElement,
|
|
179
|
-
Elements: 1
|
|
180
|
-
}),
|
|
181
|
-
name: 'checkMultiCheckboxOptions'
|
|
182
|
-
});
|
|
183
|
-
cy.wrap(fieldsetElement).scrollIntoView({
|
|
184
|
-
offset: {
|
|
185
|
-
left: 0,
|
|
186
|
-
top: -100
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
cy.wrap(fieldsetElement).find('input[type="checkbox"]').uncheck({
|
|
190
|
-
force
|
|
191
|
-
}).wait(250);
|
|
192
|
-
// If `values` is undefined, we don't need to check anything
|
|
193
|
-
if (!values) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
values.forEach((value)=>{
|
|
197
|
-
cy.wrap(fieldsetElement).contains('.rs-checkbox-label', value).closest('.rs-checkbox').find('input[type="checkbox"]').check({
|
|
198
|
-
force
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
cy.wait(250);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function checkMultiRadioOption(fieldsetElement, value, _label, force) {
|
|
205
|
-
Cypress.log({
|
|
206
|
-
consoleProps: ()=>({
|
|
207
|
-
'Applied to': fieldsetElement,
|
|
208
|
-
Elements: 1
|
|
209
|
-
}),
|
|
210
|
-
name: 'checkMultiRadioOption'
|
|
211
|
-
});
|
|
212
|
-
cy.wrap(fieldsetElement).scrollIntoView({
|
|
213
|
-
offset: {
|
|
214
|
-
left: 0,
|
|
215
|
-
top: -100
|
|
216
|
-
}
|
|
217
|
-
}).find('label').contains(value).click({
|
|
218
|
-
force
|
|
219
|
-
}).wait(250);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const DEFAULT_OPTIONS = {
|
|
223
|
-
delay: 10,
|
|
224
|
-
force: true,
|
|
225
|
-
index: 0,
|
|
226
|
-
retries: 5
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
function throwError(message) {
|
|
230
|
-
throw new Error(`[monitor-ui > Cypress] ${message}`);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function fillDatePicker(fieldsetElement, dateOrDateWithTimeTuple, _label, force, delay) {
|
|
234
|
-
Cypress.log({
|
|
235
|
-
consoleProps: ()=>({
|
|
236
|
-
'Applied to': fieldsetElement,
|
|
237
|
-
Elements: 1
|
|
238
|
-
}),
|
|
239
|
-
name: 'fillDatePicker'
|
|
240
|
-
});
|
|
241
|
-
const inputElements = fieldsetElement.querySelectorAll('input');
|
|
242
|
-
if (inputElements.length !== 4 && inputElements.length !== 6) {
|
|
243
|
-
throwError(`Expected to find 4 or 6 inputs within in DatePicker but found ${inputElements.length}.`);
|
|
244
|
-
}
|
|
245
|
-
const hasTimeInputs = inputElements.length === 6;
|
|
246
|
-
// Empty the inputs if `dateOrDateWithTimeTuple` is undefined
|
|
247
|
-
if (!dateOrDateWithTimeTuple) {
|
|
248
|
-
// -------------------------------------------------------------------------
|
|
249
|
-
// Date without time
|
|
250
|
-
cy.wrap(fieldsetElement).find('[aria-label="Jour"]').clear({
|
|
251
|
-
force
|
|
252
|
-
});
|
|
253
|
-
cy.wrap(fieldsetElement).find('[aria-label="Mois"]').clear({
|
|
254
|
-
force
|
|
255
|
-
});
|
|
256
|
-
cy.wrap(fieldsetElement).find('[aria-label="Année"]').clear({
|
|
257
|
-
force
|
|
258
|
-
});
|
|
259
|
-
if (hasTimeInputs) {
|
|
260
|
-
cy.wrap(fieldsetElement).find('[aria-label="Heure"]').clear({
|
|
261
|
-
force
|
|
262
|
-
});
|
|
263
|
-
cy.wrap(fieldsetElement).find('[aria-label="Minute"]').clear({
|
|
264
|
-
force
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
} else {
|
|
268
|
-
const [year, month, day] = dateOrDateWithTimeTuple;
|
|
269
|
-
cy.wrap(fieldsetElement).find('[aria-label="Jour"]').type(String(day).padStart(2, '0'), {
|
|
270
|
-
delay,
|
|
271
|
-
force
|
|
272
|
-
});
|
|
273
|
-
cy.wrap(fieldsetElement).find('[aria-label="Mois"]').type(String(month).padStart(2, '0'), {
|
|
274
|
-
delay,
|
|
275
|
-
force
|
|
276
|
-
});
|
|
277
|
-
cy.wrap(fieldsetElement).find('[aria-label="Année"]').type(String(year), {
|
|
278
|
-
delay,
|
|
279
|
-
force
|
|
280
|
-
});
|
|
281
|
-
if (hasTimeInputs) {
|
|
282
|
-
const [hour, minute] = dateOrDateWithTimeTuple.slice(3);
|
|
283
|
-
cy.wrap(fieldsetElement).find('[aria-label="Heure"]').type(String(hour).padStart(2, '0'), {
|
|
284
|
-
delay,
|
|
285
|
-
force
|
|
286
|
-
});
|
|
287
|
-
cy.wrap(fieldsetElement).find('[aria-label="Minute"]').type(String(minute).padStart(2, '0'), {
|
|
288
|
-
delay,
|
|
289
|
-
force
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
cy.wait(250);
|
|
294
|
-
// Close the calendar & ranged time picker popup by pressing the escape key
|
|
295
|
-
cy.get('body').type('{esc}', {
|
|
296
|
-
delay,
|
|
297
|
-
force
|
|
298
|
-
});
|
|
299
|
-
// TODO Create a util to handle the `fieldsetElement` re-creation cases.
|
|
300
|
-
// We to use a `wait` as a temporary fix to handle `fieldsetElement` re-creation cases.
|
|
301
|
-
cy.wait(250);
|
|
302
|
-
// cy.wrap(fieldsetElement).find('.Field-DatePicker__CalendarPicker').should('not.be.visible')
|
|
303
|
-
// cy.wrap(fieldsetElement).find('.Field-DateRangePicker__RangedTimePicker').should('not.exist')
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function fillDateRangePicker(fieldsetElement, dateOrDateWithTimeTupleRange, _label, force, delay) {
|
|
307
|
-
Cypress.log({
|
|
308
|
-
consoleProps: ()=>({
|
|
309
|
-
'Applied to': fieldsetElement,
|
|
310
|
-
Elements: 1
|
|
311
|
-
}),
|
|
312
|
-
name: 'fillDateRangePicker'
|
|
313
|
-
});
|
|
314
|
-
const inputElements = fieldsetElement.querySelectorAll('input');
|
|
315
|
-
if (inputElements.length !== 7 && inputElements.length !== 11) {
|
|
316
|
-
throwError(`Expected to find 7 or 11 inputs within in DatePicker but found ${inputElements.length}.`);
|
|
317
|
-
}
|
|
318
|
-
const hasTimeInput = inputElements.length !== 7;
|
|
319
|
-
// Empty the inputs if `dateOrDateWithTimeTupleRange` is undefined
|
|
320
|
-
if (!dateOrDateWithTimeTupleRange) {
|
|
321
|
-
cy.wrap(fieldsetElement).find('[aria-label="Jour de début"]').clear({
|
|
322
|
-
force
|
|
323
|
-
});
|
|
324
|
-
cy.wrap(fieldsetElement).find('[aria-label="Mois de début"]').clear({
|
|
325
|
-
force
|
|
326
|
-
});
|
|
327
|
-
cy.wrap(fieldsetElement).find('[aria-label="Année de début"]').clear({
|
|
328
|
-
force
|
|
329
|
-
});
|
|
330
|
-
if (hasTimeInput) {
|
|
331
|
-
cy.wrap(fieldsetElement).find('[aria-label="Heure de début"]').clear({
|
|
332
|
-
force
|
|
333
|
-
});
|
|
334
|
-
cy.wrap(fieldsetElement).find('[aria-label="Minute de début"]').clear({
|
|
335
|
-
force
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
cy.wrap(fieldsetElement).find('[aria-label="Jour de fin"]').clear({
|
|
339
|
-
force
|
|
340
|
-
});
|
|
341
|
-
cy.wrap(fieldsetElement).find('[aria-label="Mois de fin"]').clear({
|
|
342
|
-
force
|
|
343
|
-
});
|
|
344
|
-
cy.wrap(fieldsetElement).find('[aria-label="Année de fin"]').clear({
|
|
345
|
-
force
|
|
346
|
-
});
|
|
347
|
-
if (hasTimeInput) {
|
|
348
|
-
cy.wrap(fieldsetElement).find('[aria-label="Heure de fin"]').clear({
|
|
349
|
-
force
|
|
350
|
-
});
|
|
351
|
-
cy.wrap(fieldsetElement).find('[aria-label="Minute de fin"]').clear({
|
|
352
|
-
force
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
} else {
|
|
356
|
-
const [startDateOrDateWithTimeTuple, endDateOrDateWithTimeTuple] = dateOrDateWithTimeTupleRange;
|
|
357
|
-
const [startYear, startMonth, startDay, startHour, startMinute] = startDateOrDateWithTimeTuple;
|
|
358
|
-
const [endYear, endMonth, endDay, endHour, endMinute] = endDateOrDateWithTimeTuple;
|
|
359
|
-
cy.wrap(fieldsetElement).find('[aria-label="Jour de début"]').type(String(startDay).padStart(2, '0'), {
|
|
360
|
-
delay,
|
|
361
|
-
force
|
|
362
|
-
});
|
|
363
|
-
cy.wrap(fieldsetElement).find('[aria-label="Mois de début"]').type(String(startMonth).padStart(2, '0'), {
|
|
364
|
-
delay,
|
|
365
|
-
force
|
|
366
|
-
});
|
|
367
|
-
cy.wrap(fieldsetElement).find('[aria-label="Année de début"]').type(String(startYear), {
|
|
368
|
-
force
|
|
369
|
-
});
|
|
370
|
-
if (hasTimeInput) {
|
|
371
|
-
cy.wrap(fieldsetElement).find('[aria-label="Heure de début"]').type(String(startHour).padStart(2, '0'), {
|
|
372
|
-
delay,
|
|
373
|
-
force
|
|
374
|
-
});
|
|
375
|
-
cy.wrap(fieldsetElement).find('[aria-label="Minute de début"]').type(String(startMinute).padStart(2, '0'), {
|
|
376
|
-
force
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
cy.wrap(fieldsetElement).find('[aria-label="Jour de fin"]').type(String(endDay).padStart(2, '0'), {
|
|
380
|
-
delay,
|
|
381
|
-
force
|
|
382
|
-
});
|
|
383
|
-
cy.wrap(fieldsetElement).find('[aria-label="Mois de fin"]').type(String(endMonth).padStart(2, '0'), {
|
|
384
|
-
delay,
|
|
385
|
-
force
|
|
386
|
-
});
|
|
387
|
-
cy.wrap(fieldsetElement).find('[aria-label="Année de fin"]').type(String(endYear), {
|
|
388
|
-
force
|
|
389
|
-
});
|
|
390
|
-
if (hasTimeInput) {
|
|
391
|
-
cy.wrap(fieldsetElement).find('[aria-label="Heure de fin"]').type(String(endHour).padStart(2, '0'), {
|
|
392
|
-
delay,
|
|
393
|
-
force
|
|
394
|
-
});
|
|
395
|
-
cy.wrap(fieldsetElement).find('[aria-label="Minute de fin"]').type(String(endMinute).padStart(2, '0'), {
|
|
396
|
-
delay,
|
|
397
|
-
force
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
cy.wait(250);
|
|
402
|
-
// Close the range calendar & ranged time picker popup by pressing the escape key
|
|
403
|
-
cy.get('body').type('{esc}', {
|
|
404
|
-
delay,
|
|
405
|
-
force
|
|
406
|
-
});
|
|
407
|
-
// TODO Create a util to handle the `fieldsetElement` re-creation cases.
|
|
408
|
-
// We to use a `wait` as a temporary fix to handle `fieldsetElement` re-creation cases.
|
|
409
|
-
cy.wait(250);
|
|
410
|
-
// cy.wrap(fieldsetElement).find('.Field-DateRangePicker__RangeCalendarPicker').should('not.be.visible')
|
|
411
|
-
// cy.wrap(fieldsetElement).find('.Field-DateRangePicker__RangedTimePicker').should('not.exist')
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function fillNumberInput(fieldElement, value, _label, force, delay) {
|
|
415
|
-
Cypress.log({
|
|
416
|
-
consoleProps: ()=>({
|
|
417
|
-
'Applied to': fieldElement,
|
|
418
|
-
Elements: 1
|
|
419
|
-
}),
|
|
420
|
-
name: 'fillNumberInput'
|
|
421
|
-
});
|
|
422
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
423
|
-
offset: {
|
|
424
|
-
left: 0,
|
|
425
|
-
top: -100
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
cy.wrap(fieldElement).find('input[type="number"]').clear({
|
|
429
|
-
force
|
|
430
|
-
}).wait(250);
|
|
431
|
-
// If `value` is undefined, we don't need to input anything
|
|
432
|
-
if (!value) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
cy.wrap(fieldElement).find('input[type="number"]').type(String(value), {
|
|
436
|
-
delay,
|
|
437
|
-
force
|
|
438
|
-
}).wait(250);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function fillTextarea(fieldElement, value, _label, force, delay) {
|
|
442
|
-
Cypress.log({
|
|
443
|
-
consoleProps: ()=>({
|
|
444
|
-
'Applied to': fieldElement,
|
|
445
|
-
Elements: 1
|
|
446
|
-
}),
|
|
447
|
-
name: 'fillTextarea'
|
|
448
|
-
});
|
|
449
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
450
|
-
offset: {
|
|
451
|
-
left: 0,
|
|
452
|
-
top: -100
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
cy.wrap(fieldElement).find('textarea').clear({
|
|
456
|
-
force
|
|
457
|
-
}).wait(250);
|
|
458
|
-
// If `value` is undefined, we don't need to input anything
|
|
459
|
-
if (!value) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
cy.wrap(fieldElement).find('textarea').type(value, {
|
|
463
|
-
delay,
|
|
464
|
-
force
|
|
465
|
-
}).wait(250);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
function fillTextInput(fieldElement, value, _label, force, delay) {
|
|
469
|
-
Cypress.log({
|
|
470
|
-
consoleProps: ()=>({
|
|
471
|
-
'Applied to': fieldElement,
|
|
472
|
-
Elements: 1
|
|
473
|
-
}),
|
|
474
|
-
name: 'fillTextInput'
|
|
475
|
-
});
|
|
476
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
477
|
-
offset: {
|
|
478
|
-
left: 0,
|
|
479
|
-
top: -100
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
cy.wrap(fieldElement).find('input').clear({
|
|
483
|
-
force
|
|
484
|
-
}).wait(250);
|
|
485
|
-
// If `value` is undefined, we don't need to input anything
|
|
486
|
-
if (!value) {
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
cy.wrap(fieldElement).find('input').type(value, {
|
|
490
|
-
delay,
|
|
491
|
-
force
|
|
492
|
-
}).wait(250);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function pickCheckPickerOptions(fieldElement, values, label, force, delay, role = 'option') {
|
|
496
|
-
Cypress.log({
|
|
497
|
-
consoleProps: ()=>({
|
|
498
|
-
'Applied to': fieldElement,
|
|
499
|
-
Elements: 1
|
|
500
|
-
}),
|
|
501
|
-
name: 'pickCheckPickerOptions'
|
|
502
|
-
});
|
|
503
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
504
|
-
offset: {
|
|
505
|
-
left: 0,
|
|
506
|
-
top: -100
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
// Clear the field if there is a clear button
|
|
510
|
-
const maybeClearButton = fieldElement.querySelector('.rs-stack > .rs-stack-item > .rs-picker-clean');
|
|
511
|
-
if (maybeClearButton) {
|
|
512
|
-
cy.wrap(fieldElement).find('.rs-stack > .rs-stack-item > .rs-picker-clean').click({
|
|
513
|
-
force
|
|
514
|
-
}).wait(250);
|
|
515
|
-
}
|
|
516
|
-
// If `values` is undefined, we don't need to select anything
|
|
517
|
-
if (!values) {
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
cy.wrap(fieldElement).find('.rs-picker-toggle').click({
|
|
521
|
-
force
|
|
522
|
-
});
|
|
523
|
-
// Wait for the picker to open
|
|
524
|
-
cy.wrap(fieldElement).find('.rs-picker-popup').then(([rsuitePickerPopupElement])=>{
|
|
525
|
-
if (!rsuitePickerPopupElement) {
|
|
526
|
-
throwError(`Could not find '.rs-picker-popup' in in field with label "${label}". Did the picker open?`);
|
|
527
|
-
}
|
|
528
|
-
// Search for the value if there is a search input
|
|
529
|
-
const maybeSearchInput = rsuitePickerPopupElement.querySelector('input[role="searchbox"]');
|
|
530
|
-
values.forEach((value)=>{
|
|
531
|
-
if (maybeSearchInput) {
|
|
532
|
-
cy.wrap(rsuitePickerPopupElement).find('input[role="searchbox"]').clear().type(value, {
|
|
533
|
-
delay,
|
|
534
|
-
force
|
|
535
|
-
}).wait(250);
|
|
536
|
-
}
|
|
537
|
-
cy.wrap(rsuitePickerPopupElement).find(`[role="${role}"]`).contains(value).first().scrollIntoView().click({
|
|
538
|
-
force
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
// Close the picker popup by pressing the escape key
|
|
542
|
-
cy.get('body').type('{esc}', {
|
|
543
|
-
delay,
|
|
544
|
-
force
|
|
545
|
-
});
|
|
546
|
-
// TODO Create a util to handle the `fieldElement` re-creation cases.
|
|
547
|
-
// We to use a `wait` as a temporary fix to handle `fieldElement` re-creation cases.
|
|
548
|
-
cy.wait(250);
|
|
549
|
-
// cy.wrap(fieldElement).find('.rs-picker-popup').should('not.exist')
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function pickMultiCascaderOptions(fieldElement, values, label, force, delay) {
|
|
554
|
-
Cypress.log({
|
|
555
|
-
consoleProps: ()=>({
|
|
556
|
-
'Applied to': fieldElement,
|
|
557
|
-
Elements: 1
|
|
558
|
-
}),
|
|
559
|
-
name: 'pickMultiCascaderOptions'
|
|
560
|
-
});
|
|
561
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
562
|
-
offset: {
|
|
563
|
-
left: 0,
|
|
564
|
-
top: -100
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
// Clear the field if there is a clear button
|
|
568
|
-
const maybeClearButton = fieldElement.querySelector('.rs-stack > .rs-stack-item > .rs-picker-clean');
|
|
569
|
-
if (maybeClearButton) {
|
|
570
|
-
cy.wrap(fieldElement).find('.rs-stack > .rs-stack-item > .rs-picker-clean').click({
|
|
571
|
-
force
|
|
572
|
-
}).wait(250);
|
|
573
|
-
}
|
|
574
|
-
// If `values` is undefined, we don't need to select anything
|
|
575
|
-
if (!values) {
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
cy.wrap(fieldElement).find('.rs-picker-toggle').click({
|
|
579
|
-
force
|
|
580
|
-
});
|
|
581
|
-
// Wait for the picker to open
|
|
582
|
-
cy.wrap(fieldElement).find('.rs-picker-popup').then(([rsuitePickerPopupElement])=>{
|
|
583
|
-
if (!rsuitePickerPopupElement) {
|
|
584
|
-
throwError(`Could not find '.rs-picker-popup' in in field with label "${label}". Did the picker open?`);
|
|
585
|
-
}
|
|
586
|
-
// Search for the value if there is a search input
|
|
587
|
-
const maybeSearchInput = rsuitePickerPopupElement.querySelector('input[role="searchbox"]');
|
|
588
|
-
if (!maybeSearchInput) {
|
|
589
|
-
throwError(throwError(`\`cy.fill()\` can't handle the MultiCascader with \`<label>\` "${label}" because it's not \`searchable\`.`));
|
|
590
|
-
}
|
|
591
|
-
values.forEach((value)=>{
|
|
592
|
-
cy.wrap(rsuitePickerPopupElement).find('input[role="searchbox"]').clear().type(value, {
|
|
593
|
-
delay,
|
|
594
|
-
force
|
|
595
|
-
}).wait(250);
|
|
596
|
-
cy.wrap(rsuitePickerPopupElement).find('[role="treeitem"]').contains(value).first().scrollIntoView().click({
|
|
597
|
-
force
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
// Close the picker popup by pressing the escape key
|
|
601
|
-
cy.get('body').type('{esc}', {
|
|
602
|
-
delay,
|
|
603
|
-
force
|
|
604
|
-
});
|
|
605
|
-
// TODO Create a util to handle the `fieldElement` re-creation cases.
|
|
606
|
-
// We to use a `wait` as a temporary fix to handle `fieldElement` re-creation cases.
|
|
607
|
-
cy.wait(250);
|
|
608
|
-
// cy.wrap(fieldElement).find('.rs-picker-popup').should('not.exist')
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
function pickMultiSelectOptions(fieldElement, values, label, force, delay) {
|
|
613
|
-
Cypress.log({
|
|
614
|
-
consoleProps: ()=>({
|
|
615
|
-
'Applied to': fieldElement,
|
|
616
|
-
Elements: 1
|
|
617
|
-
}),
|
|
618
|
-
name: 'pickMultiSelectOptions'
|
|
619
|
-
});
|
|
620
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
621
|
-
offset: {
|
|
622
|
-
left: 0,
|
|
623
|
-
top: -100
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
// Clear the field if there is a clear button
|
|
627
|
-
const maybeClearButton = fieldElement.querySelector('.rs-stack > .rs-stack-item > .rs-picker-clean');
|
|
628
|
-
if (maybeClearButton) {
|
|
629
|
-
cy.wrap(fieldElement).find('.rs-stack > .rs-stack-item > .rs-picker-clean').click({
|
|
630
|
-
force
|
|
631
|
-
}).wait(250);
|
|
632
|
-
}
|
|
633
|
-
// If `values` is undefined, we don't need to select anything
|
|
634
|
-
if (!values) {
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
cy.wrap(fieldElement).find('.rs-picker-toggle').click({
|
|
638
|
-
force
|
|
639
|
-
});
|
|
640
|
-
// Wait for the picker to open
|
|
641
|
-
cy.wrap(fieldElement).get('.rs-picker-popup').then(([rsuitePickerPopupElement])=>{
|
|
642
|
-
if (!rsuitePickerPopupElement) {
|
|
643
|
-
throwError(`Could not find '.rs-picker-popup' in in field with label "${label}". Did the picker open?`);
|
|
644
|
-
}
|
|
645
|
-
values.forEach((value)=>{
|
|
646
|
-
// Search for the value if there is a search input
|
|
647
|
-
const maybeSearchInput = fieldElement.querySelector('.rs-picker-search-input > input');
|
|
648
|
-
if (maybeSearchInput) {
|
|
649
|
-
cy.wrap(fieldElement).find('.rs-picker-search-input > input').type(value, {
|
|
650
|
-
delay,
|
|
651
|
-
force
|
|
652
|
-
}).wait(250);
|
|
653
|
-
}
|
|
654
|
-
cy.wrap(rsuitePickerPopupElement).find('[role="option"]').contains(value).first().scrollIntoView().click({
|
|
655
|
-
force
|
|
656
|
-
});
|
|
657
|
-
});
|
|
658
|
-
// Close the picker popup by pressing the escape key
|
|
659
|
-
cy.get('body').type('{esc}', {
|
|
660
|
-
delay,
|
|
661
|
-
force
|
|
662
|
-
});
|
|
663
|
-
// TODO Create a util to handle the `fieldElement` re-creation cases.
|
|
664
|
-
// We to use a `wait` as a temporary fix to handle `fieldElement` re-creation cases.
|
|
665
|
-
cy.wait(250);
|
|
666
|
-
// cy.wrap(fieldElement).find('.rs-picker-popup').should('not.exist')
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function pickSearchOption(fieldElement, value, _label, force, delay) {
|
|
671
|
-
Cypress.log({
|
|
672
|
-
consoleProps: ()=>({
|
|
673
|
-
'Applied to': fieldElement,
|
|
674
|
-
Elements: 1
|
|
675
|
-
}),
|
|
676
|
-
name: 'pickSearchOption'
|
|
677
|
-
});
|
|
678
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
679
|
-
offset: {
|
|
680
|
-
left: 0,
|
|
681
|
-
top: -100
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
// Clear the field if there is a clear button
|
|
685
|
-
const maybeClearButton = fieldElement.querySelector('.Field-Search__ClearButton');
|
|
686
|
-
if (maybeClearButton) {
|
|
687
|
-
cy.wrap(fieldElement).find('.Field-Search__ClearButton').click({
|
|
688
|
-
force
|
|
689
|
-
}).wait(250);
|
|
690
|
-
}
|
|
691
|
-
// If the value is undefined, we don't need to select anything
|
|
692
|
-
if (!value) {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
// Search for the value
|
|
696
|
-
cy.wrap(fieldElement).find('input[role="combobox"]').type(value, {
|
|
697
|
-
delay,
|
|
698
|
-
force
|
|
699
|
-
});
|
|
700
|
-
// Wait for the picker to open
|
|
701
|
-
cy.wrap(fieldElement).get('.rs-picker-popup').then(([rsuitePickerPopupElement])=>{
|
|
702
|
-
// Select the first picker option
|
|
703
|
-
cy.wrap(rsuitePickerPopupElement).find('[role="option"]').first().scrollIntoView().click({
|
|
704
|
-
force
|
|
705
|
-
}).wait(250);
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
function pickSelectOption(fieldElement, value, label, force, delay) {
|
|
710
|
-
Cypress.log({
|
|
711
|
-
consoleProps: ()=>({
|
|
712
|
-
'Applied to': fieldElement,
|
|
713
|
-
Elements: 1
|
|
714
|
-
}),
|
|
715
|
-
name: 'pickSelectOption'
|
|
716
|
-
});
|
|
717
|
-
cy.wrap(fieldElement).scrollIntoView({
|
|
718
|
-
offset: {
|
|
719
|
-
left: 0,
|
|
720
|
-
top: -100
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
// Clear the field if there is a clear button
|
|
724
|
-
const maybeClearButton = fieldElement.querySelector('.rs-stack > .rs-stack-item > .rs-picker-clean');
|
|
725
|
-
if (maybeClearButton) {
|
|
726
|
-
cy.wrap(fieldElement).find('.rs-stack > .rs-stack-item > .rs-picker-clean').click({
|
|
727
|
-
force
|
|
728
|
-
}).wait(250);
|
|
729
|
-
}
|
|
730
|
-
// If the value is undefined, we don't need to select anything
|
|
731
|
-
if (!value) {
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
// Open the picker
|
|
735
|
-
cy.wrap(fieldElement).find('.rs-stack > .rs-stack-item > .rs-picker-caret-icon').click({
|
|
736
|
-
force
|
|
737
|
-
}).wait(250);
|
|
738
|
-
// Wait for the picker to open
|
|
739
|
-
cy.wrap(fieldElement).get('.rs-picker-popup').then(([rsuitePickerPopupElement])=>{
|
|
740
|
-
if (!rsuitePickerPopupElement) {
|
|
741
|
-
throwError(`Could not find '.rs-picker-popup' in in field with label "${label}". Did the picker open?`);
|
|
742
|
-
}
|
|
743
|
-
// Search for the value if there is a search input
|
|
744
|
-
const maybeSearchInput = rsuitePickerPopupElement.querySelector('input[role="searchbox"]');
|
|
745
|
-
if (maybeSearchInput) {
|
|
746
|
-
cy.wrap(rsuitePickerPopupElement).find('input[role="searchbox"]').type(value, {
|
|
747
|
-
delay,
|
|
748
|
-
force
|
|
749
|
-
}).wait(250);
|
|
750
|
-
}
|
|
751
|
-
cy.wrap(rsuitePickerPopupElement).find('[role="option"]').contains(value).scrollIntoView().click({
|
|
752
|
-
force
|
|
753
|
-
}).wait(250);
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
const throwAssertionError = (expectedType, component)=>throwError(`\`value\` should be of type \`${expectedType}\` in \`cy.fill(label, value)\` when used on a <${component} />.`);
|
|
758
|
-
function assertBooleanOrUndefined(value, component) {
|
|
759
|
-
if (value === undefined || typeof value === 'boolean') {
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
throwAssertionError('boolean | undefined', component);
|
|
763
|
-
}
|
|
764
|
-
function assertDateTupleOrDateWithTimeTupleOrUndefined(value, component) {
|
|
765
|
-
if (value === undefined) {
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
if (Array.isArray(value) && (value.length === 3 || value.length === 5) && value.every((valueItem)=>typeof valueItem === 'number')) {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
throwAssertionError('DateTuple | DateWithTimeTuple | undefined', component);
|
|
772
|
-
}
|
|
773
|
-
function assertDateRangeTupleOrDateWithTimeRangeTupleOrUndefined(value, component) {
|
|
774
|
-
if (value === undefined) {
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
if (Array.isArray(value) && value.length === 2 && (Array.isArray(value[0]) && value[0].length === 3 && value[1].length === 3 || Array.isArray(value[0]) && value[0].length === 5 && value[1].length === 5) && value.every((valueItem)=>Array.isArray(valueItem) && valueItem.every((valueItemItem)=>typeof valueItemItem === 'number'))) {
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
throwAssertionError('DateRangeTuple | DateWithTimeRangeTuple | undefined', component);
|
|
781
|
-
}
|
|
782
|
-
function assertNumberOrUndefined(value, component) {
|
|
783
|
-
if (value === undefined || typeof value === 'number') {
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
throwAssertionError('number | undefined', component);
|
|
787
|
-
}
|
|
788
|
-
function assertString(value, component) {
|
|
789
|
-
if (typeof value === 'string') {
|
|
790
|
-
return;
|
|
791
|
-
}
|
|
792
|
-
throwAssertionError('string', component);
|
|
793
|
-
}
|
|
794
|
-
function assertStringOrUndefined(value, component) {
|
|
795
|
-
if (value === undefined || typeof value === 'string') {
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
throwAssertionError('string | undefined', component);
|
|
799
|
-
}
|
|
800
|
-
function assertStringArrayOrUndefined(value, component) {
|
|
801
|
-
if (value === undefined) {
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
if (Array.isArray(value) && value.every((valueItem)=>typeof valueItem === 'string')) {
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
throwAssertionError('string[] | undefined', component);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
let TOTAL_RETRIES;
|
|
811
|
-
function fill(label, value, options = {}) {
|
|
812
|
-
const controlledOptions = {
|
|
813
|
-
...DEFAULT_OPTIONS,
|
|
814
|
-
...options
|
|
815
|
-
};
|
|
816
|
-
if (!TOTAL_RETRIES) {
|
|
817
|
-
TOTAL_RETRIES = controlledOptions.retries;
|
|
818
|
-
}
|
|
819
|
-
Cypress.log({
|
|
820
|
-
consoleProps: ()=>({
|
|
821
|
-
'Left Retries': controlledOptions.retries
|
|
822
|
-
}),
|
|
823
|
-
message: `Filling field with label/legend "${label}" with value "${JSON.stringify(value)}".`,
|
|
824
|
-
name: 'fill'
|
|
825
|
-
});
|
|
826
|
-
try {
|
|
827
|
-
// =========================================================================
|
|
828
|
-
// If it's a field labelled by a `<label />` element
|
|
829
|
-
const labelElement = findElementByText('label', label, {
|
|
830
|
-
index: controlledOptions.index
|
|
831
|
-
});
|
|
832
|
-
if (labelElement) {
|
|
833
|
-
const fieldElement = findElementParentBySelector(labelElement, '.Element-Field');
|
|
834
|
-
if (!fieldElement) {
|
|
835
|
-
throwError(`Could not find '.Element-Field' in field with label "${label}" at index "${controlledOptions.index}".`);
|
|
836
|
-
}
|
|
837
|
-
switch(true){
|
|
838
|
-
// ---------------------------------------------------------------------
|
|
839
|
-
// Checkbox
|
|
840
|
-
case fieldElement.classList.contains('Field-Checkbox'):
|
|
841
|
-
assertBooleanOrUndefined(value, 'Checkbox');
|
|
842
|
-
checkCheckbox(fieldElement, value, label, controlledOptions.force);
|
|
843
|
-
return;
|
|
844
|
-
// ---------------------------------------------------------------------
|
|
845
|
-
// CheckPicker
|
|
846
|
-
case fieldElement.classList.contains('Field-CheckPicker'):
|
|
847
|
-
assertStringArrayOrUndefined(value, 'CheckPicker');
|
|
848
|
-
pickCheckPickerOptions(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
849
|
-
return;
|
|
850
|
-
// ---------------------------------------------------------------------
|
|
851
|
-
// CheckTreePicker
|
|
852
|
-
case fieldElement.classList.contains('Field-CheckTreePicker'):
|
|
853
|
-
assertStringArrayOrUndefined(value, 'CheckTreePicker');
|
|
854
|
-
pickCheckPickerOptions(fieldElement, value, label, controlledOptions.force, controlledOptions.delay, 'treeitem');
|
|
855
|
-
return;
|
|
856
|
-
// ---------------------------------------------------------------------
|
|
857
|
-
// MultiCascader
|
|
858
|
-
case fieldElement.classList.contains('Field-MultiCascader'):
|
|
859
|
-
assertStringArrayOrUndefined(value, 'MultiCascader');
|
|
860
|
-
pickMultiCascaderOptions(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
861
|
-
return;
|
|
862
|
-
// ---------------------------------------------------------------------
|
|
863
|
-
// MultiSelect
|
|
864
|
-
case fieldElement.classList.contains('Field-MultiSelect'):
|
|
865
|
-
assertStringArrayOrUndefined(value, 'MultiSelect');
|
|
866
|
-
pickMultiSelectOptions(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
867
|
-
return;
|
|
868
|
-
// ---------------------------------------------------------------------
|
|
869
|
-
// Search
|
|
870
|
-
case fieldElement.classList.contains('Field-Search'):
|
|
871
|
-
assertStringOrUndefined(value, 'Search');
|
|
872
|
-
pickSearchOption(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
873
|
-
return;
|
|
874
|
-
// ---------------------------------------------------------------------
|
|
875
|
-
// Select
|
|
876
|
-
case fieldElement.classList.contains('Field-Select'):
|
|
877
|
-
assertStringOrUndefined(value, 'Select');
|
|
878
|
-
pickSelectOption(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
879
|
-
return;
|
|
880
|
-
// ---------------------------------------------------------------------
|
|
881
|
-
// NumberInput
|
|
882
|
-
case fieldElement.classList.contains('Field-NumberInput'):
|
|
883
|
-
assertNumberOrUndefined(value, 'TextInput');
|
|
884
|
-
fillNumberInput(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
885
|
-
return;
|
|
886
|
-
// ---------------------------------------------------------------------
|
|
887
|
-
// Textarea
|
|
888
|
-
case fieldElement.classList.contains('Field-Textarea'):
|
|
889
|
-
assertStringOrUndefined(value, 'Textarea');
|
|
890
|
-
fillTextarea(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
891
|
-
return;
|
|
892
|
-
// ---------------------------------------------------------------------
|
|
893
|
-
// TextInput
|
|
894
|
-
case fieldElement.classList.contains('Field-TextInput'):
|
|
895
|
-
assertStringOrUndefined(value, 'TextInput');
|
|
896
|
-
fillTextInput(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
897
|
-
return;
|
|
898
|
-
// ---------------------------------------------------------------------
|
|
899
|
-
// PhoneInput
|
|
900
|
-
case fieldElement.classList.contains('Field-PhoneInput'):
|
|
901
|
-
assertStringOrUndefined(value, 'PhoneInput');
|
|
902
|
-
fillTextInput(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
903
|
-
return;
|
|
904
|
-
// ---------------------------------------------------------------------
|
|
905
|
-
// LinkInput
|
|
906
|
-
case fieldElement.classList.contains('Field-LinkInput'):
|
|
907
|
-
assertStringOrUndefined(value, 'LinkInput');
|
|
908
|
-
fillTextInput(fieldElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
909
|
-
return;
|
|
910
|
-
default:
|
|
911
|
-
throwError(`\`cy.fill()\` can't handle field with \`<label>\` "${label}".`);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
// =========================================================================
|
|
915
|
-
// If it's a field labelled by a `<legend />` element
|
|
916
|
-
const legendElement = findElementByText('legend', label, {
|
|
917
|
-
index: controlledOptions.index
|
|
918
|
-
});
|
|
919
|
-
if (legendElement) {
|
|
920
|
-
const fieldsetElement = findElementParentBySelector(legendElement, '.Element-Fieldset');
|
|
921
|
-
if (!fieldsetElement) {
|
|
922
|
-
throwError(`Could not find '.Element-Fieldset' in field with \`<legend />\` "${label}" at index "${controlledOptions.index}".`);
|
|
923
|
-
}
|
|
924
|
-
switch(true){
|
|
925
|
-
// ---------------------------------------------------------------------
|
|
926
|
-
// DatePicker
|
|
927
|
-
case fieldsetElement.classList.contains('Field-DatePicker'):
|
|
928
|
-
assertDateTupleOrDateWithTimeTupleOrUndefined(value, 'DatePicker');
|
|
929
|
-
fillDatePicker(fieldsetElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
930
|
-
return;
|
|
931
|
-
// ---------------------------------------------------------------------
|
|
932
|
-
// DateRangePicker
|
|
933
|
-
case fieldsetElement.classList.contains('Field-DateRangePicker'):
|
|
934
|
-
assertDateRangeTupleOrDateWithTimeRangeTupleOrUndefined(value, 'DateRangePicker');
|
|
935
|
-
fillDateRangePicker(fieldsetElement, value, label, controlledOptions.force, controlledOptions.delay);
|
|
936
|
-
return;
|
|
937
|
-
// ---------------------------------------------------------------------
|
|
938
|
-
// MultiCheckbox
|
|
939
|
-
case fieldsetElement.classList.contains('Field-MultiCheckbox'):
|
|
940
|
-
assertStringArrayOrUndefined(value, 'MultiCheckbox');
|
|
941
|
-
checkMultiCheckboxOptions(fieldsetElement, value, label, controlledOptions.force);
|
|
942
|
-
return;
|
|
943
|
-
// ---------------------------------------------------------------------
|
|
944
|
-
// MultiRadio
|
|
945
|
-
case fieldsetElement.classList.contains('Field-MultiRadio'):
|
|
946
|
-
assertString(value, 'MultiRadio');
|
|
947
|
-
checkMultiRadioOption(fieldsetElement, value, label, controlledOptions.force);
|
|
948
|
-
return;
|
|
949
|
-
default:
|
|
950
|
-
throwError(`\`cy.fill()\` can't handle the input element in field with \`<legend>\` "${label}".`);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
throwError(`Could not find a field labelled by a \`<label />\` or \`<legend />\` "${label}".`);
|
|
954
|
-
} catch (err) {
|
|
955
|
-
if (controlledOptions.retries > 0) {
|
|
956
|
-
cy.wait(250).then(()=>{
|
|
957
|
-
cy.log(`[monitor-ui > Cypress] Retrying (${TOTAL_RETRIES - controlledOptions.retries + 1} / ${TOTAL_RETRIES})...`);
|
|
958
|
-
fill(label, value, {
|
|
959
|
-
...controlledOptions,
|
|
960
|
-
retries: controlledOptions.retries - 1
|
|
961
|
-
});
|
|
962
|
-
});
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
const normalizedError = err instanceof Error ? err : new Error(String(err));
|
|
966
|
-
Cypress.log({
|
|
967
|
-
consoleProps: ()=>({
|
|
968
|
-
err,
|
|
969
|
-
label,
|
|
970
|
-
value
|
|
971
|
-
}),
|
|
972
|
-
displayName: 'ERROR',
|
|
973
|
-
message: String(normalizedError.message),
|
|
974
|
-
name: 'fill'
|
|
975
|
-
}).error(normalizedError);
|
|
976
|
-
throwError([
|
|
977
|
-
`Could not find or fill field with label or legend "${label}" at index "${controlledOptions.index}" after ${TOTAL_RETRIES} attempts.`,
|
|
978
|
-
`This error was thrown: “${normalizedError.message}”`,
|
|
979
|
-
`Please check the Cypress "- ERROR" log above for more details.`
|
|
980
|
-
].join('\n'));
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
function forceCheck(subject, options = {}) {
|
|
985
|
-
Cypress.log({
|
|
986
|
-
consoleProps: ()=>({
|
|
987
|
-
'Applied to': subject,
|
|
988
|
-
Elements: 1
|
|
989
|
-
}),
|
|
990
|
-
name: 'forceCheck'
|
|
991
|
-
});
|
|
992
|
-
if (!subject) {
|
|
993
|
-
throw new Error(`Could not find subject.`);
|
|
994
|
-
}
|
|
995
|
-
const wrappedSubject = cy.wrap(subject);
|
|
996
|
-
return wrappedSubject.check({
|
|
997
|
-
...options,
|
|
998
|
-
force: true
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
function forceClear(subject, options = {}) {
|
|
1003
|
-
Cypress.log({
|
|
1004
|
-
consoleProps: ()=>({
|
|
1005
|
-
'Applied to': subject,
|
|
1006
|
-
Elements: 1
|
|
1007
|
-
}),
|
|
1008
|
-
name: 'forceClear'
|
|
1009
|
-
});
|
|
1010
|
-
if (!subject) {
|
|
1011
|
-
throw new Error(`Could not find subject.`);
|
|
1012
|
-
}
|
|
1013
|
-
const wrappedSubject = cy.wrap(subject);
|
|
1014
|
-
return wrappedSubject.clear({
|
|
1015
|
-
...options,
|
|
1016
|
-
force: true
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
function forceClick(subject, options = {}) {
|
|
1021
|
-
Cypress.log({
|
|
1022
|
-
consoleProps: ()=>({
|
|
1023
|
-
'Applied to': subject,
|
|
1024
|
-
Elements: 1
|
|
1025
|
-
}),
|
|
1026
|
-
name: 'forceClick'
|
|
1027
|
-
});
|
|
1028
|
-
if (!subject) {
|
|
1029
|
-
throw new Error(`Could not find subject.`);
|
|
1030
|
-
}
|
|
1031
|
-
const wrappedSubject = cy.wrap(subject);
|
|
1032
|
-
return wrappedSubject.click({
|
|
1033
|
-
...options,
|
|
1034
|
-
force: true
|
|
1035
|
-
});
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
function forceType(subject, text, options = {}) {
|
|
1039
|
-
Cypress.log({
|
|
1040
|
-
consoleProps: ()=>({
|
|
1041
|
-
'Applied to': subject,
|
|
1042
|
-
Elements: 1
|
|
1043
|
-
}),
|
|
1044
|
-
name: 'forceType'
|
|
1045
|
-
});
|
|
1046
|
-
if (!subject) {
|
|
1047
|
-
throw new Error(`Could not find subject.`);
|
|
1048
|
-
}
|
|
1049
|
-
const wrappedSubject = cy.wrap(subject);
|
|
1050
|
-
return wrappedSubject.type(text, {
|
|
1051
|
-
...options,
|
|
1052
|
-
force: true
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
function forceUncheck(subject, options = {}) {
|
|
1057
|
-
Cypress.log({
|
|
1058
|
-
consoleProps: ()=>({
|
|
1059
|
-
'Applied to': subject,
|
|
1060
|
-
Elements: 1
|
|
1061
|
-
}),
|
|
1062
|
-
name: 'forceUncheck'
|
|
1063
|
-
});
|
|
1064
|
-
if (!subject) {
|
|
1065
|
-
throw new Error(`Could not find subject.`);
|
|
1066
|
-
}
|
|
1067
|
-
const wrappedSubject = cy.wrap(subject);
|
|
1068
|
-
return wrappedSubject.uncheck({
|
|
1069
|
-
...options,
|
|
1070
|
-
force: true
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
function getDataCy(dataCy) {
|
|
1075
|
-
return cy.get(`[data-cy="${dataCy}"]`);
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
function getTableRowById(prevSubjectElements, id) {
|
|
1079
|
-
const prevSubjectElement = prevSubjectElements ? prevSubjectElements[0] : undefined;
|
|
1080
|
-
if (prevSubjectElements && !prevSubjectElements[0]) {
|
|
1081
|
-
throw new Error('`prevSubjectElements[0]` is undefined.');
|
|
1082
|
-
}
|
|
1083
|
-
return (prevSubjectElement ? cy.wrap(prevSubjectElement) : cy.get('body')).first().find(`.Table-SimpleTable tr[data-id="${id}"]`);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
function getTableRowByText(prevSubjectElements, text) {
|
|
1087
|
-
const prevSubjectElement = prevSubjectElements ? prevSubjectElements[0] : undefined;
|
|
1088
|
-
if (prevSubjectElements && !prevSubjectElements[0]) {
|
|
1089
|
-
throw new Error('`prevSubjectElements[0]` is undefined.');
|
|
1090
|
-
}
|
|
1091
|
-
return (prevSubjectElement ? cy.wrap(prevSubjectElement) : cy.get('body')).first().contains(`.Table-SimpleTable tr`, text);
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
function waitForLastRequest(alias, partialRequest, maxRequests, level = 0, callback = ()=>{}) {
|
|
1095
|
-
if (level === maxRequests) {
|
|
1096
|
-
throw new Error(`${maxRequests} requests exceeded`);
|
|
1097
|
-
}
|
|
1098
|
-
// @ts-ignore
|
|
1099
|
-
return cy.wait(alias).then((interception)=>{
|
|
1100
|
-
// @ts-ignore
|
|
1101
|
-
const isMatch = Cypress._.isMatch(interception.request, partialRequest);
|
|
1102
|
-
if (isMatch) {
|
|
1103
|
-
return callback(interception.response);
|
|
1104
|
-
}
|
|
1105
|
-
// eslint-disable-next-line no-console
|
|
1106
|
-
cy.log('Intercepted request', JSON.stringify(interception.request));
|
|
1107
|
-
// @ts-ignore
|
|
1108
|
-
return cy.waitForLastRequest(alias, partialRequest, maxRequests, level + 1, callback);
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
const registerMonitorUiCustomCommands = ()=>{
|
|
1113
|
-
Cypress.Commands.add('clickButton', {
|
|
1114
|
-
prevSubject: 'optional'
|
|
1115
|
-
}, clickButton);
|
|
1116
|
-
Cypress.Commands.add('clickLink', clickLink);
|
|
1117
|
-
Cypress.Commands.add('waitForLastRequest', waitForLastRequest);
|
|
1118
|
-
Cypress.Commands.add('clickOutside', clickOutside);
|
|
1119
|
-
Cypress.Commands.add('fill', fill);
|
|
1120
|
-
Cypress.Commands.add('forceCheck', {
|
|
1121
|
-
prevSubject: true
|
|
1122
|
-
}, forceCheck);
|
|
1123
|
-
Cypress.Commands.add('forceClear', {
|
|
1124
|
-
prevSubject: true
|
|
1125
|
-
}, forceClear);
|
|
1126
|
-
Cypress.Commands.add('forceClick', {
|
|
1127
|
-
prevSubject: true
|
|
1128
|
-
}, forceClick);
|
|
1129
|
-
Cypress.Commands.add('forceType', {
|
|
1130
|
-
prevSubject: true
|
|
1131
|
-
}, forceType);
|
|
1132
|
-
Cypress.Commands.add('forceUncheck', {
|
|
1133
|
-
prevSubject: true
|
|
1134
|
-
}, forceUncheck);
|
|
1135
|
-
Cypress.Commands.add('getDataCy', getDataCy);
|
|
1136
|
-
Cypress.Commands.add('getTableRowById', {
|
|
1137
|
-
prevSubject: 'optional'
|
|
1138
|
-
}, getTableRowById);
|
|
1139
|
-
Cypress.Commands.add('getTableRowByText', {
|
|
1140
|
-
prevSubject: 'optional'
|
|
1141
|
-
}, getTableRowByText);
|
|
1142
|
-
};
|
|
1143
|
-
registerMonitorUiCustomCommands();
|
|
1144
|
-
|
|
1145
|
-
export { registerMonitorUiCustomCommands };
|