@ebertjendustries/cstestwrapper 1.0.13 → 1.0.14

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/dist/index.js DELETED
@@ -1,1938 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- AbstractComponentTesting: () => AbstractComponentTesting,
34
- AbstractInputTesting: () => AbstractInputTesting,
35
- AbstractSelectTesting: () => AbstractSelectTesting,
36
- AbstractViewTesting: () => AbstractViewTesting,
37
- AlertTesting: () => AlertTesting,
38
- BoxTesting: () => BoxTesting,
39
- ButtonDropdownTesting: () => ButtonDropdownTesting,
40
- ButtonTesting: () => ButtonTesting,
41
- CSVNoItemsViewTesting: () => CSVNoItemsViewTesting,
42
- CSVPriceInputViewTesting: () => CSVPriceInputViewTesting,
43
- CSVSearchFilterViewTesting: () => CSVSearchFilterViewTesting,
44
- CSVTextPromptModalViewTesting: () => CSVTextPromptModalViewTesting,
45
- CardsTesting: () => CardsTesting,
46
- CheckboxTesting: () => CheckboxTesting,
47
- CollectionPreferencesSetting: () => CollectionPreferencesSetting,
48
- CollectionPreferencesTesting: () => CollectionPreferencesTesting,
49
- DatePickerTesting: () => DatePickerTesting,
50
- FlashbarTesting: () => FlashbarTesting,
51
- FormTesting: () => FormTesting,
52
- HeaderTesting: () => HeaderTesting,
53
- IconTesting: () => IconTesting,
54
- LinkTesting: () => LinkTesting,
55
- MockBrowserAPIs: () => MockBrowserAPIs,
56
- MockRestClient: () => MockRestClient,
57
- MockServerBuilder: () => MockServerBuilder,
58
- ModalTesting: () => ModalTesting,
59
- MultiselectTesting: () => MultiselectTesting,
60
- NumberInputTesting: () => NumberInputTesting,
61
- PaginationTesting: () => PaginationTesting,
62
- ProgressBarTesting: () => ProgressBarTesting,
63
- RatingTesting: () => RatingTesting,
64
- SegmentedControlTesting: () => SegmentedControlTesting,
65
- SelectTesting: () => SelectTesting,
66
- StatusIndicatorTesting: () => StatusIndicatorTesting,
67
- StringInputTesting: () => StringInputTesting,
68
- TableTesting: () => TableTesting,
69
- TabsTesting: () => TabsTesting,
70
- TestLocalisation: () => TestLocalisation,
71
- TestingFactory: () => TestingFactory,
72
- TextContentTesting: () => TextContentTesting,
73
- TextFilterTesting: () => TextFilterTesting,
74
- TextareaTesting: () => TextareaTesting,
75
- ToggleTesting: () => ToggleTesting,
76
- ViewTestWrapper: () => ViewTestWrapper,
77
- WizardTesting: () => WizardTesting,
78
- setupRestClientMock: () => setupRestClientMock
79
- });
80
- module.exports = __toCommonJS(index_exports);
81
-
82
- // src/localisation/TestLocalisation.ts
83
- var TestLocalisation = class {
84
- };
85
-
86
- // src/components/AbstractComponentTesting.ts
87
- var import_dom = __toESM(require("@cloudscape-design/components/test-utils/dom"));
88
- var import_react = require("@testing-library/react");
89
- var import_react2 = require("react");
90
- var import_vitest = require("vitest");
91
- var import_cswrapper = require("@ebertjendustries/cswrapper");
92
- var AbstractComponentTesting = class _AbstractComponentTesting {
93
- constructor(elementSpec, view, findFunction) {
94
- this.elementSpec = elementSpec;
95
- this.view = view;
96
- this.findFunction = findFunction;
97
- if (elementSpec.getDataTestId().indexOf(".") !== -1) {
98
- throw new Error("Data test ids to be used as selected must not contain dots. Found dots in following data-testid: " + elementSpec.getDataTestId());
99
- }
100
- }
101
- static expectEnabled(element, msg) {
102
- if (element.hasAttribute("aria-disabled")) {
103
- (0, import_vitest.expect)(element, msg).toHaveAttribute("aria-disabled", "false");
104
- } else {
105
- (0, import_vitest.expect)(element, msg).toBeEnabled();
106
- }
107
- }
108
- static expectDisabled(element, msg) {
109
- if (element.hasAttribute("aria-disabled")) {
110
- (0, import_vitest.expect)(element, msg).toHaveAttribute("aria-disabled", "true");
111
- } else {
112
- (0, import_vitest.expect)(element, msg).toBeDisabled();
113
- }
114
- }
115
- static doFindElement(dataTestId, findFunction) {
116
- return findFunction(`[data-testid*=${dataTestId}]`);
117
- }
118
- expectFormFieldLabelDisplayed() {
119
- (0, import_vitest.expect)(this.getFormFieldWrapper().findLabel()).not.toBeNull();
120
- }
121
- expectFormFieldLabelNotDisplayed() {
122
- if (this.getFormFieldWrapper() !== null) {
123
- (0, import_vitest.expect)(this.getFormFieldWrapper().findLabel()).toBeNull();
124
- } else {
125
- (0, import_vitest.expect)(this.getFormFieldWrapper()).toBeNull();
126
- }
127
- }
128
- getElement() {
129
- const element = this.getElementWrapper();
130
- return this.assertElement(this.elementSpec.getDataTestId(), () => element.getElement());
131
- }
132
- queryElement() {
133
- const element = _AbstractComponentTesting.doFindElement(this.elementSpec.getDataTestId(), this.findFunction);
134
- if (element === null) {
135
- return null;
136
- } else {
137
- const htmlElement = element.getElement();
138
- if (htmlElement === void 0) {
139
- return null;
140
- }
141
- return htmlElement;
142
- }
143
- }
144
- awaitElement() {
145
- return import_react.screen.findByTestId(this.elementSpec.getDataTestId());
146
- }
147
- async awaitPresent() {
148
- (0, import_vitest.expect)(await this.awaitElement()).toBeInTheDocument();
149
- }
150
- expectPresent() {
151
- (0, import_vitest.expect)(this.getElement()).toBeInTheDocument();
152
- }
153
- expectNotPresent() {
154
- (0, import_vitest.expect)(this.queryElement()).toBeNull();
155
- }
156
- expectEnabled() {
157
- _AbstractComponentTesting.expectEnabled(this.getElement(), this.msgForExpect());
158
- }
159
- expectDisabled() {
160
- _AbstractComponentTesting.expectDisabled(this.getElement(), this.msgForExpect());
161
- }
162
- click() {
163
- (0, import_react2.act)(() => {
164
- const element = this.assertElement(this.elementSpec.getDataTestId(), (dataTestId) => _AbstractComponentTesting.doFindElement(dataTestId, this.findFunction));
165
- element.click();
166
- });
167
- }
168
- expectReadOnly() {
169
- (0, import_vitest.expect)(this.getElement()).toHaveAttribute("readonly", "true");
170
- }
171
- expectNotReadOnly() {
172
- (0, import_vitest.expect)(this.getElement()).not.toHaveAttribute("readonly");
173
- }
174
- expectChecked() {
175
- (0, import_vitest.expect)(this.getElement(), this.msgForExpect()).toBeChecked();
176
- }
177
- expectNotChecked() {
178
- (0, import_vitest.expect)(this.getElement(), this.msgForExpect()).not.toBeChecked();
179
- }
180
- expectCheckState(checked) {
181
- if (checked) {
182
- this.expectChecked();
183
- } else {
184
- this.expectNotChecked();
185
- }
186
- }
187
- expectContent(text) {
188
- (0, import_vitest.expect)(this.getElement(), this.msgForExpect()).toHaveTextContent(text);
189
- }
190
- async awaitNotPresent() {
191
- await (0, import_react.waitForElementToBeRemoved)(() => this.queryElement());
192
- }
193
- getFormFieldWrapper() {
194
- return _AbstractComponentTesting.doFindElement(this.elementSpec.getDataTestId() + import_cswrapper.FORM_FIELD_ID_SUFFIX, (dataTestId) => (0, import_dom.default)().findFormField(dataTestId));
195
- }
196
- assertElement(dataTestId, getterFunction) {
197
- const element = getterFunction(dataTestId);
198
- if (element === null || element === void 0) {
199
- throw new Error(this.elementNotFoundErrorMessage(dataTestId));
200
- }
201
- return element;
202
- }
203
- elementNotFoundErrorMessage(dataTestId) {
204
- return `Element with data-testid ${dataTestId} not found`;
205
- }
206
- getElementWrapper() {
207
- return this.assertElement(this.elementSpec.getDataTestId(), (dataTestId) => _AbstractComponentTesting.doFindElement(dataTestId, this.findFunction));
208
- }
209
- msgForExpect(index, customSuffix) {
210
- const indexPart = index !== void 0 ? `[${index}]` : "";
211
- const suffixPart = customSuffix !== void 0 ? ` - ${customSuffix}` : "";
212
- return `${this.constructor.name}<data-testid=${this.elementSpec.getDataTestId()}>${indexPart}${suffixPart}`;
213
- }
214
- };
215
-
216
- // src/components/AbstractInputTesting.ts
217
- var import_react3 = require("@testing-library/react");
218
- var import_cswrapper2 = require("@ebertjendustries/cswrapper");
219
- var import_cswrapper3 = require("@ebertjendustries/cswrapper");
220
- var import_vitest2 = require("vitest");
221
- var AbstractInputTesting = class extends AbstractComponentTesting {
222
- clear() {
223
- this.setStringValue("");
224
- }
225
- async forceTooLongValidationMessage(repeatedString) {
226
- const inputValue = (repeatedString === void 0 ? "test" : repeatedString).repeat(this.elementSpec.maxLength + 2);
227
- this.setStringValue(inputValue);
228
- const localiser = this.view.getLocaliser();
229
- const fieldValidityFunction = localiser.getFieldValidityLocalisationFunction();
230
- await this.expectErrorMessage(fieldValidityFunction(this.elementSpec, import_cswrapper2.ElementValidityLevel.MAX_LENGTH_EXCEEDED));
231
- }
232
- async awaitMandatoryMissing() {
233
- const localiser = this.view.getLocaliser();
234
- const fieldValidityFunction = localiser.getFieldValidityLocalisationFunction();
235
- await this.expectErrorMessage(fieldValidityFunction(new import_cswrapper3.FieldSpec("", true), import_cswrapper2.ElementValidityLevel.REQUIRED_VALUE_IS_NOT_PRESENT));
236
- }
237
- expectReadOnly() {
238
- (0, import_vitest2.expect)(this.getNativeHTMLInput().readOnly).toBeTruthy();
239
- }
240
- expectNotReadOnly() {
241
- (0, import_vitest2.expect)(this.getNativeHTMLInput().readOnly).toBeFalsy();
242
- }
243
- expectEmpty() {
244
- (0, import_vitest2.expect)(this.getNativeHTMLInput()).toHaveValue(null);
245
- }
246
- overwriteAndVerify(value) {
247
- this.setStringValue(value === void 0 ? "" : value.toString());
248
- this.expectValue(value);
249
- }
250
- expectEnabled() {
251
- (0, import_vitest2.expect)(this.getNativeHTMLInput()).toBeEnabled();
252
- }
253
- expectDisabled() {
254
- (0, import_vitest2.expect)(this.getNativeHTMLInput()).toBeDisabled();
255
- }
256
- async expectErrorMessage(message) {
257
- await (0, import_react3.waitFor)(() => (0, import_vitest2.expect)(this.getFormFieldWrapper().findError()).not.toBeNull());
258
- (0, import_vitest2.expect)(this.getFormFieldWrapper().findError().getElement()).toHaveTextContent(message);
259
- }
260
- };
261
-
262
- // src/components/AbstractSelectTesting.ts
263
- var import_react4 = require("@testing-library/react");
264
- var import_react5 = require("react");
265
- var import_vitest3 = require("vitest");
266
- var AbstractSelectTesting = class extends AbstractComponentTesting {
267
- constructor(fieldSpec, view, findFunction, expandToViewport) {
268
- super(fieldSpec, view, findFunction);
269
- this.expandToViewport = expandToViewport;
270
- }
271
- async expectSelectedEnumEntries(enumFactory, selectedEntries) {
272
- const localiser = this.view.getLocaliser();
273
- await this.expectSelectedEntries(selectedEntries.map((entry) => localiser.getEnumLabel(enumFactory, entry)), enumFactory.values.length);
274
- }
275
- async expectSelectedEntries(selectedEntries, totalEntryCount) {
276
- const selectWrapper = await this.openDropdown();
277
- const selectedOptions = this.getDropdown(selectWrapper).findSelectedOptions();
278
- const selectedOptionsText = selectedOptions.map((selectedOption) => selectedOption.findLabel().getElement().textContent);
279
- console.log(`CURRENTLY selected options = ${selectedOptionsText}, EXPECTED selected options = ${selectedEntries}`);
280
- const indexDiff = selectedEntries.length === totalEntryCount ? 1 : 0;
281
- (0, import_vitest3.expect)(selectedOptions, this.msgForExpect()).toHaveLength(selectedEntries.length + indexDiff);
282
- const selectedEntriesSet = /* @__PURE__ */ new Set();
283
- selectedEntries.forEach((entry) => selectedEntriesSet.add(entry));
284
- for (let index = indexDiff; index < selectedOptionsText.length; index++) {
285
- const selectedOption = selectedOptionsText[index];
286
- const hasElement = selectedEntriesSet.has(selectedOption);
287
- if (!hasElement) {
288
- console.log(`Expected element at index ${index} to be selected: ${selectedOption}.`);
289
- }
290
- (0, import_vitest3.expect)(hasElement, this.msgForExpect(index)).toBeTruthy();
291
- }
292
- await this.closeDropdown(selectWrapper);
293
- }
294
- /**
295
- * Expects entries in the array.
296
- *
297
- * @param entries The expected entry labels
298
- * @param selectedIndices The selected entry indices
299
- *
300
- * The selected indices are zero-based and DO NOT consider the "Select all" entry. I.e. the first entry after
301
- * "Select all" has index = 0.
302
- */
303
- async expectEntries(entries, selectedIndices) {
304
- selectedIndices = selectedIndices.sort((a, b) => a - b);
305
- (0, import_vitest3.expect)(await this.awaitElement(), this.msgForExpect()).toBeInTheDocument();
306
- const selectWrapper = await this.openDropdown();
307
- const options = this.getDropdown(selectWrapper).findOptions();
308
- (0, import_vitest3.expect)(options, this.msgForExpect()).toHaveLength(entries.length);
309
- const selectedOptions = this.getDropdown(selectWrapper).findSelectedOptions();
310
- const indexDiff = entries.length === selectedIndices.length ? 1 : 0;
311
- (0, import_vitest3.expect)(selectedOptions, this.msgForExpect()).toHaveLength(selectedIndices.length + indexDiff);
312
- for (let index = indexDiff; index < selectedOptions.length; index++) {
313
- const selectedOption = selectedOptions[index];
314
- (0, import_vitest3.expect)(selectedOption.findLabel().getElement().textContent, this.msgForExpect(index)).toBe(entries[selectedIndices[index - indexDiff]]);
315
- }
316
- await this.closeDropdown(selectWrapper);
317
- }
318
- async expectEnumEntries(enumFactory, selectedEnums, except) {
319
- const totalEnums = enumFactory.values.filter((e) => except === void 0 || except.indexOf(e) === -1);
320
- const selectedOptionIndices = selectedEnums.map((i) => totalEnums.findIndex((e) => e === i));
321
- const localiser = this.view.getLocaliser();
322
- await this.expectEntries(
323
- totalEnums.map((e) => localiser.getEnumLabel(enumFactory, e)),
324
- selectedOptionIndices
325
- );
326
- }
327
- async selectOrDeselect(clickedIndices) {
328
- (0, import_vitest3.expect)(await this.awaitElement(), this.msgForExpect()).toBeInTheDocument();
329
- const sortedIndices = clickedIndices.sort((a, b) => b - a);
330
- const selectWrapper = await this.openDropdown();
331
- for (let index = 0; index < sortedIndices.length; index++) {
332
- const clickedIndex = sortedIndices[index];
333
- (0, import_react5.act)(() => selectWrapper.selectOption(clickedIndex + 1, this.getOptions()));
334
- }
335
- await this.closeDropdown(selectWrapper);
336
- }
337
- // ATTENTION! Do NOT use with enum single select! It will lead to failing tests as it does not change selection.
338
- async select(entries) {
339
- console.log("SELECTING options = " + entries);
340
- const indicesToSelect = [];
341
- const indicesToDeselect = [];
342
- const selectWrapper = await this.openDropdown();
343
- const selectedOptionValues = this.optionsToEntrySet(this.getDropdown(selectWrapper).findSelectedOptions());
344
- const allOptions = this.getDropdown(selectWrapper).findOptions();
345
- await this.closeDropdown(selectWrapper);
346
- const optionValuesToSelect = /* @__PURE__ */ new Set();
347
- entries.forEach((entry) => optionValuesToSelect.add(entry));
348
- for (let index = 0; index < allOptions.length; index++) {
349
- const optionValue = allOptions[index].getElement().textContent;
350
- if (optionValuesToSelect.has(optionValue) && !selectedOptionValues.has(optionValue)) {
351
- indicesToSelect.push(index);
352
- } else if (!optionValuesToSelect.has(optionValue) && selectedOptionValues.has(optionValue)) {
353
- indicesToDeselect.push(index);
354
- }
355
- }
356
- await this.selectOrDeselect(indicesToSelect);
357
- await this.selectOrDeselect(indicesToDeselect);
358
- await this.closeDropdown(await this.openDropdown());
359
- }
360
- async openDropdown() {
361
- const selectWrapper = this.getElementWrapper();
362
- (0, import_react5.act)(() => selectWrapper.openDropdown());
363
- await (0, import_react4.waitFor)(() => (0, import_vitest3.expect)(this.getDropdown(selectWrapper).findOptions().length, this.msgForExpect()).toBeGreaterThan(0));
364
- return selectWrapper;
365
- }
366
- async closeDropdown(selectWrapper) {
367
- (0, import_react5.act)(() => selectWrapper.closeDropdown(this.getOptions()));
368
- if (!this.expandToViewport) {
369
- await (0, import_react4.waitFor)(() => (0, import_vitest3.expect)(this.getDropdown(selectWrapper).findOptions().length, this.msgForExpect()).toBe(0));
370
- }
371
- }
372
- async awaitHasSelectedEntryCount(selectedEntryCount, totalEntryCount) {
373
- const selectWrapper = await this.openDropdown();
374
- const options = this.getDropdown(selectWrapper).findSelectedOptions();
375
- if (selectedEntryCount === totalEntryCount) {
376
- (0, import_vitest3.expect)(options, this.msgForExpect()).toHaveLength(selectedEntryCount + 1);
377
- } else {
378
- (0, import_vitest3.expect)(options, this.msgForExpect()).toHaveLength(selectedEntryCount);
379
- }
380
- await this.closeDropdown(selectWrapper);
381
- }
382
- getOptions() {
383
- return this.expandToViewport === void 0 ? void 0 : { expandToViewport: this.expandToViewport };
384
- }
385
- getDropdown(selectWrapper) {
386
- return selectWrapper.findDropdown(this.getOptions());
387
- }
388
- optionsToEntrySet(options) {
389
- const entriesSet = /* @__PURE__ */ new Set();
390
- options.forEach((option) => entriesSet.add(option.getElement().textContent));
391
- return entriesSet;
392
- }
393
- };
394
-
395
- // src/views/AbstractViewTesting.tsx
396
- var import_cswrapper6 = require("@ebertjendustries/cswrapper");
397
-
398
- // src/components/MultiselectTesting.ts
399
- var import_dom2 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
400
- var MultiselectTesting = class extends AbstractSelectTesting {
401
- constructor(fieldSpec, view, expandToViewport) {
402
- super(fieldSpec, view, (selector) => (0, import_dom2.default)().findMultiselect(selector), expandToViewport);
403
- this.view = view;
404
- }
405
- };
406
-
407
- // src/components/SelectTesting.ts
408
- var import_dom3 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
409
- var import_vitest4 = require("vitest");
410
- var SelectTesting = class extends AbstractSelectTesting {
411
- constructor(fieldSpec, view, expandToViewport) {
412
- super(fieldSpec, view, (selector) => (0, import_dom3.default)().findSelect(selector), expandToViewport);
413
- this.view = view;
414
- }
415
- expectEnabled() {
416
- (0, import_vitest4.expect)(this.getElementWrapper().isDisabled(), this.msgForExpect()).toBeFalsy();
417
- }
418
- expectDisabled() {
419
- (0, import_vitest4.expect)(this.getElementWrapper().isDisabled(), this.msgForExpect()).toBeTruthy();
420
- }
421
- };
422
-
423
- // src/components/InputTesting.ts
424
- var import_dom4 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
425
- var import_react6 = require("react");
426
- var import_cswrapper4 = require("@ebertjendustries/cswrapper");
427
- var import_vitest5 = require("vitest");
428
- var StringInputTesting = class extends AbstractInputTesting {
429
- constructor(fieldSpec, view) {
430
- super(fieldSpec, view, (selector) => (0, import_dom4.default)().findInput(selector));
431
- this.view = view;
432
- }
433
- setStringValue(value) {
434
- (0, import_react6.act)(() => {
435
- this.getElementWrapper().setInputValue(value === void 0 ? "" : value);
436
- });
437
- }
438
- expectValue(value) {
439
- (0, import_vitest5.expect)(this.getNativeHTMLInput()).toHaveValue(value === void 0 ? "" : value);
440
- }
441
- getNativeHTMLInput() {
442
- return this.getElementWrapper().findNativeInput().getElement();
443
- }
444
- };
445
- var NumberInputTesting = class extends AbstractInputTesting {
446
- constructor(fieldSpec, view) {
447
- super(fieldSpec, view, (selector) => (0, import_dom4.default)().findInput(selector));
448
- this.view = view;
449
- }
450
- setStringValue(value) {
451
- (0, import_react6.act)(() => {
452
- if (typeof value === "number") {
453
- this.getElementWrapper().setInputValue(value.toString());
454
- } else {
455
- this.getElementWrapper().setInputValue(value === void 0 ? "" : value);
456
- }
457
- });
458
- }
459
- async forceSmallerThanLowerBoundMessage() {
460
- const inputValue = this.elementSpec.minValue - 1;
461
- this.setStringValue(inputValue.toString());
462
- const localiser = this.view.getLocaliser();
463
- const fieldValidityFunction = localiser.getFieldValidityLocalisationFunction();
464
- await this.expectErrorMessage(fieldValidityFunction(this.elementSpec, import_cswrapper4.ElementValidityLevel.LOWER_BOUND_ONLY_TOO_SMALL));
465
- }
466
- expectValue(value) {
467
- (0, import_vitest5.expect)(this.getNativeHTMLInput()).toHaveValue(value === void 0 ? null : value);
468
- }
469
- getNativeHTMLInput() {
470
- return this.getElementWrapper().findNativeInput().getElement();
471
- }
472
- };
473
- var DatePickerTesting = class extends AbstractInputTesting {
474
- constructor(fieldSpec, view) {
475
- super(fieldSpec, view, (selector) => (0, import_dom4.default)().findDatePicker(selector));
476
- this.view = view;
477
- }
478
- setStringValue(value) {
479
- (0, import_react6.act)(() => {
480
- this.getElementWrapper().setInputValue(value === void 0 ? "" : value.replaceAll("-", "/"));
481
- });
482
- }
483
- expectValue(value) {
484
- if (value === void 0) {
485
- this.expectEmpty();
486
- } else {
487
- (0, import_vitest5.expect)(this.getNativeHTMLInput()).toHaveValue(value.replaceAll("-", "/"));
488
- }
489
- }
490
- getNativeHTMLInput() {
491
- return this.getElementWrapper().findNativeInput().getElement();
492
- }
493
- };
494
-
495
- // src/components/TableTesting.ts
496
- var import_dom5 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
497
- var import_react7 = require("@testing-library/react");
498
- var import_react8 = require("react");
499
- var import_vitest6 = require("vitest");
500
- var TableTesting = class extends AbstractComponentTesting {
501
- constructor(fieldSpec, view) {
502
- super(fieldSpec, view, (selector) => (0, import_dom5.default)().findTable(selector));
503
- this.view = view;
504
- }
505
- expectSelectCount(expectedSelectCount) {
506
- const selectedRows = this.getElementWrapper().findSelectedRows();
507
- (0, import_vitest6.expect)(selectedRows).toHaveLength(expectedSelectCount);
508
- }
509
- getRowCount() {
510
- return this.getElementWrapper().findRows().length;
511
- }
512
- selectAllItems() {
513
- (0, import_react8.act)(() => this.getElementWrapper().findSelectAllTrigger().click());
514
- }
515
- expectSelectedItems(selectedRowIndices) {
516
- const allItems = this.getElementWrapper().findRows();
517
- const selectedItems = this.getElementWrapper().findSelectedRows();
518
- for (let index = 0; index < allItems.length; index++) {
519
- if (selectedRowIndices.indexOf(index) !== -1) {
520
- const item = allItems[index];
521
- (0, import_vitest6.expect)(selectedItems).toContainEqual(item);
522
- }
523
- }
524
- }
525
- expectUnselectedItems(unselectedRowIndices) {
526
- const allItems = this.getElementWrapper().findRows();
527
- const selectedItems = this.getElementWrapper().findSelectedRows();
528
- for (let index = 0; index < allItems.length; index++) {
529
- if (unselectedRowIndices.indexOf(index) !== -1) {
530
- const item = allItems[index];
531
- (0, import_vitest6.expect)(selectedItems).not.toContain(item);
532
- }
533
- }
534
- }
535
- selectItems(clickedRowIndices) {
536
- for (let i = 0; i < clickedRowIndices.length; i++) {
537
- const clickedIndex = clickedRowIndices[i];
538
- const selectionArea = this.assertElement((clickedIndex + 1).toString(), () => this.getElementWrapper().findRowSelectionArea(clickedIndex + 1));
539
- (0, import_react8.act)(() => {
540
- selectionArea.click();
541
- });
542
- }
543
- }
544
- printRow(rowIndex, columnCount) {
545
- let row = "";
546
- for (let colIndex = 0; colIndex < columnCount; colIndex++) {
547
- row = row + this.getElementWrapper().findBodyCell(rowIndex + 1, colIndex + 1).getElement().textContent + "; ";
548
- }
549
- console.log(`ROW CONTENT (index = ${rowIndex}) = ${row}`);
550
- }
551
- expectCellContent(rowIndex, colIndex, content) {
552
- (0, import_vitest6.expect)(this.getElementWrapper().findBodyCell(rowIndex + 1, colIndex + 1).getElement()).toHaveTextContent(content);
553
- }
554
- expectTableContent(content) {
555
- (0, import_vitest6.expect)(this.getRowCount()).toBe(content.length);
556
- for (let rowIndex = 0; rowIndex < content.length; rowIndex++) {
557
- this.expectRowContent(rowIndex, content[rowIndex]);
558
- }
559
- }
560
- expectRowContent(rowIndex, content) {
561
- for (let colIndex = 0; colIndex < content.length; colIndex++) {
562
- const cellContent = content[colIndex];
563
- this.expectCellContent(rowIndex, colIndex, cellContent);
564
- }
565
- }
566
- async editCellWithConfirm(rowIndex, colIndex, editSteps) {
567
- await this.editCell(rowIndex, colIndex, editSteps, () => this.getElementWrapper().findEditingCellSaveButton());
568
- }
569
- async editCellWithCancel(rowIndex, colIndex, editSteps) {
570
- await this.editCell(rowIndex, colIndex, editSteps, () => this.getElementWrapper().findEditingCellCancelButton());
571
- }
572
- expectNotContainedInAnyRow(colIndex, content) {
573
- const rowCount = this.getRowCount();
574
- for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
575
- (0, import_vitest6.expect)(this.getElementWrapper().findBodyCell(rowIndex + 1, colIndex + 1).getElement()).not.toHaveTextContent(content);
576
- }
577
- }
578
- async awaitLoading() {
579
- await (0, import_react7.waitFor)(() => (0, import_vitest6.expect)(this.getElementWrapper().findLoadingText()).not.toBeNull());
580
- }
581
- async awaitNotLoading() {
582
- await (0, import_react7.waitFor)(() => (0, import_vitest6.expect)(this.getElementWrapper().findLoadingText()).toBeNull());
583
- }
584
- changeColumnSorting(columnHeader) {
585
- const column = this.getElementWrapper().findColumnHeaders().findIndex((header) => header.getElement().textContent === columnHeader);
586
- const sortButton = this.getElementWrapper().findColumnSortingArea(column + 1);
587
- (0, import_react8.act)(() => sortButton.click());
588
- }
589
- expectSortedBy(columnHeader, desc) {
590
- const descSorted = this.getElementWrapper().findDescSortedColumn();
591
- const ascSorted = this.getElementWrapper().findAscSortedColumn();
592
- if (desc) {
593
- (0, import_vitest6.expect)(descSorted).not.toBeNull();
594
- (0, import_vitest6.expect)(descSorted.getElement().textContent).toBe(columnHeader);
595
- } else {
596
- (0, import_vitest6.expect)(ascSorted).not.toBeNull();
597
- (0, import_vitest6.expect)(ascSorted.getElement().textContent).toBe(columnHeader);
598
- }
599
- }
600
- async editCell(rowIndex, colIndex, editSteps, findLeaveButton) {
601
- await (0, import_react7.waitFor)(() => (0, import_vitest6.expect)(this.getElementWrapper().findEditCellButton(rowIndex + 1, colIndex + 1)).not.toBeNull());
602
- (0, import_react8.act)(() => this.getElementWrapper().findEditCellButton(rowIndex + 1, colIndex + 1).click());
603
- await (0, import_react7.waitFor)(() => (0, import_vitest6.expect)(findLeaveButton()).not.toBeNull());
604
- await editSteps();
605
- (0, import_react8.act)(() => findLeaveButton().click());
606
- await (0, import_react7.waitFor)(() => (0, import_vitest6.expect)(this.getElementWrapper().findEditCellButton(rowIndex + 1, colIndex + 1)).not.toBeNull());
607
- }
608
- };
609
-
610
- // src/components/WizardTesting.ts
611
- var import_dom6 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
612
- var import_react9 = require("react");
613
- var WizardTesting = class extends AbstractComponentTesting {
614
- constructor(fieldSpec, view) {
615
- super(fieldSpec, view, (selector) => (0, import_dom6.default)().findWizard(selector));
616
- this.view = view;
617
- }
618
- cancel() {
619
- (0, import_react9.act)(() => this.getElementWrapper().findCancelButton().click());
620
- }
621
- skip() {
622
- const skipButton = this.assertElement(this.elementSpec.getDataTestId() + "SkipButton", () => this.getElementWrapper().findSkipToButton());
623
- (0, import_react9.act)(() => skipButton.click());
624
- }
625
- prev() {
626
- const prevButton = this.assertElement(this.elementSpec.getDataTestId() + "PrevButton", () => this.getElementWrapper().findPreviousButton());
627
- (0, import_react9.act)(() => prevButton.click());
628
- }
629
- next() {
630
- (0, import_react9.act)(() => this.getElementWrapper().findPrimaryButton().click());
631
- }
632
- confirm() {
633
- this.next();
634
- }
635
- goToStep(stepIndex) {
636
- (0, import_react9.act)(() => this.getElementWrapper().findMenuNavigationLinks()[stepIndex].click());
637
- }
638
- };
639
-
640
- // src/components/ButtonTesting.ts
641
- var import_dom7 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
642
- var import_react10 = require("@testing-library/react");
643
- var import_vitest7 = require("vitest");
644
- var ButtonTesting = class extends AbstractComponentTesting {
645
- constructor(fieldSpec, view) {
646
- super(fieldSpec, view, (selector) => (0, import_dom7.default)().findButton(selector));
647
- this.view = view;
648
- }
649
- async awaitLoading() {
650
- await (0, import_react10.waitFor)(() => (0, import_vitest7.expect)(this.getElementWrapper().findLoadingIndicator()).not.toBeNull());
651
- }
652
- async awaitNotLoading() {
653
- await (0, import_react10.waitFor)(() => (0, import_vitest7.expect)(this.getElementWrapper().findLoadingIndicator()).toBeNull());
654
- }
655
- async clickAndWaitForLoadingDone() {
656
- this.click();
657
- await this.awaitLoading();
658
- await this.awaitNotLoading();
659
- }
660
- };
661
-
662
- // src/components/ButtonDropdownTesting.ts
663
- var import_dom8 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
664
- var import_react11 = require("@testing-library/react");
665
- var import_react12 = require("react");
666
- var import_vitest8 = require("vitest");
667
- var ButtonDropdownTesting = class extends AbstractComponentTesting {
668
- constructor(fieldSpec, view) {
669
- super(fieldSpec, view, (selector) => (0, import_dom8.default)().findButtonDropdown(selector));
670
- this.view = view;
671
- }
672
- async openDropdown() {
673
- (0, import_react12.act)(() => this.getElementWrapper().openDropdown());
674
- await (0, import_react11.waitFor)(() => (0, import_vitest8.expect)(this.getDropdown()).not.toBeNull());
675
- }
676
- async clickItem(dataTestId) {
677
- await this.openDropdown();
678
- (0, import_react12.act)(() => {
679
- this.getElementWrapper().findItemById(dataTestId).click();
680
- });
681
- }
682
- getDropdown() {
683
- return this.getElementWrapper().findOpenDropdown();
684
- }
685
- };
686
-
687
- // src/components/ModalTesting.ts
688
- var import_dom9 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
689
- var import_react13 = require("@testing-library/react");
690
- var import_react14 = require("react");
691
- var import_vitest9 = require("vitest");
692
- var ModalTesting = class extends AbstractComponentTesting {
693
- constructor(viewSpec, view) {
694
- super(viewSpec, view, (selector) => (0, import_dom9.default)().findModal(selector));
695
- this.view = view;
696
- }
697
- expectHidden() {
698
- (0, import_vitest9.expect)(this.getElementWrapper().isVisible()).toBeFalsy();
699
- }
700
- expectVisible() {
701
- (0, import_vitest9.expect)(this.getElementWrapper().isVisible()).toBeTruthy();
702
- }
703
- async awaitVisible() {
704
- return (0, import_react13.waitFor)(() => (0, import_vitest9.expect)(this.getElementWrapper().isVisible()).toBeTruthy());
705
- }
706
- async awaitHidden() {
707
- return (0, import_react13.waitFor)(() => (0, import_vitest9.expect)(this.getElementWrapper().isVisible()).toBeFalsy());
708
- }
709
- dismiss() {
710
- (0, import_react14.act)(() => {
711
- this.getElementWrapper().findDismissButton().click();
712
- });
713
- }
714
- };
715
-
716
- // src/components/RatingTesting.ts
717
- var import_dom10 = require("@cloudscape-design/test-utils-core/dom");
718
- var import_react15 = require("@testing-library/react");
719
- var import_react16 = require("react");
720
- var import_cswrapper5 = require("@ebertjendustries/cswrapper");
721
- var import_vitest10 = require("vitest");
722
- var RatingTesting = class extends AbstractComponentTesting {
723
- constructor(viewSpec, view, factory, toOrderNumber) {
724
- super(viewSpec, view, () => {
725
- const element = import_react15.screen.queryByLabelText((0, import_cswrapper5.getEnumRatingValues)(factory, toOrderNumber)[0].toString());
726
- if (element === null) {
727
- return null;
728
- }
729
- return new import_dom10.ElementWrapper(element);
730
- });
731
- this.view = view;
732
- this.enumValuesInOrder = (0, import_cswrapper5.getEnumRatingValues)(factory, toOrderNumber);
733
- }
734
- static mockBoundingBox() {
735
- window.SVGElement.prototype.getBBox = () => ({
736
- x: 0,
737
- y: 0,
738
- width: 0,
739
- height: 0
740
- });
741
- }
742
- static unmockBoundingBox() {
743
- delete window.SVGElement.prototype.getBBox;
744
- }
745
- expectSelected(selectedEnum) {
746
- (0, import_vitest10.expect)(this.getByLabelText(selectedEnum)).toBeChecked();
747
- }
748
- expectAllUnselected() {
749
- for (const element of this.enumValuesInOrder.slice(1)) {
750
- (0, import_vitest10.expect)(this.getByLabelText(element)).not.toBeChecked();
751
- }
752
- }
753
- select(selectedEnum) {
754
- (0, import_react16.act)(() => {
755
- this.getByLabelText(selectedEnum).click();
756
- });
757
- }
758
- unselectAll() {
759
- (0, import_react16.act)(() => {
760
- this.getByLabelText(this.enumValuesInOrder[1]).click();
761
- });
762
- (0, import_react16.act)(() => {
763
- this.getByLabelText(this.enumValuesInOrder[1]).click();
764
- });
765
- }
766
- expectEnabled() {
767
- AbstractComponentTesting.expectEnabled(this.getByLabelText(this.enumValuesInOrder[1]), this.msgForExpect());
768
- }
769
- expectDisabled() {
770
- AbstractComponentTesting.expectDisabled(this.getByLabelText(this.enumValuesInOrder[1]), this.msgForExpect());
771
- }
772
- getByLabelText(enumInstance) {
773
- return import_react15.screen.getByLabelText((0, import_cswrapper5.getEnumRatingLabel)(enumInstance, this.elementSpec.instanceId));
774
- }
775
- };
776
-
777
- // src/components/CheckboxTesting.ts
778
- var import_dom11 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
779
- var import_react17 = require("react");
780
- var CheckboxTesting = class extends AbstractComponentTesting {
781
- constructor(fieldSpec, view) {
782
- super(fieldSpec, view, (selector) => (0, import_dom11.default)().findCheckbox(selector));
783
- this.view = view;
784
- }
785
- click() {
786
- (0, import_react17.act)(() => {
787
- this.getElementWrapper().findNativeInput().click();
788
- });
789
- }
790
- isChecked() {
791
- return this.getElement().checked;
792
- }
793
- getElement() {
794
- const element = this.getElementWrapper().findNativeInput();
795
- return this.assertElement("None", () => element.getElement());
796
- }
797
- toggleIfNecessary(desiredCheckedState) {
798
- if (this.isChecked() !== desiredCheckedState) {
799
- this.click();
800
- }
801
- }
802
- };
803
-
804
- // src/components/HeaderTesting.ts
805
- var import_dom12 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
806
- var import_vitest11 = require("vitest");
807
- var HeaderTesting = class extends AbstractComponentTesting {
808
- constructor(fieldSpec, view) {
809
- super(fieldSpec, view, (selector) => (0, import_dom12.default)().findHeader(selector));
810
- this.view = view;
811
- }
812
- expectCounterLocalisation(variables) {
813
- const localisedElements = this.view.getLocaliser().localiseField(this.elementSpec.getLocalisationKey(), variables);
814
- (0, import_vitest11.expect)(this.getElementWrapper().findCounter().getElement()).toHaveTextContent(localisedElements.counter);
815
- }
816
- expectCounter(counterText) {
817
- (0, import_vitest11.expect)(this.getElementWrapper().findCounter().getElement()).toHaveTextContent(counterText);
818
- }
819
- expectContent(content) {
820
- (0, import_vitest11.expect)(this.getElementWrapper().findHeadingText().getElement()).toHaveTextContent(content);
821
- }
822
- expectNotContent(content) {
823
- (0, import_vitest11.expect)(this.getElementWrapper().findHeadingText().getElement()).not.toHaveTextContent(content);
824
- }
825
- };
826
-
827
- // src/components/BoxTesting.ts
828
- var import_dom13 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
829
- var import_vitest12 = require("vitest");
830
- var BoxTesting = class extends AbstractComponentTesting {
831
- constructor(fieldSpec, view) {
832
- super(fieldSpec, view, (selector) => (0, import_dom13.default)().findBox(selector));
833
- this.view = view;
834
- }
835
- expectContent(content) {
836
- (0, import_vitest12.expect)(this.getElementWrapper().getElement()).toHaveTextContent(content);
837
- }
838
- expectLocalisation(variables, alternateNs) {
839
- const localisedElements = this.view.getLocaliser().localiseField(this.elementSpec.getLocalisationKey(), variables, alternateNs);
840
- this.expectContent(localisedElements.children.trim());
841
- }
842
- };
843
-
844
- // src/components/CollectionPreferencesTesting.ts
845
- var import_dom14 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
846
- var import_react18 = require("react");
847
- var import_vitest13 = require("vitest");
848
- var CollectionPreferencesSetting = class {
849
- };
850
- var CollectionPreferencesTesting = class extends AbstractComponentTesting {
851
- constructor(fieldSpec, view, supportedPageSizes) {
852
- super(fieldSpec, view, (selector) => (0, import_dom14.default)().findCollectionPreferences(selector));
853
- this.view = view;
854
- this.supportedPageSizes = supportedPageSizes;
855
- }
856
- async expectPreferences(preferences) {
857
- const modal = this.openPreferencesModal();
858
- if (preferences.pageSize !== void 0) {
859
- const pageSizeIndex = this.getPageSizeIndex(preferences.pageSize);
860
- (0, import_vitest13.expect)(modal.findPageSizePreference().findOptions()[pageSizeIndex].findNativeInput().getElement()).toBeChecked();
861
- }
862
- if (preferences.stickFirstColumns !== void 0) {
863
- (0, import_vitest13.expect)(modal.findStickyColumnsPreference("first").findRadioGroup().findButtons()[preferences.stickFirstColumns].findNativeInput().getElement()).toBeChecked();
864
- }
865
- if (preferences.stickLastColumns !== void 0) {
866
- (0, import_vitest13.expect)(modal.findStickyColumnsPreference("last").findRadioGroup().findButtons()[preferences.stickLastColumns].findNativeInput().getElement()).toBeChecked();
867
- }
868
- this.expectCheckboxSetting(preferences.wrapLines, modal.findWrapLinesPreference());
869
- this.expectCheckboxSetting(preferences.stripedRows, modal.findStripedRowsPreference());
870
- this.expectCheckboxSetting(preferences.compact, modal.findContentDensityPreference());
871
- this.cancelPreferencesModal();
872
- }
873
- async editPreferences(preferences) {
874
- const modal = this.openPreferencesModal();
875
- if (preferences.pageSize !== void 0) {
876
- const pageSizeIndex = this.getPageSizeIndex(preferences.pageSize);
877
- (0, import_react18.act)(() => modal.findPageSizePreference().findOptions()[pageSizeIndex].findLabel().click());
878
- }
879
- if (preferences.stickFirstColumns !== void 0) {
880
- (0, import_react18.act)(() => modal.findStickyColumnsPreference("first").findRadioGroup().findButtons()[preferences.stickFirstColumns].findNativeInput().click());
881
- }
882
- if (preferences.stickLastColumns !== void 0) {
883
- (0, import_react18.act)(() => modal.findStickyColumnsPreference("last").findRadioGroup().findButtons()[preferences.stickLastColumns].findNativeInput().click());
884
- }
885
- this.editCheckboxSetting(preferences.wrapLines, modal.findWrapLinesPreference());
886
- this.editCheckboxSetting(preferences.stripedRows, modal.findStripedRowsPreference());
887
- this.editCheckboxSetting(preferences.compact, modal.findContentDensityPreference());
888
- this.confirmPreferencesModal();
889
- }
890
- openPreferencesModal() {
891
- (0, import_react18.act)(() => this.getElementWrapper().findTriggerButton().click());
892
- (0, import_vitest13.expect)(this.getElementWrapper().findModal()).not.toBeNull();
893
- return this.getElementWrapper().findModal();
894
- }
895
- confirmPreferencesModal() {
896
- (0, import_react18.act)(() => this.getElementWrapper().findModal().findConfirmButton().click());
897
- }
898
- cancelPreferencesModal() {
899
- (0, import_react18.act)(() => this.getElementWrapper().findModal().findCancelButton().click());
900
- }
901
- getPageSizeIndex(pageSize) {
902
- const pageSizeIndex = this.supportedPageSizes.indexOf(pageSize);
903
- if (pageSizeIndex === -1) {
904
- throw new Error(`Unsupported page size: ${pageSize}, only following page sizes are supported: ${JSON.stringify(this.supportedPageSizes)}.`);
905
- }
906
- return pageSizeIndex;
907
- }
908
- editCheckboxSetting(settingValue, checkbox) {
909
- if (settingValue !== void 0) {
910
- if (settingValue !== checkbox.findNativeInput().getElement().checked) {
911
- (0, import_react18.act)(() => checkbox.findNativeInput().click());
912
- }
913
- }
914
- }
915
- expectCheckboxSetting(settingValue, checkbox) {
916
- if (settingValue !== void 0) {
917
- if (settingValue) {
918
- (0, import_vitest13.expect)(checkbox.findNativeInput().getElement()).toBeChecked();
919
- } else {
920
- (0, import_vitest13.expect)(checkbox.findNativeInput().getElement()).not.toBeChecked();
921
- }
922
- }
923
- }
924
- };
925
-
926
- // src/components/LinkTesting.ts
927
- var import_dom15 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
928
- var LinkTesting = class extends AbstractComponentTesting {
929
- constructor(fieldSpec, view) {
930
- super(fieldSpec, view, (selector) => (0, import_dom15.default)().findLink(selector));
931
- this.view = view;
932
- }
933
- };
934
-
935
- // src/components/ToggleTesting.ts
936
- var import_dom16 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
937
- var import_react19 = require("react");
938
- var ToggleTesting = class extends AbstractComponentTesting {
939
- constructor(fieldSpec, view) {
940
- super(fieldSpec, view, (selector) => (0, import_dom16.default)().findToggle(selector));
941
- this.view = view;
942
- }
943
- click() {
944
- (0, import_react19.act)(() => {
945
- this.getElementWrapper().findNativeInput().click();
946
- });
947
- }
948
- getElement() {
949
- const element = this.getElementWrapper().findNativeInput();
950
- return this.assertElement("None", () => element.getElement());
951
- }
952
- toggleIfNecessary(desiredCheckedState) {
953
- if (this.isChecked() !== desiredCheckedState) {
954
- this.click();
955
- }
956
- }
957
- isChecked() {
958
- return this.getElement().checked;
959
- }
960
- };
961
-
962
- // src/components/FlashbarTesting.ts
963
- var import_dom17 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
964
- var import_react20 = require("@testing-library/react");
965
- var import_vitest14 = require("vitest");
966
- var FlashbarTesting = class extends AbstractComponentTesting {
967
- constructor(fieldSpec, view) {
968
- super(fieldSpec, view, (selector) => (0, import_dom17.default)().findFlashbar(selector));
969
- this.view = view;
970
- }
971
- async awaitMessages() {
972
- await (0, import_react20.waitFor)(() => (0, import_vitest14.expect)(this.getElementWrapper().findItems().length).toBeGreaterThan(0));
973
- const wrappers = this.getElementWrapper().findItems();
974
- for (let index = 0; index < wrappers.length; index++) {
975
- const wrapper29 = wrappers[index];
976
- await (0, import_react20.waitFor)(() => (0, import_vitest14.expect)(wrapper29.findContent()).not.toBeNull());
977
- }
978
- }
979
- expectMessagePresentCount(text, count, headerMessage) {
980
- if (this.queryElement() === null) {
981
- (0, import_vitest14.expect)(0).toBe(count);
982
- } else {
983
- const wrappers = this.getElementWrapper().findItems();
984
- const textContent = wrappers.map((flash) => {
985
- const element = headerMessage ? flash.findHeader().getElement() : flash.findContent().getElement();
986
- return element.textContent;
987
- });
988
- let actualCount = 0;
989
- if (typeof text === "string") {
990
- actualCount = textContent.filter((txt) => txt === text).length;
991
- } else {
992
- actualCount = textContent.filter((txt) => text.test(txt)).length;
993
- }
994
- (0, import_vitest14.expect)(actualCount).toBe(count);
995
- }
996
- }
997
- expectMessagePresentOnce(text, headerMessage) {
998
- this.expectMessagePresentCount(text, 1, headerMessage);
999
- }
1000
- expectMessageNotPresent(text, headerMessage) {
1001
- this.expectMessagePresentCount(text, 0, headerMessage);
1002
- }
1003
- };
1004
-
1005
- // src/components/SegmentedControlTesting.ts
1006
- var import_dom18 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1007
- var import_react21 = require("@testing-library/react");
1008
- var import_react22 = require("react");
1009
- var import_vitest15 = require("vitest");
1010
- var SegmentedControlTesting = class extends AbstractComponentTesting {
1011
- constructor(fieldSpec, view, factory) {
1012
- super(fieldSpec, view, (selector) => (0, import_dom18.default)().findSegmentedControl(selector));
1013
- this.view = view;
1014
- this.factory = factory;
1015
- }
1016
- async selectEnum(enumValue) {
1017
- await this.select(this.factory.values.findIndex((value) => value === enumValue));
1018
- }
1019
- async select(index) {
1020
- (0, import_react22.act)(() => {
1021
- this.getElementWrapper().findSegments()[index].click();
1022
- });
1023
- await (0, import_react21.waitFor)(() => (0, import_vitest15.expect)(this.getElementWrapper().findSelectedSegment().getElement()).toStrictEqual(this.getElementWrapper().findSegments()[index].getElement()));
1024
- }
1025
- expectSelected(index) {
1026
- const selectedElement = this.getElementWrapper().findSelectedSegment();
1027
- if (selectedElement === null || selectedElement === void 0) {
1028
- throw new Error(this.elementNotFoundErrorMessage(this.elementSpec.getDataTestId()));
1029
- }
1030
- const expectedElement = this.getElementWrapper().findSegments()[index];
1031
- (0, import_vitest15.expect)(selectedElement).toStrictEqual(expectedElement);
1032
- }
1033
- expectSelectedEnum(enumValue) {
1034
- this.expectSelected(this.factory.values.findIndex((value) => value === enumValue));
1035
- }
1036
- getSelectedEnum() {
1037
- const selectedElement = this.getElementWrapper().findSelectedSegment();
1038
- if (selectedElement === null || selectedElement === void 0) {
1039
- throw new Error(this.elementNotFoundErrorMessage(this.elementSpec.getDataTestId()));
1040
- }
1041
- const textContent = selectedElement.getElement().textContent;
1042
- const allLabels = this.view.getLocaliser().getAllEnumLabels(this.factory);
1043
- const index = allLabels.findIndex((label) => label === textContent);
1044
- return this.factory.values[index];
1045
- }
1046
- };
1047
-
1048
- // src/components/AlertTesting.ts
1049
- var import_dom19 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1050
- var import_vitest16 = require("vitest");
1051
- var AlertTesting = class extends AbstractComponentTesting {
1052
- constructor(fieldSpec, view) {
1053
- super(fieldSpec, view, (selector) => (0, import_dom19.default)().findAlert(selector));
1054
- this.view = view;
1055
- }
1056
- expectContent(content) {
1057
- (0, import_vitest16.expect)(this.getElementWrapper().findContent().getElement()).toHaveTextContent(content);
1058
- }
1059
- expectLocalisation(variables, alternateNs) {
1060
- const localisedElements = this.view.getLocaliser().localiseField(this.elementSpec.getLocalisationKey(), variables, alternateNs);
1061
- this.expectContent(localisedElements.children);
1062
- }
1063
- };
1064
-
1065
- // src/components/StatusIndicatorTesting.ts
1066
- var import_dom20 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1067
- var import_vitest17 = require("vitest");
1068
- var StatusIndicatorTesting = class extends AbstractComponentTesting {
1069
- constructor(fieldSpec, view) {
1070
- super(fieldSpec, view, (selector) => (0, import_dom20.default)().findStatusIndicator(selector));
1071
- this.view = view;
1072
- }
1073
- expectContent(content) {
1074
- (0, import_vitest17.expect)(this.getElementWrapper().getElement()).toHaveTextContent(content);
1075
- }
1076
- };
1077
-
1078
- // src/components/CardsTesting.ts
1079
- var import_dom21 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1080
- var import_react23 = require("@testing-library/react");
1081
- var import_react24 = require("react");
1082
- var import_vitest18 = require("vitest");
1083
- var CardsTesting = class extends AbstractComponentTesting {
1084
- constructor(fieldSpec, view) {
1085
- super(fieldSpec, view, (selector) => (0, import_dom21.default)().findCards(selector));
1086
- this.view = view;
1087
- }
1088
- expectSelectedItems(selectedItemIndices) {
1089
- const allItems = this.getElementWrapper().findItems();
1090
- const selectedItems = this.getElementWrapper().findSelectedItems();
1091
- for (let index = 0; index < allItems.length; index++) {
1092
- if (selectedItemIndices.indexOf(index) !== -1) {
1093
- const item = allItems[index];
1094
- (0, import_vitest18.expect)(selectedItems).toContainEqual(item);
1095
- }
1096
- }
1097
- }
1098
- expectUnselectedItems(unselectedItemIndices) {
1099
- const allItems = this.getElementWrapper().findItems();
1100
- const selectedItems = this.getElementWrapper().findSelectedItems();
1101
- for (let index = 0; index < allItems.length; index++) {
1102
- if (unselectedItemIndices.indexOf(index) !== -1) {
1103
- const item = allItems[index];
1104
- (0, import_vitest18.expect)(selectedItems).not.toContain(item);
1105
- }
1106
- }
1107
- this.getElementWrapper().findLoadingText();
1108
- }
1109
- async awaitLoadingText(expectedText) {
1110
- await (0, import_react23.waitFor)(() => (0, import_vitest18.expect)(this.getElementWrapper().findLoadingText().getElement()).toHaveTextContent(expectedText));
1111
- return (0, import_react23.waitFor)(() => (0, import_vitest18.expect)(this.getElementWrapper().findLoadingText()).toBeNull());
1112
- }
1113
- clickItems(clickedItemIndices) {
1114
- const allItems = this.getElementWrapper().findItems();
1115
- for (let index = 0; index < allItems.length; index++) {
1116
- if (clickedItemIndices.indexOf(index) !== -1) {
1117
- const item = allItems[index];
1118
- const selectionArea = this.assertElement("none", () => item.findSelectionArea());
1119
- (0, import_react24.act)(() => {
1120
- selectionArea.click();
1121
- });
1122
- }
1123
- }
1124
- }
1125
- expectCardTitle(cardIndex, expectedTitle) {
1126
- (0, import_vitest18.expect)(this.getElementWrapper().findItems()[cardIndex].findCardHeader().getElement()).toHaveTextContent(expectedTitle);
1127
- }
1128
- getItemCount() {
1129
- return this.getElementWrapper().findItems().length;
1130
- }
1131
- async awaitLoading() {
1132
- await (0, import_react23.waitFor)(() => (0, import_vitest18.expect)(this.getElementWrapper().findLoadingText()).not.toBeNull());
1133
- }
1134
- async awaitNotLoading() {
1135
- await (0, import_react23.waitFor)(() => (0, import_vitest18.expect)(this.getElementWrapper().findLoadingText()).toBeNull());
1136
- }
1137
- };
1138
-
1139
- // src/components/TextareaTesting.ts
1140
- var import_dom22 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1141
- var import_react25 = require("react");
1142
- var import_vitest19 = require("vitest");
1143
- var TextareaTesting = class extends AbstractInputTesting {
1144
- constructor(fieldSpec, view) {
1145
- super(fieldSpec, view, (selector) => (0, import_dom22.default)().findTextarea(selector));
1146
- this.view = view;
1147
- }
1148
- setStringValue(value) {
1149
- (0, import_react25.act)(() => {
1150
- this.getElementWrapper().setTextareaValue(value);
1151
- });
1152
- }
1153
- expectValue(value) {
1154
- (0, import_vitest19.expect)(this.getNativeHTMLInput()).toHaveValue(value === void 0 ? "" : value);
1155
- }
1156
- getNativeHTMLInput() {
1157
- return this.getElementWrapper().findNativeTextarea().getElement();
1158
- }
1159
- };
1160
-
1161
- // src/components/TabsTesting.ts
1162
- var import_dom23 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1163
- var import_react26 = require("react");
1164
- var import_vitest20 = require("vitest");
1165
- var TabsTesting = class extends AbstractComponentTesting {
1166
- constructor(fieldSpec, view) {
1167
- super(fieldSpec, view, (selector) => (0, import_dom23.default)().findTabs(selector));
1168
- this.view = view;
1169
- }
1170
- expectActiveTab(index) {
1171
- const activeTab = this.getElementWrapper().findActiveTab();
1172
- this.assertTabAtIndex(activeTab, index);
1173
- const tabLinkByIndex = this.getElementWrapper().findTabLinkByIndex(index + 1);
1174
- this.assertTabAtIndex(tabLinkByIndex, index);
1175
- (0, import_vitest20.expect)(activeTab).toEqual(tabLinkByIndex);
1176
- }
1177
- selectTab(index) {
1178
- const tabLinkByIndex = this.getElementWrapper().findTabLinkByIndex(index + 1);
1179
- this.assertTabAtIndex(tabLinkByIndex, index);
1180
- (0, import_react26.act)(() => {
1181
- tabLinkByIndex.click();
1182
- });
1183
- }
1184
- assertTabAtIndex(tab, index) {
1185
- if (tab === null || tab === void 0) {
1186
- throw new Error(this.elementNotFoundErrorMessage("No tab at index = " + index.toString()));
1187
- }
1188
- }
1189
- };
1190
-
1191
- // src/components/TextFilterTesting.ts
1192
- var import_dom24 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1193
- var TextFilterTesting = class extends AbstractComponentTesting {
1194
- constructor(fieldSpec, view) {
1195
- super(fieldSpec, view, (selector) => (0, import_dom24.default)().findTextFilter(selector));
1196
- this.view = view;
1197
- }
1198
- };
1199
-
1200
- // src/components/TextContentTesting.ts
1201
- var import_dom25 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1202
- var import_vitest21 = require("vitest");
1203
- var TextContentTesting = class extends AbstractComponentTesting {
1204
- constructor(fieldSpec, view) {
1205
- super(fieldSpec, view, (selector) => (0, import_dom25.default)().findTextContent(selector));
1206
- this.view = view;
1207
- }
1208
- expectContent(content) {
1209
- (0, import_vitest21.expect)(this.getElementWrapper().getElement()).toHaveTextContent(content);
1210
- }
1211
- };
1212
-
1213
- // src/components/PaginationTesting.ts
1214
- var import_dom26 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1215
- var import_react27 = require("react");
1216
- var import_vitest22 = require("vitest");
1217
- var PaginationTesting = class extends AbstractComponentTesting {
1218
- constructor(fieldSpec, view) {
1219
- super(fieldSpec, view, (selector) => (0, import_dom26.default)().findPagination(selector));
1220
- this.view = view;
1221
- }
1222
- expectPageParams(currentPageDisplayIndex, pageCount) {
1223
- const pageNumbers = this.getElementWrapper().findPageNumbers();
1224
- const lastPage = pageNumbers[pageNumbers.length - 1];
1225
- (0, import_vitest22.expect)(lastPage.getElement()).toHaveTextContent(pageCount.toString());
1226
- (0, import_vitest22.expect)(this.getElementWrapper().findCurrentPage().getElement()).toHaveTextContent(currentPageDisplayIndex);
1227
- }
1228
- async changePage(fromIndex, toIndex) {
1229
- const nextButton = this.getElementWrapper().findNextPageButton();
1230
- const prevButton = this.getElementWrapper().findPreviousPageButton();
1231
- if (toIndex === fromIndex + 1) {
1232
- (0, import_react27.act)(() => nextButton.click());
1233
- } else if (toIndex === fromIndex - 1) {
1234
- (0, import_react27.act)(() => prevButton.click());
1235
- } else {
1236
- const pageIndexTo = (toIndex + 1).toString();
1237
- const pageNumbersWithIndex = this.getElementWrapper().findPageNumbers().filter((pageNumber) => pageNumber.getElement().textContent === pageIndexTo);
1238
- if (pageNumbersWithIndex.length !== 1) {
1239
- throw new Error(`Expected page index ${pageIndexTo} not displayed currently in pagination component! Here are the currently displayed page numbers: ${this.getElementWrapper().findPageNumbers().map((n) => n.getElement().textContent)}`);
1240
- }
1241
- (0, import_react27.act)(() => pageNumbersWithIndex[0].click());
1242
- }
1243
- }
1244
- };
1245
-
1246
- // src/components/FormTesting.ts
1247
- var import_dom27 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1248
- var FormTesting = class extends AbstractComponentTesting {
1249
- constructor(fieldSpec, view) {
1250
- super(fieldSpec, view, (selector) => (0, import_dom27.default)().findForm(selector));
1251
- this.view = view;
1252
- }
1253
- };
1254
-
1255
- // src/components/ProgressBarTesting.ts
1256
- var import_dom28 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1257
- var import_react28 = require("@testing-library/react");
1258
- var import_vitest23 = require("vitest");
1259
- var ProgressBarTesting = class extends AbstractComponentTesting {
1260
- constructor(fieldSpec, view) {
1261
- super(fieldSpec, view, (selector) => (0, import_dom28.default)().findProgressBar(selector));
1262
- this.view = view;
1263
- }
1264
- async awaitPercentageDisplay(text) {
1265
- await (0, import_react28.waitFor)(() => (0, import_vitest23.expect)(this.getElementWrapper().findPercentageText()).not.toBeNull());
1266
- const percentageText = this.getElementWrapper().findPercentageText();
1267
- await (0, import_react28.waitFor)(() => (0, import_vitest23.expect)(percentageText.findTextContent()).not.toBeNull());
1268
- await (0, import_react28.waitFor)(() => (0, import_vitest23.expect)(percentageText.findTextContent().getElement()).toHaveTextContent(text.toString()));
1269
- }
1270
- async awaitResultText(text) {
1271
- await (0, import_react28.waitFor)(() => (0, import_vitest23.expect)(this.getElementWrapper().findResultText().findTextContent().getElement()).toHaveTextContent(text));
1272
- }
1273
- };
1274
-
1275
- // src/components/IconTesting.ts
1276
- var import_dom29 = __toESM(require("@cloudscape-design/components/test-utils/dom"));
1277
- var IconTesting = class extends AbstractComponentTesting {
1278
- constructor(fieldSpec, view) {
1279
- super(fieldSpec, view, (selector) => (0, import_dom29.default)().findIcon(selector));
1280
- this.view = view;
1281
- }
1282
- };
1283
-
1284
- // src/components/TestingFactory.ts
1285
- var TestingFactory = class {
1286
- constructor(parentView) {
1287
- this.parentView = parentView;
1288
- }
1289
- multiselect(fieldSpec, expandToViewport) {
1290
- return new MultiselectTesting(fieldSpec, this.parentView, expandToViewport);
1291
- }
1292
- select(fieldSpec, expandToViewport) {
1293
- return new SelectTesting(fieldSpec, this.parentView, expandToViewport);
1294
- }
1295
- stringInput(fieldSpec) {
1296
- return new StringInputTesting(fieldSpec, this.parentView);
1297
- }
1298
- numberInput(fieldSpec) {
1299
- return new NumberInputTesting(fieldSpec, this.parentView);
1300
- }
1301
- table(fieldSpec) {
1302
- return new TableTesting(fieldSpec, this.parentView);
1303
- }
1304
- wizard(fieldSpec) {
1305
- return new WizardTesting(fieldSpec, this.parentView);
1306
- }
1307
- datePicker(fieldSpec) {
1308
- return new DatePickerTesting(fieldSpec, this.parentView);
1309
- }
1310
- button(fieldSpec) {
1311
- return new ButtonTesting(fieldSpec, this.parentView);
1312
- }
1313
- buttonDropdown(fieldSpec) {
1314
- return new ButtonDropdownTesting(fieldSpec, this.parentView);
1315
- }
1316
- modal(viewSpec) {
1317
- return new ModalTesting(viewSpec, this.parentView);
1318
- }
1319
- rating(viewSpec, factory, toOrderNumber) {
1320
- return new RatingTesting(viewSpec, this.parentView, factory, toOrderNumber);
1321
- }
1322
- checkbox(fieldSpec) {
1323
- return new CheckboxTesting(fieldSpec, this.parentView);
1324
- }
1325
- header(fieldSpec) {
1326
- return new HeaderTesting(fieldSpec, this.parentView);
1327
- }
1328
- box(fieldSpec) {
1329
- return new BoxTesting(fieldSpec, this.parentView);
1330
- }
1331
- collectionPreferences(fieldSpec, pageSizes) {
1332
- return new CollectionPreferencesTesting(fieldSpec, this.parentView, pageSizes);
1333
- }
1334
- link(fieldSpec) {
1335
- return new LinkTesting(fieldSpec, this.parentView);
1336
- }
1337
- toggle(fieldSpec) {
1338
- return new ToggleTesting(fieldSpec, this.parentView);
1339
- }
1340
- flashbar(fieldSpec) {
1341
- return new FlashbarTesting(fieldSpec, this.parentView);
1342
- }
1343
- segmentedControl(fieldSpec, factory) {
1344
- return new SegmentedControlTesting(fieldSpec, this.parentView, factory);
1345
- }
1346
- alert(fieldSpec) {
1347
- return new AlertTesting(fieldSpec, this.parentView);
1348
- }
1349
- statusIndicator(fieldSpec) {
1350
- return new StatusIndicatorTesting(fieldSpec, this.parentView);
1351
- }
1352
- cards(fieldSpec) {
1353
- return new CardsTesting(fieldSpec, this.parentView);
1354
- }
1355
- textarea(fieldSpec) {
1356
- return new TextareaTesting(fieldSpec, this.parentView);
1357
- }
1358
- tabs(fieldSpec) {
1359
- return new TabsTesting(fieldSpec, this.parentView);
1360
- }
1361
- textFilter(fieldSpec) {
1362
- return new TextFilterTesting(fieldSpec, this.parentView);
1363
- }
1364
- textContent(fieldSpec) {
1365
- return new TextContentTesting(fieldSpec, this.parentView);
1366
- }
1367
- pageSelect(fieldSpec) {
1368
- return new PaginationTesting(fieldSpec, this.parentView);
1369
- }
1370
- form(elementSpec) {
1371
- return new FormTesting(elementSpec, this.parentView);
1372
- }
1373
- progressBar(fieldSpec) {
1374
- return new ProgressBarTesting(fieldSpec, this.parentView);
1375
- }
1376
- icon(fieldSpec) {
1377
- return new IconTesting(fieldSpec, this.parentView);
1378
- }
1379
- };
1380
-
1381
- // src/views/AbstractViewTesting.tsx
1382
- var import_react29 = require("@testing-library/react");
1383
- var import_fs = require("fs");
1384
- var import_user_event = __toESM(require("@testing-library/user-event"));
1385
- var import_vitest24 = require("vitest");
1386
- var AbstractViewTesting = class {
1387
- constructor(namespace, viewSpec, testLocalisation) {
1388
- this.namespace = namespace;
1389
- this.viewSpec = viewSpec;
1390
- this.testLocalisation = testLocalisation;
1391
- this.factory = new TestingFactory(this);
1392
- this.parent = viewSpec.parent;
1393
- }
1394
- getLocaliser() {
1395
- return this.testLocalisation.getLocaliser(this.namespace);
1396
- }
1397
- fromSpec(componentSpec, testElements) {
1398
- return import_cswrapper6.ViewSpec.create(componentSpec.key, componentSpec.ns, (spec) => testElements(componentSpec.elements, this.factory));
1399
- }
1400
- printDOM() {
1401
- const dom = (0, import_react29.prettyDOM)(void 0, 1e7, { highlight: false });
1402
- if (dom) {
1403
- (0, import_fs.writeFileSync)("./DOM.txt", dom.toString());
1404
- }
1405
- }
1406
- /**
1407
- * renders the component
1408
- */
1409
- renderComponent() {
1410
- }
1411
- async waitForView(viewSpec) {
1412
- await this.factory.form(viewSpec).awaitPresent();
1413
- }
1414
- expectViewNotPresent(viewSpec) {
1415
- (0, import_vitest24.expect)(import_react29.screen.queryByTestId(viewSpec.getDataTestId())).not.toBeInTheDocument();
1416
- }
1417
- translate(key, variables, alternateNs) {
1418
- return this.getLocaliser().localiseKey(key, variables, alternateNs);
1419
- }
1420
- /**
1421
- * To test triggering the default action, e.g. form submit, by pressing enter.
1422
- */
1423
- async pressEnter(element) {
1424
- await import_user_event.default.type(element, "{enter}");
1425
- }
1426
- };
1427
-
1428
- // src/views/CSVNoItemsViewTesting.tsx
1429
- var import_cswrapper7 = require("@ebertjendustries/cswrapper");
1430
- var CSVNoItemsViewTesting = class extends AbstractViewTesting {
1431
- constructor(namespace, viewSpec, entityTypeFactory, testLocalisation) {
1432
- super(namespace, viewSpec, testLocalisation);
1433
- this.entityTypeFactory = entityTypeFactory;
1434
- this.noItemsView = this.fromSpec((0, import_cswrapper7.CSV_NO_ITEMS_VIEW_SPEC)(this.namespace), (elements, factory) => ({
1435
- boxHeading: factory.box(elements.boxHeading),
1436
- boxBody: factory.box(elements.boxBody)
1437
- }));
1438
- }
1439
- async awaitPresent() {
1440
- await this.waitForView((0, import_cswrapper7.CSV_NO_ITEMS_VIEW_SPEC)(this.namespace));
1441
- this.expectPresent();
1442
- }
1443
- async awaitNotPresent() {
1444
- await this.noItemsView.elements.boxHeading.awaitNotPresent();
1445
- }
1446
- expectPresent() {
1447
- this.noItemsView.elements.boxHeading.expectPresent();
1448
- }
1449
- expectNotPresent() {
1450
- this.noItemsView.elements.boxHeading.expectNotPresent();
1451
- }
1452
- expectLocalisation(itemType) {
1453
- this.noItemsView.elements.boxBody.expectLocalisation({ itemType: this.getLocaliser().getEnumLabel(this.entityTypeFactory, itemType) });
1454
- }
1455
- };
1456
-
1457
- // src/views/CSVPriceInputViewTesting.tsx
1458
- var import_cswrapper8 = require("@ebertjendustries/cswrapper");
1459
- var import_cswrapper9 = require("@ebertjendustries/cswrapper");
1460
- var CSVPriceInputViewTesting = class extends AbstractViewTesting {
1461
- constructor(namespace, viewSpec, testLocalisation, currencyFactory, expandToViewport) {
1462
- super(namespace, viewSpec, testLocalisation);
1463
- this.currencyFactory = currencyFactory;
1464
- this.expandToViewport = expandToViewport;
1465
- this.csvPriceInputView = this.fromSpec((0, import_cswrapper8.CSV_PRICE_INPUT_VIEW_SPEC)(this.parent, this.viewSpec.key), (elements, factory) => ({
1466
- amountInput: factory.numberInput(elements.inputPrice),
1467
- currencyInput: factory.select(elements.selectCurrency, this.expandToViewport),
1468
- displayBox: factory.box(elements.boxPriceDisplay)
1469
- }));
1470
- }
1471
- expectDisplayPrice(price) {
1472
- this.csvPriceInputView.elements.displayBox.expectContent(import_cswrapper9.PriceUtils.getFormattedPrice("en", price));
1473
- }
1474
- async setPrice(price) {
1475
- if (isNaN(price.priceInCents)) {
1476
- this.csvPriceInputView.elements.amountInput.clear();
1477
- } else {
1478
- const priceX = price.priceInCents / 100;
1479
- this.csvPriceInputView.elements.amountInput.setStringValue(priceX.toString());
1480
- }
1481
- await this.csvPriceInputView.elements.currencyInput.selectOrDeselect([this.currencyFactory.getEnumIndex(price.currency)]);
1482
- }
1483
- async expectPrice(price) {
1484
- if (isNaN(price.priceInCents)) {
1485
- this.csvPriceInputView.elements.amountInput.expectEmpty();
1486
- } else {
1487
- const priceX = price.priceInCents / 100;
1488
- this.csvPriceInputView.elements.amountInput.expectValue(priceX);
1489
- }
1490
- await this.csvPriceInputView.elements.currencyInput.expectEnumEntries(this.currencyFactory, [price.currency]);
1491
- }
1492
- };
1493
-
1494
- // src/views/CSVSearchFilterViewTesting.tsx
1495
- var import_cswrapper10 = require("@ebertjendustries/cswrapper");
1496
- var CSVSearchFilterViewTesting = class extends AbstractViewTesting {
1497
- constructor(namespace, viewSpec, testLocalisation) {
1498
- super(namespace, viewSpec, testLocalisation);
1499
- this.csvSearchFilterView = this.fromSpec((0, import_cswrapper10.CSV_SEARCH_FILTER_VIEW_SPEC)(this.parent, this.viewSpec.key), (elements, factory) => ({
1500
- searchTextFilter: factory.stringInput(elements.inputSearch),
1501
- searchButton: factory.button(elements.buttonSearch)
1502
- }));
1503
- }
1504
- async awaitNotLoading() {
1505
- await this.csvSearchFilterView.elements.searchButton.awaitNotLoading();
1506
- }
1507
- searchFor(searchText) {
1508
- this.csvSearchFilterView.elements.searchTextFilter.overwriteAndVerify(searchText);
1509
- this.search();
1510
- }
1511
- search() {
1512
- this.csvSearchFilterView.elements.searchButton.click();
1513
- }
1514
- editSearchText(searchText) {
1515
- this.csvSearchFilterView.elements.searchTextFilter.setStringValue(searchText);
1516
- }
1517
- expectState(expectedSearchText, disabledButton) {
1518
- this.csvSearchFilterView.elements.searchTextFilter.expectValue(expectedSearchText);
1519
- if (disabledButton) {
1520
- this.csvSearchFilterView.elements.searchButton.expectDisabled();
1521
- } else {
1522
- this.csvSearchFilterView.elements.searchButton.expectEnabled();
1523
- }
1524
- }
1525
- expectFilteringEnabled() {
1526
- this.csvSearchFilterView.elements.searchButton.expectEnabled();
1527
- }
1528
- expectFilteringDisabled() {
1529
- this.csvSearchFilterView.elements.searchButton.expectDisabled();
1530
- }
1531
- };
1532
-
1533
- // src/views/CSVTextPromptModalViewTesting.tsx
1534
- var import_cswrapper11 = require("@ebertjendustries/cswrapper");
1535
- var CSVTextPromptModalViewTesting = class extends AbstractViewTesting {
1536
- constructor(namespace, viewSpec, testLocalisation) {
1537
- super(namespace, viewSpec, testLocalisation);
1538
- this.csvTextPromptModalView = this.fromSpec((0, import_cswrapper11.CSV_TEXT_PROMPT_MODAL_VIEW_SPEC)(this.parent, this.viewSpec.key), (elements, factory) => ({
1539
- headerHeading: factory.header(elements.headerHeading),
1540
- boxBodyText: factory.box(elements.boxBodyText),
1541
- buttonPrimary: factory.button(elements.buttonPrimary),
1542
- buttonSecondary: factory.button(elements.buttonSecondary),
1543
- modal: factory.modal(this.viewSpec)
1544
- }));
1545
- }
1546
- expectHidden() {
1547
- this.csvTextPromptModalView.elements.modal.expectHidden();
1548
- }
1549
- expectVisible() {
1550
- this.csvTextPromptModalView.elements.modal.expectVisible();
1551
- }
1552
- async awaitVisible() {
1553
- return this.csvTextPromptModalView.elements.modal.awaitVisible();
1554
- }
1555
- async awaitHidden() {
1556
- return this.csvTextPromptModalView.elements.modal.awaitHidden();
1557
- }
1558
- dismiss() {
1559
- this.csvTextPromptModalView.elements.modal.dismiss();
1560
- }
1561
- confirm() {
1562
- this.csvTextPromptModalView.elements.buttonPrimary.click();
1563
- }
1564
- async expectVisibleAfterOpsThenConfirm(operations, navigatingAway) {
1565
- for (let index = 0; index < operations.length; index++) {
1566
- const operation = operations[index];
1567
- this.expectHidden();
1568
- operation();
1569
- await this.awaitVisible();
1570
- this.confirm();
1571
- if (!navigatingAway) {
1572
- await this.awaitHidden();
1573
- }
1574
- }
1575
- }
1576
- async expectVisibleAfterOpsThenDismiss(operations, navigatingAway) {
1577
- for (let index = 0; index < operations.length; index++) {
1578
- const operation = operations[index];
1579
- this.expectHidden();
1580
- operation();
1581
- await this.awaitVisible();
1582
- this.dismiss();
1583
- if (!navigatingAway) {
1584
- await this.awaitHidden();
1585
- }
1586
- }
1587
- }
1588
- };
1589
-
1590
- // src/mocks/MockBrowserAPIs.ts
1591
- var import_vitest25 = require("vitest");
1592
- var realDateNow = global.Date.now;
1593
- var MockBrowserAPIs = class {
1594
- static mockConfirmAlways(confirm) {
1595
- return window.confirm = import_vitest25.vi.fn().mockImplementation(() => confirm);
1596
- }
1597
- static mockScroll() {
1598
- return window.scrollTo = import_vitest25.vi.fn();
1599
- }
1600
- static mockDateNow(epochMillisToReturn) {
1601
- realDateNow = Date.now.bind(global.Date);
1602
- const dateNowStub = import_vitest25.vi.fn(() => epochMillisToReturn);
1603
- global.Date.now = dateNowStub;
1604
- return dateNowStub;
1605
- }
1606
- static resetDateNow() {
1607
- global.Date.now = realDateNow;
1608
- }
1609
- };
1610
-
1611
- // src/mocks/MockRestClient.ts
1612
- var import_vitest26 = require("vitest");
1613
- var import_console = require("console");
1614
- var import_cswrapper12 = require("@ebertjendustries/cswrapper");
1615
- var import_cswrapper13 = require("@ebertjendustries/cswrapper");
1616
- var RealRestClient = __toESM(require("@ebertjendustries/cswrapper"));
1617
- var import_cswrapper14 = require("@ebertjendustries/cswrapper");
1618
- var LOGGER = new import_cswrapper12.Log("RestClientMock");
1619
- var MockResponseStore = class {
1620
- constructor(parentUUID) {
1621
- this.parentUUID = parentUUID;
1622
- this.responses = {};
1623
- this.nextResponseIndex = {};
1624
- this.simulatedDelaysInSeconds = {};
1625
- }
1626
- addResponse(url, response, delayInMilliseconds) {
1627
- if (this.responses.hasOwnProperty(url)) {
1628
- this.responses[url].push(response);
1629
- this.simulatedDelaysInSeconds[url].push(delayInMilliseconds);
1630
- } else {
1631
- this.responses[url] = [response];
1632
- this.nextResponseIndex[url] = 0;
1633
- this.simulatedDelaysInSeconds[url] = [delayInMilliseconds];
1634
- }
1635
- }
1636
- consumeNextResponse(url) {
1637
- if (this.responses.hasOwnProperty(url)) {
1638
- const responses = this.responses[url];
1639
- const nextResponseIndex = this.nextResponseIndex[url];
1640
- if (nextResponseIndex === responses.length) {
1641
- throw new Error(`${this.parentUUID} Unexpected next call to url ${url}. Already consumed ${responses.length} call response(s). Please check your logic, maybe your prod code behaves in unexpected ways, or you forgot to add the mock response value.`);
1642
- }
1643
- const response = this.responses[url][nextResponseIndex];
1644
- this.nextResponseIndex[url] = this.nextResponseIndex[url] + 1;
1645
- return { response, delay: this.simulatedDelaysInSeconds[url][nextResponseIndex] };
1646
- } else {
1647
- throw new Error(`${this.parentUUID} No mock configured for url ${url}. Known urls are: ${Object.keys(this.responses)}.`);
1648
- }
1649
- }
1650
- expectAllCalled(hard) {
1651
- Object.keys(this.nextResponseIndex).forEach((url) => {
1652
- const expectedCondition = this.nextResponseIndex[url] === this.responses[url].length;
1653
- if (hard && !expectedCondition) {
1654
- throw new Error(`${this.parentUUID} For url ${url}, not every expected call has been consumed. Consumed ${this.nextResponseIndex[url]} calls, but expected ${this.responses[url].length} calls.`);
1655
- } else {
1656
- (0, import_console.assert)(expectedCondition, `${this.parentUUID} For url ${url}, not every expected call has been consumed. Consumed ${this.nextResponseIndex[url]} calls, but expected ${this.responses[url].length} calls.`);
1657
- }
1658
- });
1659
- }
1660
- };
1661
- function setupRestClientMock(controllerSpec) {
1662
- const mockRestClient = new MockRestClient(controllerSpec.key);
1663
- const mock = import_vitest26.vi.spyOn(RealRestClient, "createRestClient");
1664
- LOGGER.info(`Setting up mock rest client with key ${controllerSpec.key}.`);
1665
- mock.mockImplementation(() => {
1666
- return mockRestClient;
1667
- });
1668
- return mockRestClient;
1669
- }
1670
- var MockRestClient = class {
1671
- constructor(name) {
1672
- this.get = import_vitest26.vi.fn();
1673
- this.put = import_vitest26.vi.fn();
1674
- this.post = import_vitest26.vi.fn();
1675
- this.del = import_vitest26.vi.fn();
1676
- this.uuid = "<" + crypto.randomUUID().split("-")[4] + ">";
1677
- LOGGER.info(`Instantiating mock rest client with name ${name} and UUID ${this.uuid}.`);
1678
- this.getResponseValues = new MockResponseStore(this.uuid);
1679
- this.putResponseValues = new MockResponseStore(this.uuid);
1680
- this.postResponseValues = new MockResponseStore(this.uuid);
1681
- this.deleteResponseValues = new MockResponseStore(this.uuid);
1682
- this.mockGet();
1683
- this.mockPut();
1684
- this.mockPost();
1685
- this.mockDelete();
1686
- }
1687
- expectAllHaveBeenCalled(hard) {
1688
- this.getResponseValues.expectAllCalled(hard);
1689
- this.putResponseValues.expectAllCalled(hard);
1690
- this.postResponseValues.expectAllCalled(hard);
1691
- this.deleteResponseValues.expectAllCalled(hard);
1692
- }
1693
- addGetResponse(url, response, delayInMilliseconds) {
1694
- LOGGER.info(`${this.uuid} Configuring GET ${url} ${this.getDelayForLogging(delayInMilliseconds)}.`);
1695
- this.getResponseValues.addResponse(url, response, delayInMilliseconds);
1696
- }
1697
- addPutResponse(url, response, delayInMilliseconds) {
1698
- LOGGER.info(`${this.uuid} Configuring PUT ${url} ${this.getDelayForLogging(delayInMilliseconds)}.`);
1699
- this.putResponseValues.addResponse(url, response, delayInMilliseconds);
1700
- }
1701
- addPostResponse(url, response, delayInMilliseconds) {
1702
- LOGGER.info(`${this.uuid} Configuring POST ${url} ${this.getDelayForLogging(delayInMilliseconds)}.`);
1703
- this.postResponseValues.addResponse(url, response, delayInMilliseconds);
1704
- }
1705
- addDeleteResponse(url, response, delayInMilliseconds) {
1706
- LOGGER.info(`${this.uuid} Configuring DELETE ${url} ${this.getDelayForLogging(delayInMilliseconds)}.`);
1707
- this.deleteResponseValues.addResponse(url, response, delayInMilliseconds);
1708
- }
1709
- getDelayForLogging(delayInMilliseconds) {
1710
- return delayInMilliseconds === void 0 ? "- no delay" : `- ${delayInMilliseconds} ms`;
1711
- }
1712
- mockGet() {
1713
- this.doMocking(this.get, this.getResponseValues);
1714
- }
1715
- mockPut() {
1716
- this.doMocking(this.put, this.putResponseValues);
1717
- }
1718
- mockPost() {
1719
- this.doMocking(this.post, this.postResponseValues);
1720
- }
1721
- mockDelete() {
1722
- this.doMocking(this.del, this.deleteResponseValues);
1723
- }
1724
- doMocking(mock, mockResponseStore) {
1725
- mock.mockImplementation(
1726
- async (endpoint, payload, operation, header) => {
1727
- const val = mockResponseStore.consumeNextResponse(endpoint);
1728
- const response = val.response;
1729
- const delayInMilliseconds = val.delay;
1730
- if (delayInMilliseconds !== void 0) {
1731
- await (0, import_cswrapper13.sleep)(delayInMilliseconds);
1732
- }
1733
- if (response !== null && response !== void 0 && (0, import_cswrapper14.isContentWithMessages)(response)) {
1734
- return Promise.reject(response);
1735
- }
1736
- return this.mockImpl(response, endpoint, payload, operation, header);
1737
- }
1738
- );
1739
- }
1740
- mockImpl(returnValue, endpoint, payload, operation, header) {
1741
- LOGGER.debug(`${this.uuid} -----------> Mock REST API call <---------------`);
1742
- LOGGER.debug(`${this.uuid} Calling REST API endpoint ${endpoint} with operation ${operation} and header <${header}>`);
1743
- const returnPromise = Promise.resolve({ content: returnValue, messages: [] });
1744
- LOGGER.debug(`${this.uuid} DONE calling REST API endpoint ${endpoint} with operation ${operation} and header ${header}`);
1745
- return returnPromise;
1746
- }
1747
- };
1748
-
1749
- // src/mocks/MockServerBuilder.ts
1750
- var MockServerBuilder = class _MockServerBuilder {
1751
- constructor(port, requireFunc) {
1752
- this.port = port;
1753
- this.mockData = {};
1754
- this.redirectUrls = {};
1755
- this.jsonServer = requireFunc("json-server");
1756
- this.server = this.jsonServer.create();
1757
- this.server.use(this.jsonServer.bodyParser);
1758
- }
1759
- addToMockData(key, data) {
1760
- this.mockData[key] = data;
1761
- }
1762
- /**
1763
- * Puts mock data: Adds it to internal data structures and prepares it for mocking. It potentially updates
1764
- * the overall mock data object later passed into jsonServer router as well as the rewrite object later
1765
- * passed into jsonServer.rewriter.
1766
- *
1767
- * @param key The key of the data
1768
- * @param data The data itself
1769
- * @param urlRedirects The redirect URLs to be rewritten to the key url
1770
- * @param crud Whether this is a crud redirect
1771
- * @returns The loaded mock data object
1772
- */
1773
- putMockData(key, data, urlRedirects, crud) {
1774
- this.addToMockData(key, data);
1775
- if (crud !== void 0) {
1776
- this.addToRedirects(key, urlRedirects, crud);
1777
- } else {
1778
- this.addToRedirects(key, urlRedirects, false);
1779
- }
1780
- }
1781
- addToRedirects(key, urlRedirects, crud) {
1782
- urlRedirects.forEach((urlRedirect) => this.redirectUrls[urlRedirect] = "/" + key);
1783
- if (crud) {
1784
- urlRedirects.forEach((urlRedirect) => this.redirectUrls[urlRedirect + "/:id"] = "/" + key + "/:id");
1785
- }
1786
- }
1787
- rewritePostToGet(url) {
1788
- this.useCors(url);
1789
- this.server.use(url, _MockServerBuilder.postRewriteToGet);
1790
- }
1791
- static set200WithData(res, data) {
1792
- res.status(200).jsonp({ content: data });
1793
- }
1794
- static respondWithError(res, componentId, messageId, httpStatus, op, message) {
1795
- res.status(httpStatus).jsonp({
1796
- messages: [
1797
- {
1798
- "code": {
1799
- "componentId": componentId,
1800
- "httpStatusCode": httpStatus,
1801
- "localCode": messageId,
1802
- "messageSeverity": "ERR",
1803
- "uniqueCode": componentId + messageId
1804
- },
1805
- "correlationId": "N/A",
1806
- "detailMessage": message,
1807
- "operation": op,
1808
- "timestamp": "2022-05-10T15:17:08Z"
1809
- }
1810
- ]
1811
- });
1812
- }
1813
- mockCall(url, callProcessor) {
1814
- this.useCors(url);
1815
- this.server.use(url, callProcessor);
1816
- }
1817
- mockCRUDMulti(urls, allElements, finder, operationDesc) {
1818
- urls.forEach((url) => this.mockCRUD(url, allElements, finder, operationDesc));
1819
- }
1820
- mockCRUD(url, allElements, finder, operationDesc) {
1821
- this.mockCall(`${url}${url.endsWith("/") ? "" : "/"}:id`, async (req, res, next) => {
1822
- const method = req.method;
1823
- const id = parseInt(req.params["id"]);
1824
- console.log(`Calling ${operationDesc} CRUD ${method} with id ${id}`);
1825
- if (method === "GET") {
1826
- let returnedEntity = finder(id);
1827
- _MockServerBuilder.set200WithData(res, returnedEntity);
1828
- } else {
1829
- _MockServerBuilder.set200WithData(res, {});
1830
- }
1831
- });
1832
- this.mockCall(`${url}`, async (req, res, next) => {
1833
- const method = req.method;
1834
- console.log(`Calling ${operationDesc} CRUD ${method}${method === "GET" ? " ALL" : ""}`);
1835
- if (method === "GET") {
1836
- _MockServerBuilder.set200WithData(res, allElements);
1837
- } else if (method === "PUT") {
1838
- _MockServerBuilder.set200WithData(res, req.body);
1839
- } else {
1840
- _MockServerBuilder.set200WithData(res, {});
1841
- }
1842
- });
1843
- }
1844
- start() {
1845
- console.log("Mock data keys: " + Object.keys(this.mockData));
1846
- console.log("Redirect URLs: ", this.redirectUrls);
1847
- const router = this.jsonServer.router(this.mockData);
1848
- const middlewares = this.jsonServer.defaults();
1849
- this.server.use(this.jsonServer.rewriter(this.redirectUrls));
1850
- Object.keys(this.redirectUrls).forEach((redirectUrl) => {
1851
- this.useCors(redirectUrl);
1852
- });
1853
- this.server.use(middlewares);
1854
- this.server.use(router);
1855
- router.render = function(req, res) {
1856
- res.jsonp({
1857
- content: res.locals.data
1858
- });
1859
- };
1860
- this.server.listen(this.port, () => {
1861
- console.log("JSON Server is running on port " + this.port);
1862
- });
1863
- }
1864
- useCors(url) {
1865
- console.log("Configuring CORS for: ", url);
1866
- this.server.use(url, _MockServerBuilder.allowCors);
1867
- }
1868
- static allowCors(req, res, next) {
1869
- res.header("Access-Control-Allow-Origin", "*");
1870
- res.header("Access-Control-Allow-Headers", "*");
1871
- res.header("Access-Control-Allow-Methods", "*");
1872
- next();
1873
- }
1874
- static postRewriteToGet(req, res, next) {
1875
- if (req.method === "POST") {
1876
- console.log(`Received POST request, rewriting to GET: ` + req.url);
1877
- req.method = "GET";
1878
- }
1879
- next();
1880
- }
1881
- };
1882
-
1883
- // src/utils/ViewTestWrapper.tsx
1884
- var import_react30 = require("react");
1885
- var import_jsx_runtime = require("react/jsx-runtime");
1886
- function ViewTestWrapper(props) {
1887
- const [value, setValue] = (0, import_react30.useState)(props.initialValue);
1888
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: props.view(value, (propertyName, changedValue) => setValue(changedValue)) });
1889
- }
1890
- // Annotate the CommonJS export names for ESM import in node:
1891
- 0 && (module.exports = {
1892
- AbstractComponentTesting,
1893
- AbstractInputTesting,
1894
- AbstractSelectTesting,
1895
- AbstractViewTesting,
1896
- AlertTesting,
1897
- BoxTesting,
1898
- ButtonDropdownTesting,
1899
- ButtonTesting,
1900
- CSVNoItemsViewTesting,
1901
- CSVPriceInputViewTesting,
1902
- CSVSearchFilterViewTesting,
1903
- CSVTextPromptModalViewTesting,
1904
- CardsTesting,
1905
- CheckboxTesting,
1906
- CollectionPreferencesSetting,
1907
- CollectionPreferencesTesting,
1908
- DatePickerTesting,
1909
- FlashbarTesting,
1910
- FormTesting,
1911
- HeaderTesting,
1912
- IconTesting,
1913
- LinkTesting,
1914
- MockBrowserAPIs,
1915
- MockRestClient,
1916
- MockServerBuilder,
1917
- ModalTesting,
1918
- MultiselectTesting,
1919
- NumberInputTesting,
1920
- PaginationTesting,
1921
- ProgressBarTesting,
1922
- RatingTesting,
1923
- SegmentedControlTesting,
1924
- SelectTesting,
1925
- StatusIndicatorTesting,
1926
- StringInputTesting,
1927
- TableTesting,
1928
- TabsTesting,
1929
- TestLocalisation,
1930
- TestingFactory,
1931
- TextContentTesting,
1932
- TextFilterTesting,
1933
- TextareaTesting,
1934
- ToggleTesting,
1935
- ViewTestWrapper,
1936
- WizardTesting,
1937
- setupRestClientMock
1938
- });