-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy patharrayProperty.spec.ts
More file actions
564 lines (404 loc) · 22.6 KB
/
arrayProperty.spec.ts
File metadata and controls
564 lines (404 loc) · 22.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
import {type Page, expect, mergeTests} from '@playwright/test';
import {importWorkflowTest, loginTest, projectTest} from '../../fixtures';
import {WorkflowPage} from '../../pages/workflowPage';
import sampleWorkflow from '../../sampleWorkflow.json';
import {clickAndExpectToBeVisible} from '../../utils/clickAndExpectToBeVisible';
import {type TestProjectI, type TestWorkflowI} from '../../utils/projectUtils';
import {
type WorkflowDefinitionI,
addArrayItemViaPopover,
getPropertyValue,
getWorkflowDefinition,
openPropertiesTab,
reopenConfigurationPanel,
replaceMentionsInputValue,
} from '../../utils/workflowUtils';
const SAMPLE_VAR_ARRAY = getPropertyValue({
propertyName: 'Array',
taskName: 'var_1',
workflowDefinition: sampleWorkflow as WorkflowDefinitionI,
}) as string[] | undefined;
export const test = mergeTests(loginTest(), projectTest, importWorkflowTest);
test.describe('ArrayProperty - Array property type (ArrayProperty.tsx)', () => {
let authenticatedPage: Page;
let project: TestProjectI;
let workflow: TestWorkflowI;
let workflowPage: WorkflowPage;
test.beforeEach(async ({authenticatedPage: page, project: testProject, workflow: testWorkflow}) => {
authenticatedPage = page;
project = testProject;
workflow = testWorkflow;
workflowPage = new WorkflowPage(authenticatedPage);
await test.step('Navigate to workflow editor and wait for load', async () => {
await workflowPage.goToWorkflowEditor(project.id, workflow.workflowId);
});
await test.step('Open var_1 node configuration panel', async () => {
await clickAndExpectToBeVisible({
target: workflowPage.firstTaskComponentConfigurationPanel,
trigger: workflowPage.firstNode,
});
});
await test.step('Switch to the Properties tab and expand value', async () => {
await openPropertiesTab(workflowPage.firstTaskComponentConfigurationPanel);
const valuePropertyList = workflowPage.parentObjectProperty.getByRole('list', {
name: 'value object properties',
});
await expect(valuePropertyList).toBeVisible();
});
});
test.describe('Rendering from workflow definition', () => {
test('should render array property with items from workflow definition', async () => {
await test.step('Locate Array property section', async () => {
await expect(workflowPage.arrayProperty).toBeVisible();
});
await test.step('Verify array items are rendered', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
const expectedArray = SAMPLE_VAR_ARRAY;
await expect(arrayItems).toHaveCount(expectedArray?.length ?? 0);
});
await test.step('Verify first array item value matches definition', async () => {
const input = workflowPage.arrayPropertyItemTextboxAt(0);
const expectedValue = SAMPLE_VAR_ARRAY?.[0];
await expect(input).toContainText(expectedValue ?? '');
});
});
test('should render array item with correct control type (e.g. STRING)', async () => {
await test.step('Verify item at index 0 has textbox for STRING type', async () => {
const arrayPropertyItemTextboxAtIndex0 = workflowPage.arrayPropertyItemTextboxAt(0);
await expect(arrayPropertyItemTextboxAtIndex0).toBeVisible();
});
});
});
test.describe('Add array item', () => {
test('should show Add array item button when array has single item type', async () => {
const addButton = workflowPage.arrayProperty.getByRole('button', {name: /Add array item/i});
await expect(addButton).toBeVisible();
});
test('should add new item when clicking Add array item', async () => {
const initialCount = SAMPLE_VAR_ARRAY?.length ?? 0;
await test.step('Add an array item', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
page: authenticatedPage,
});
});
await test.step('Verify new item appears at next index', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(initialCount + 1);
});
});
test('should persist new array item to workflow definition after add', async () => {
await test.step('Add array item and wait for debounced save', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
page: authenticatedPage,
});
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Verify workflow definition contains updated array', async () => {
const workflowDefinition = await getWorkflowDefinition(authenticatedPage, workflow.workflowId);
const arrayValue = WorkflowPage.getFirstTaskArrayParameter(workflowDefinition);
WorkflowPage.assertVar1ArrayParameterIsDefined(arrayValue);
});
});
test('should show SubPropertyPopover when array has multiple item types', async () => {
await test.step('Click Add array item and verify popover with type selector appears', async () => {
const addButton = workflowPage.arrayProperty.getByRole('button', {name: /Add array item/i});
const popover = authenticatedPage.getByLabel('Array property popover');
await clickAndExpectToBeVisible({
target: popover,
trigger: addButton,
});
const typeCombobox = popover.getByRole('combobox');
await expect(typeCombobox).toBeVisible();
await authenticatedPage.keyboard.press('Escape');
await expect(popover).not.toBeVisible();
});
await test.step('Select a different type and add item', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
itemType: 'INTEGER',
page: authenticatedPage,
});
const arrayItems = workflowPage.arrayPropertyItems;
const expectedInitialCount = SAMPLE_VAR_ARRAY?.length ?? 0;
await expect(arrayItems).toHaveCount(expectedInitialCount + 1);
});
});
});
test.describe('Delete array item', () => {
test('should show delete button on custom array items', async () => {
await test.step('Add an item so the new item has custom: true and shows delete button', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
page: authenticatedPage,
});
});
await test.step('Verify delete button is present on the added item', async () => {
const addedItem = workflowPage.arrayPropertyItemAt(0);
const deleteButton = addedItem.getByRole('button');
await expect(deleteButton).toBeVisible();
});
});
test('should remove item from list when delete is clicked', async () => {
await test.step('Add two items', async () => {
await workflowPage.addArrayItemsToReachRowCount({
targetRowCount: 2,
});
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(2);
});
await test.step('Delete the first item', async () => {
const firstItem = workflowPage.arrayPropertyItemAt(0);
const deleteButton = firstItem.getByRole('button');
await deleteButton.click();
});
await test.step('Verify item count decreased back to 1', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(1);
});
});
test('should persist array after delete to workflow definition', async () => {
await test.step('Add item then delete it and wait for debounced save', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
page: authenticatedPage,
});
await authenticatedPage.waitForTimeout(WorkflowPage.SHORT_DEBOUNCE_MS);
const addedItem = workflowPage.arrayPropertyItemAt(1);
await addedItem.getByRole('button').click();
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Verify workflow definition array has one item again', async () => {
const workflowDefinition = await getWorkflowDefinition(authenticatedPage, workflow.workflowId);
const arrayValue = WorkflowPage.getFirstTaskArrayParameter(workflowDefinition);
WorkflowPage.assertVar1ArrayParameterIsDefined(arrayValue);
expect(arrayValue).toHaveLength(1);
});
});
test('should not show the deleted row value on the next row when the next row was empty', async () => {
const valueOnDeletedRow = 'ByteChef';
await test.step('Add a second row; first row has a value, second row stays empty', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
page: authenticatedPage,
});
await authenticatedPage.waitForTimeout(WorkflowPage.SHORT_DEBOUNCE_MS);
const firstRowInput = workflowPage.arrayPropertyItemTextboxAt(0);
await firstRowInput.fill(valueOnDeletedRow);
const secondRowInput = workflowPage.arrayPropertyItemTextboxAt(1);
await expect(secondRowInput).toHaveText('');
});
await test.step('Delete the first row (the row that held the value)', async () => {
const firstRow = workflowPage.arrayPropertyItemAt(0);
await firstRow.getByRole('button').click();
});
await test.step('The remaining row must stay empty (value must not jump from the deleted row)', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(1);
const remainingRowInput = workflowPage.arrayPropertyItemTextboxAt(0);
await expect(remainingRowInput).toBeEmpty();
});
});
test('should not show the deleted middle row value on another row when neighbors were empty', async () => {
const valueOnMiddleRow = 'ByteChef';
await test.step('Add two rows so there are three rows total', async () => {
await workflowPage.addArrayItemsToReachRowCount({
targetRowCount: 3,
});
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(3);
});
await test.step('Clear first row, set middle row value, leave last row empty', async () => {
const firstRowInput = workflowPage.arrayPropertyItemTextboxAt(0);
await firstRowInput.fill('');
const middleRowInput = workflowPage.arrayPropertyItemTextboxAt(1);
await middleRowInput.fill(valueOnMiddleRow);
const lastRowInput = workflowPage.arrayPropertyItemTextboxAt(2);
await expect(lastRowInput).toHaveText('');
});
await test.step('Delete the middle row', async () => {
const middleRow = workflowPage.arrayPropertyItemAt(1);
await middleRow.getByRole('button').click();
});
await test.step('Neither remaining row should display the deleted middle value', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(2);
const firstRemainingInput = workflowPage.arrayPropertyItemTextboxAt(0);
const secondRemainingInput = workflowPage.arrayPropertyItemTextboxAt(1);
await expect(firstRemainingInput).not.toContainText(valueOnMiddleRow);
await expect(secondRemainingInput).not.toContainText(valueOnMiddleRow);
});
});
test('should show foo and bar in order after deleting the empty middle item', async () => {
const firstRowValue = 'foo';
const thirdRowValue = 'bar';
await test.step('Add two rows so there are three rows total', async () => {
await workflowPage.addArrayItemsToReachRowCount({
targetRowCount: 3,
});
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(3);
});
await test.step('Set first row to foo, leave second row empty, set third row to bar', async () => {
const firstRowInput = workflowPage.arrayPropertyItemTextboxAt(0);
await replaceMentionsInputValue({
input: firstRowInput,
page: authenticatedPage,
value: firstRowValue,
});
const middleRowInput = workflowPage.arrayPropertyItemTextboxAt(1);
await replaceMentionsInputValue({
input: middleRowInput,
page: authenticatedPage,
value: '',
});
const thirdRowInput = workflowPage.arrayPropertyItemTextboxAt(2);
await replaceMentionsInputValue({
input: thirdRowInput,
page: authenticatedPage,
value: thirdRowValue,
});
await expect(thirdRowInput).toHaveText(thirdRowValue, {timeout: 10000});
await expect(middleRowInput).toBeEmpty();
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Delete the middle row (the one with no value)', async () => {
const middleRow = workflowPage.arrayPropertyItemAt(1);
await middleRow.getByRole('button').click();
});
await test.step('UI shows foo then bar on the two remaining rows', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(2);
const firstRemainingInput = workflowPage.arrayPropertyItemTextboxAt(0);
const secondRemainingInput = workflowPage.arrayPropertyItemTextboxAt(1);
await expect(firstRemainingInput).toHaveText(firstRowValue, {timeout: 30000});
await expect(secondRemainingInput).toHaveText(thirdRowValue, {timeout: 30000});
});
});
test('should keep the following INTEGER row empty after deleting a filled INTEGER row above it', async () => {
const valueOnDeletedIntegerRow = '1337';
await test.step('Add two INTEGER rows (STRING, INTEGER, INTEGER)', async () => {
await workflowPage.addArrayItemsToReachRowCount({
itemType: 'INTEGER',
targetRowCount: 3,
});
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(3);
});
await test.step('Set first INTEGER row to a value and leave the second INTEGER row empty', async () => {
const firstIntegerInput = workflowPage.arrayPropertyItemSpinbuttonAt(1);
await replaceMentionsInputValue({
input: firstIntegerInput,
page: authenticatedPage,
value: valueOnDeletedIntegerRow,
});
const secondIntegerInput = workflowPage.arrayPropertyItemSpinbuttonAt(2);
await replaceMentionsInputValue({
input: secondIntegerInput,
page: authenticatedPage,
value: '',
});
await expect(secondIntegerInput).toHaveValue('');
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Delete the INTEGER row that holds the value', async () => {
const integerRowWithValue = workflowPage.arrayPropertyItemAt(1);
await integerRowWithValue.getByRole('button').last().click();
});
await test.step('The INTEGER row that was empty after it must stay empty', async () => {
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(2);
const remainingIntegerRowAfterDeleted = workflowPage.arrayPropertyItemSpinbuttonAt(1);
await expect(remainingIntegerRowAfterDeleted).toHaveValue('');
});
});
});
test.describe('Edit array item value', () => {
test('should allow editing value in array item', async () => {
await test.step('Change value in first array item', async () => {
const firstArrayItemTextbox = workflowPage.arrayPropertyItemTextboxAt(0);
await firstArrayItemTextbox.fill('edited array value');
});
await test.step('Wait for debounced save', async () => {
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
});
test('should persist edited array item value to workflow definition', async () => {
const newValue = 'persisted array value';
await test.step('Edit first array item', async () => {
const firstArrayItemTextbox = workflowPage.arrayPropertyItemTextboxAt(0);
await firstArrayItemTextbox.fill(newValue);
});
await test.step('Wait for debounced save', async () => {
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Verify workflow definition has new value', async () => {
const workflowDefinition = await getWorkflowDefinition(authenticatedPage, workflow.workflowId);
const arrayValue = WorkflowPage.getFirstTaskArrayParameter(workflowDefinition);
WorkflowPage.assertVar1ArrayParameterIsDefined(arrayValue);
expect((arrayValue as string[])[0]).toBe(newValue);
});
});
test('should persist after reload when array item value was edited', async () => {
const newValue = 'reload persisted value';
await test.step('Edit first array item', async () => {
const firstArrayItemTextbox = workflowPage.arrayPropertyItemTextboxAt(0);
await firstArrayItemTextbox.fill(newValue);
});
await test.step('Wait for debounced save', async () => {
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Reload and verify value persists', async () => {
await authenticatedPage.reload();
await authenticatedPage.waitForLoadState('domcontentloaded');
await authenticatedPage.waitForTimeout(2000);
await reopenConfigurationPanel(authenticatedPage);
await openPropertiesTab(workflowPage.firstTaskComponentConfigurationPanel);
const firstArrayItemTextbox = workflowPage.arrayPropertyItemTextboxAt(0);
await expect(firstArrayItemTextbox).toContainText(newValue);
});
});
// Regression for the stale-node-data bug: useLayout skips re-runs on
// parameter-only changes, so nodes[i].data.parameters stayed frozen at
// the first layout. Clicking another node and coming back seeded the
// details panel from stale data and the just-added item disappeared
// until the next full page reload.
test('should keep edits visible after opening another node and returning to var_1', async () => {
const newValue = 'still here after node switch';
await test.step('Add a new array item and fill it', async () => {
await addArrayItemViaPopover({
arrayProperty: workflowPage.arrayProperty,
page: authenticatedPage,
});
const initialCount = SAMPLE_VAR_ARRAY?.length ?? 0;
const newItemTextbox = workflowPage.arrayPropertyItemTextboxAt(initialCount);
await replaceMentionsInputValue({
input: newItemTextbox,
page: authenticatedPage,
value: newValue,
});
await authenticatedPage.waitForTimeout(WorkflowPage.LONG_DEBOUNCE_MS);
});
await test.step('Open another node (propertyTesting_1), then return to var_1', async () => {
const otherNode = authenticatedPage.getByLabel('propertyTesting_1 node');
await clickAndExpectToBeVisible({
target: authenticatedPage.getByLabel('propertyTesting_1 component configuration panel'),
trigger: otherNode,
});
await clickAndExpectToBeVisible({
target: workflowPage.firstTaskComponentConfigurationPanel,
trigger: workflowPage.firstNode,
});
await openPropertiesTab(workflowPage.firstTaskComponentConfigurationPanel);
});
await test.step('Newly added item value must still be rendered (no stale node data)', async () => {
const initialCount = SAMPLE_VAR_ARRAY?.length ?? 0;
const arrayItems = workflowPage.arrayPropertyItems;
await expect(arrayItems).toHaveCount(initialCount + 1);
const newItemTextbox = workflowPage.arrayPropertyItemTextboxAt(initialCount);
await expect(newItemTextbox).toContainText(newValue);
});
});
});
});