-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPlan.ts
More file actions
611 lines (556 loc) · 28.9 KB
/
Plan.ts
File metadata and controls
611 lines (556 loc) · 28.9 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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';
import { adjectives, animals, colors, uniqueNamesGenerator } from 'unique-names-generator';
import { Status } from '../../src/enums/status';
import { Constraints } from './Constraints.js';
import { Plans } from './Plans.js';
import { SchedulingConditions } from './SchedulingConditions.js';
import { SchedulingGoals } from './SchedulingGoals.js';
export class Plan {
activitiesTable: Locator;
activitiesTableFirstRow: Locator;
activityCheckingStatusSelector: (status: string) => string;
analyzeButton: Locator;
appError: Locator;
consoleContainer: Locator;
constraintListItemSelector: string;
constraintManageButton: Locator;
constraintModalFilter: Locator;
constraintNewButton: Locator;
externalSourceManageButton: Locator;
gridMenu: Locator;
gridMenuButton: Locator;
gridMenuItem: (name: string) => Locator;
navButtonActivityChecking: Locator;
navButtonActivityCheckingMenu: Locator;
navButtonConstraints: Locator;
navButtonConstraintsMenu: Locator;
navButtonExpansion: Locator;
navButtonExpansionMenu: Locator;
navButtonScheduling: Locator;
navButtonSchedulingMenu: Locator;
navButtonSimulation: Locator;
navButtonSimulationMenu: Locator;
navButtonSimulationMenuStatus: Locator;
panelActivityDirectivesTable: Locator;
panelActivityForm: Locator;
panelActivityTypes: Locator;
panelConstraints: Locator;
panelExpansion: Locator;
panelPlanMetadata: Locator;
panelSchedulingConditions: Locator;
panelSchedulingGoals: Locator;
panelSimulatedActivitiesTable: Locator;
panelSimulation: Locator;
panelTimeline: Locator;
panelTimelineEditor: Locator;
planCollaboratorInput: Locator;
planCollaboratorInputContainer: Locator;
planCollaboratorLoadingInput: Locator;
planNameInput: Locator;
planTitle: Locator;
reSimulateButton: Locator;
roleSelector: Locator;
scheduleButton: Locator;
schedulingConditionEnabledCheckboxSelector: (conditionName: string) => Locator;
schedulingConditionListItemSelector: (conditionName: string) => string;
schedulingConditionManageButton: Locator;
schedulingConditionNewButton: Locator;
schedulingConditionsModalFilter: Locator;
schedulingGoal: (goalName: string) => Locator;
schedulingGoalDifferenceBadge: (goalName: string) => Locator;
schedulingGoalEnabledCheckboxSelector: (goalName: string) => Locator;
schedulingGoalExpand: (goalName: string) => Locator;
schedulingGoalListItemSelector: (goalName: string) => string;
schedulingGoalManageButton: Locator;
schedulingGoalNewButton: Locator;
schedulingGoalsModalFilter: Locator;
schedulingSatisfiedActivity: Locator;
schedulingStatusSelector: (status: string) => string;
simulateButton: Locator;
simulationHistoryList: Locator;
simulationStatusSelector: (status: string) => string;
constructor(
public page: Page,
public plans: Plans,
public constraints: Constraints,
public schedulingGoals: SchedulingGoals,
public schedulingConditions: SchedulingConditions,
public planName = plans.planName,
) {
this.constraintListItemSelector = `.constraint-list-item:has-text("${constraints.constraintName}")`;
this.schedulingConditionListItemSelector = (conditionName: string) =>
`.scheduling-condition:has-text("${conditionName}")`;
this.schedulingGoalListItemSelector = (goalName: string) => `.scheduling-goal:has-text("${goalName}")`;
this.schedulingStatusSelector = (status: string) =>
`div[data-component-name="SchedulingGoalsPanel"] .header-actions > .status-badge.${status.toLowerCase()}`;
this.simulationStatusSelector = (status: string) =>
`.nav-button:has-text("Simulation") .status-badge[aria-label=${status}]`;
this.activityCheckingStatusSelector = (status: string) =>
`.nav-button:has-text("Activities") .status-badge[aria-label=${status}]`;
this.updatePage(page);
}
async addActivity(name: string = 'GrowBanana') {
await this.showPanel(PanelNames.TIMELINE_ITEMS);
const currentNumOfActivitiesWithName = await this.panelActivityDirectivesTable.getByRole('row', { name }).count();
const activityListItem = this.page.locator(`.list-item :text-is("${name}")`);
const activityRow = this.page
.locator('.timeline')
.getByRole('listitem')
.filter({ hasText: 'Activities by Type' })
.first()
.locator('.overlay');
await activityListItem.dragTo(activityRow, { timeout: 5000 });
await this.waitForToast('Activity Directive Created Successfully');
await expect(this.panelActivityDirectivesTable.getByRole('row', { name })).toHaveCount(
currentNumOfActivitiesWithName + 1,
);
}
/* TODO saving this work for a future PR */
// async addActivityAsFilter(name: string = 'GrowBanana') {
// const activityListItem = await this.page.waitForSelector(`.list-item:has-text("${name}")`);
// await activityListItem.hover();
// const addButton = await this.page.getByLabel(`AddActivity-${name}`);
// await addButton.click();
// const contextMenuItem = await this.page.waitForSelector(
// '.context-menu .context-menu-item:has-text("Activities by Type")',
// );
// await contextMenuItem.hover();
// const contextSubMenuItem = await contextMenuItem.waitForSelector(
// ".context-menu .context-menu-item:has-text('Activity Layer')",
// );
// await contextSubMenuItem.click();
// }
async addPlanCollaborator(name: string, isUsername = true) {
await this.showPanel(PanelNames.PLAN_METADATA, true);
await this.waitForPlanCollaboratorLoad();
await this.planCollaboratorInput.fill(name);
await this.page.getByRole('option', { name }).click();
// If the name is a username then check for the existence of the username in selected items
// Otherwise it is a plan option and will add an unspecified amount of users
if (isUsername) {
await expect(
this.planCollaboratorInputContainer.locator('.tags-input-selected-items').getByRole('option', { name }),
).not.toBeUndefined();
}
await this.waitForToast('Plan Collaborators Updated');
}
async createBranch(
baseURL?: string,
name: string = uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals] }),
) {
const branchPlanUrlRegex = new RegExp(`${baseURL}/plans/(?<planId>\\d+)`);
await this.page.waitForURL(branchPlanUrlRegex);
const matches = this.page.url().match(branchPlanUrlRegex);
expect(matches).not.toBeNull();
let currentPlanId = 'foo';
if (matches) {
const { groups: { planId } = {} } = matches;
currentPlanId = planId;
}
await this.page.getByText(this.planName).first().click();
await this.page.getByText('Create branch').click();
await this.page.getByPlaceholder('Name of branch').click();
await this.page.getByPlaceholder('Name of branch').fill(name);
await this.page.getByRole('button', { name: 'Create Branch' }).click();
const parentPlanUrlRegex = new RegExp(`${baseURL}/plans/((?!${currentPlanId}).)*`);
await this.page.waitForURL(parentPlanUrlRegex);
}
async createConstraint(baseURL: string | undefined) {
await this.constraintManageButton.click();
const [newConstraintPage] = await Promise.all([
this.page.waitForEvent('popup'),
await this.constraintNewButton.click(),
]);
this.constraints.updatePage(newConstraintPage);
await newConstraintPage.waitForURL(`${baseURL}/constraints/new?modelId=*`);
await this.constraints.createConstraint(baseURL);
await newConstraintPage.close();
this.constraints.updatePage(this.page);
await this.constraintModalFilter.fill(this.constraints.constraintName);
// wait for table to filter
await this.page.waitForTimeout(100);
await this.page.getByRole('row', { name: this.constraints.constraintName }).getByRole('checkbox').click();
await this.page.getByRole('button', { name: 'Update' }).click();
await this.page.waitForSelector(this.constraintListItemSelector, { state: 'visible', strict: true });
}
async createSchedulingCondition(baseURL: string | undefined) {
await this.schedulingConditionManageButton.click();
const [newSchedulingConditionPage] = await Promise.all([
this.page.waitForEvent('popup'),
this.schedulingConditionNewButton.click(),
]);
this.schedulingConditions.updatePage(newSchedulingConditionPage);
await newSchedulingConditionPage.waitForURL(`${baseURL}/scheduling/conditions/new?modelId=*`);
await this.schedulingConditions.createSchedulingCondition(baseURL);
await newSchedulingConditionPage.close();
this.schedulingConditions.updatePage(this.page);
await this.schedulingConditionsModalFilter.fill(this.schedulingConditions.conditionName);
// wait for table to filter
await this.page.waitForTimeout(100);
await this.page
.getByRole('row', { name: this.schedulingConditions.conditionName })
.getByRole('checkbox')
.click({ position: { x: 2, y: 2 } });
await this.page.getByRole('button', { name: 'Update' }).click();
await this.page.waitForSelector(this.schedulingConditionListItemSelector(this.schedulingConditions.conditionName), {
state: 'visible',
strict: true,
});
}
async createSchedulingGoal(baseURL: string | undefined, goalName: string) {
await this.schedulingGoalManageButton.click();
const [newSchedulingGoalPage] = await Promise.all([
this.page.waitForEvent('popup'),
this.schedulingGoalNewButton.click(),
]);
this.schedulingGoals.updatePage(newSchedulingGoalPage);
await newSchedulingGoalPage.waitForURL(`${baseURL}/scheduling/goals/new?modelId=*`);
await this.schedulingGoals.createSchedulingGoal(baseURL, goalName);
await newSchedulingGoalPage.close();
this.schedulingGoals.updatePage(this.page);
await this.schedulingGoalsModalFilter.fill(goalName);
// wait for table to filter
await this.page.waitForTimeout(100);
await this.page
.getByRole('row', { name: goalName })
.getByRole('checkbox')
.click({ position: { x: 2, y: 2 } });
await this.page.getByRole('button', { name: 'Update' }).click();
await this.page.waitForSelector(this.schedulingGoalListItemSelector(goalName), { state: 'visible', strict: true });
}
async deleteAllActivities() {
const gridCells = await this.panelActivityDirectivesTable.getByRole('gridcell');
if ((await gridCells.count()) > 0) {
await this.panelActivityDirectivesTable.getByRole('gridcell').first().click({ button: 'right' });
await this.page.locator('.context-menu > .context-menu-item:has-text("Select All Activity Directives")').click();
await this.panelActivityDirectivesTable.getByRole('gridcell').first().click({ button: 'right' });
await this.page.getByText(/Delete \d+ Activit(y|ies) Directives?/).click();
const confirmDeletionButton = await this.page.getByRole('button', { name: 'Confirm' });
await confirmDeletionButton.waitFor({ state: 'attached', timeout: 1000 });
await confirmDeletionButton.click();
}
}
async fillActivityPresetName(presetName: string) {
await this.panelActivityForm.getByRole('button', { name: 'Set Preset' }).click();
await this.panelActivityForm.locator('.dropdown-header').waitFor({ state: 'attached' });
await this.panelActivityForm.getByPlaceholder('Enter preset name').click();
await this.panelActivityForm.getByPlaceholder('Enter preset name').fill(presetName);
await this.panelActivityForm.getByPlaceholder('Enter preset name').blur();
}
async fillExternalDatasetFileInput(importFilePath: string) {
const inputFile = this.page.locator('input[name="file"]');
await inputFile.focus();
await inputFile.setInputFiles(importFilePath);
await inputFile.evaluate(e => e.blur());
}
async fillPlanName(name: string) {
await this.planNameInput.fill(name);
await this.planNameInput.evaluate(e => e.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' })));
await this.planNameInput.evaluate(e => e.dispatchEvent(new Event('change')));
await this.planNameInput.blur();
}
async fillSimulationTemplateName(templateName: string) {
await this.panelSimulation.getByRole('button', { name: 'Set Template' }).click();
await this.panelSimulation.locator('.dropdown-header').waitFor({ state: 'attached' });
await this.panelSimulation.getByPlaceholder('Enter template name').click();
await this.panelSimulation.getByPlaceholder('Enter template name').fill(templateName);
await this.panelSimulation.getByPlaceholder('Enter template name').blur();
}
async getSimulationHistoryListLength() {
const elements = await this.simulationHistoryList.locator(`button:has-text("Simulation ID")`).all();
return elements.length;
}
/**
* Wait for Hasura events to finish seeding the database after a model is created.
* If we do not wait then navigation to the plan will fail because the data is not there yet.
* If your tests fail then the timeout might be too short.
* Re-run the tests and increase the timeout if you get consistent failures.
*/
async goto(planId = this.plans.planId) {
await this.page.goto(`/plans/${planId}`);
await this.page.waitForURL(`/plans/${planId}`, { waitUntil: 'networkidle' });
await expect(this.page.locator('.nav-button-title:has-text("Activities")')).toBeVisible();
}
async hoverMenu(menuButton: Locator) {
await menuButton.hover();
const menu = menuButton.getByRole('menu');
await menu.waitFor({ state: 'attached' });
await menu.waitFor({ state: 'visible' });
}
async reRunSimulation(expectedFinalState = Status.Complete) {
await this.reSimulateButton.click();
await this.page.waitForTimeout(1000);
await this.waitForSimulationStatus(expectedFinalState);
}
async removeConstraint() {
await this.constraintManageButton.click();
await this.constraintModalFilter.fill(this.constraints.constraintName);
// wait for table to filter
await this.page.waitForTimeout(100);
await this.page.getByRole('row', { name: this.constraints.constraintName }).getByRole('checkbox').uncheck();
await this.page.getByRole('button', { name: 'Update' }).click();
await this.page.locator(this.constraintListItemSelector).waitFor({ state: 'detached' });
}
async removePlanCollaborator(name: string) {
await this.showPanel(PanelNames.PLAN_METADATA, true);
await this.waitForPlanCollaboratorLoad();
await this.planCollaboratorInputContainer
.locator('.tags-input-selected-items')
.getByRole('option', { name })
.click();
await this.waitForToast('Plan Collaborator Removed Successfully');
}
async removeSchedulingGoal(goalName: string) {
await this.schedulingGoalManageButton.click();
await this.schedulingGoalsModalFilter.fill(goalName);
// wait for table to filter
await this.page.waitForTimeout(100);
await this.page.getByRole('row', { name: goalName }).getByRole('checkbox').uncheck();
await this.page.getByRole('button', { name: 'Update' }).click();
await this.page.locator(this.schedulingGoalListItemSelector(goalName)).waitFor({ state: 'detached' });
}
async renamePlan(name: string) {
await this.fillPlanName(name);
await this.waitForToast('Plan Updated Successfully');
}
async runAnalysis() {
await this.analyzeButton.click();
/**
* wait for UI to update with pending status, but don't explicitly check because
* the final state of the status might update before the check occurs
**/
await this.page.waitForTimeout(300);
await this.waitForSchedulingStatus(Status.Complete);
}
async runScheduling(expectedFinalState = Status.Complete) {
await this.scheduleButton.click();
/**
* wait for UI to update with pending status, but don't explicitly check because
* the final state of the status might update before the check occurs
**/
await this.page.waitForTimeout(300);
await this.waitForSchedulingStatus(expectedFinalState);
}
async runSimulation(expectedFinalState = Status.Complete) {
await this.simulateButton.click();
/**
* wait for UI to update with pending status, but don't explicitly check because
* the final state of the status might update before the check occurs
**/
await this.page.waitForTimeout(300);
await this.waitForSimulationStatus(expectedFinalState);
}
async selectActivityAnchorByIndex(index: number) {
await this.panelActivityForm.getByRole('button', { name: 'Set Anchor' }).click();
await this.panelActivityForm.getByRole('menuitem').nth(index).waitFor({ state: 'attached' });
const anchorMenuName = await this.panelActivityForm.getByRole('menuitem').nth(index)?.innerText();
await this.panelActivityForm.getByRole('menuitem').nth(index).click();
await this.panelActivityForm.getByRole('menuitem').nth(index).waitFor({ state: 'detached' });
await this.page.waitForFunction(
anchorMenuName => document.querySelector('.anchor-form .selected-display-value')?.innerHTML === anchorMenuName,
anchorMenuName,
);
await expect(this.panelActivityForm.getByRole('textbox', { name: anchorMenuName })).toBeVisible();
}
async selectActivityPresetByName(presetName: string) {
await this.panelActivityForm.getByRole('button', { name: 'Set Preset' }).click();
await this.panelActivityForm.getByRole('menuitem', { name: presetName }).waitFor({ state: 'attached' });
await this.panelActivityForm.getByRole('menuitem', { name: presetName }).click();
await this.panelActivityForm.getByRole('menuitem', { name: presetName }).waitFor({ state: 'detached' });
try {
const applyPresetButton = await this.page.getByRole('button', { name: 'Apply Preset' });
// allow time for modal to apply the preset to show up if applicable
await applyPresetButton.waitFor({ state: 'attached', timeout: 1000 });
// await new Promise(resolve => setTimeout(resolve, 1000));
if (await applyPresetButton.isVisible()) {
await applyPresetButton.click();
}
} catch (e) {
if (e.name !== 'TimeoutError') {
console.error(e);
}
}
await this.page.waitForFunction(
presetName =>
document.querySelector('.activity-preset-input-container .selected-display-value')?.innerHTML === presetName,
presetName,
);
await expect(this.panelActivityForm.getByRole('textbox', { name: presetName })).toBeVisible();
}
async selectSimulationTemplateByName(templateName: string) {
await this.panelSimulation.getByRole('button', { name: 'Set Template' }).click();
await this.panelSimulation.getByRole('menuitem', { name: templateName }).waitFor({ state: 'attached' });
await this.panelSimulation.getByRole('menuitem', { name: templateName }).click();
await this.panelSimulation.getByRole('menuitem', { name: templateName }).waitFor({ state: 'detached' });
try {
const applyTemplateButton = await this.page.getByRole('button', { name: 'Apply Simulation Template' });
// allow time for modal to apply the preset to show up if applicable
await applyTemplateButton.waitFor({ state: 'attached', timeout: 1000 });
// await new Promise(resolve => setTimeout(resolve, 1000));
if (await applyTemplateButton.isVisible()) {
await applyTemplateButton.click();
}
} catch (e) {
if (e.name !== 'TimeoutError') {
console.error(e);
}
}
await this.page.waitForFunction(
templateName =>
document.querySelector('.simulation-template-input-container .selected-display-value')?.innerHTML ===
templateName,
templateName,
);
await expect(this.panelSimulation.getByRole('textbox', { name: templateName })).toBeVisible();
}
async showConstraintsLayout() {
await this.showPanel(PanelNames.CONSTRAINTS);
await this.panelConstraints.waitFor({ state: 'attached' });
await this.panelConstraints.waitFor({ state: 'visible' });
await this.panelActivityDirectivesTable.waitFor({ state: 'attached' });
await this.panelActivityDirectivesTable.waitFor({ state: 'visible' });
await this.panelTimeline.waitFor({ state: 'attached' });
await this.panelTimeline.waitFor({ state: 'visible' });
await expect(this.panelConstraints).toBeVisible();
await expect(this.panelActivityDirectivesTable).toBeVisible();
await expect(this.panelTimeline).toBeVisible();
}
async showPanel(name: PanelNames, pickLastMenu: boolean = false) {
await expect(this.gridMenu).not.toBeVisible();
let gridMenuButton: Locator;
if (pickLastMenu) {
gridMenuButton = await this.gridMenuButton.last();
} else {
gridMenuButton = await this.gridMenuButton.first();
}
await expect(gridMenuButton).toBeVisible();
await expect(gridMenuButton).toBeEnabled();
await this.page.waitForTimeout(1000);
await gridMenuButton.click();
await this.gridMenu.waitFor({ state: 'attached' });
await this.gridMenu.waitFor({ state: 'visible' });
await this.gridMenuItem(name).click();
}
async showSchedulingLayout() {
await this.showPanel(PanelNames.SCHEDULING_GOALS);
await this.showPanel(PanelNames.SCHEDULING_CONDITIONS, true);
await this.panelSchedulingGoals.waitFor({ state: 'attached' });
await this.panelSchedulingGoals.waitFor({ state: 'visible' });
await this.panelSchedulingConditions.waitFor({ state: 'attached' });
await this.panelSchedulingConditions.waitFor({ state: 'visible' });
await this.panelActivityDirectivesTable.waitFor({ state: 'attached' });
await this.panelActivityDirectivesTable.waitFor({ state: 'visible' });
await this.panelTimeline.waitFor({ state: 'attached' });
await this.panelTimeline.waitFor({ state: 'visible' });
await expect(this.panelSchedulingGoals).toBeVisible();
await expect(this.panelActivityDirectivesTable).toBeVisible();
await expect(this.panelTimeline).toBeVisible();
}
updatePage(page: Page): void {
this.appError = page.locator('.app-error');
this.activitiesTable = page.locator(`div.ag-theme-stellar.table`);
this.activitiesTableFirstRow = page
.locator(`div.ag-theme-stellar.table .ag-center-cols-container > .ag-row`)
.nth(0);
this.constraintManageButton = page.locator(`button[name="manage-constraints"]`);
this.constraintModalFilter = page.locator('.modal').getByPlaceholder('Filter constraints');
this.constraintNewButton = page.locator(`button[name="new-constraint"]`);
this.consoleContainer = page.locator(`.console-container`);
this.externalSourceManageButton = page.getByLabel('Select derivation groups to');
this.gridMenuButton = page.locator('.header > .grid-menu');
this.gridMenu = this.gridMenuButton.getByRole('menu');
this.gridMenuItem = (name: string) => this.gridMenu.getByRole('menuitem', { exact: true, name });
this.navButtonActivityChecking = page.locator(`.nav-button:has-text("Activities")`);
this.navButtonActivityCheckingMenu = this.navButtonActivityChecking.getByRole('menu');
this.navButtonExpansion = page.locator(`.nav-button:has-text("Expansion")`);
this.navButtonExpansionMenu = this.navButtonExpansion.getByRole('menu');
this.navButtonConstraints = page.locator(`.nav-button:has-text("Constraints")`);
this.navButtonConstraintsMenu = this.navButtonConstraints.getByRole('menu');
this.navButtonScheduling = page.locator(`.nav-button:has-text("Scheduling")`);
this.navButtonSchedulingMenu = this.navButtonScheduling.getByRole('menu');
this.navButtonSimulation = page.locator(`.nav-button:has-text("Simulation")`);
this.navButtonSimulationMenu = this.navButtonSimulation.getByRole('menu');
this.navButtonSimulationMenuStatus = this.navButtonSimulation.locator(`.status-badge`);
this.page = page;
this.panelActivityDirectivesTable = page.locator('[data-component-name="ActivityDirectivesTablePanel"]');
this.panelActivityForm = page.locator('[data-component-name="ActivityFormPanel"]');
this.panelActivityTypes = page.locator('[data-component-name="TimelineItemsPanel"]');
this.panelConstraints = page.locator('[data-component-name="ConstraintsPanel"]');
this.panelExpansion = page.locator('[data-component-name="ExpansionPanel"]');
this.panelPlanMetadata = page.locator('[data-component-name="PlanMetadataPanel"]');
this.panelSchedulingConditions = page.locator('[data-component-name="SchedulingConditionsPanel"]');
this.panelSchedulingGoals = page.locator('[data-component-name="SchedulingGoalsPanel"]');
this.panelSimulatedActivitiesTable = page.locator('[data-component-name="ActivitySpansTablePanel"]');
this.panelSimulation = page.locator('[data-component-name="SimulationPanel"]');
this.panelTimeline = page.locator('[data-component-name="TimelinePanel"]');
this.panelTimelineEditor = page.locator('[data-component-name="TimelineEditorPanel"]');
this.planTitle = page.locator(`.plan-title:has-text("${this.planName}")`);
this.planCollaboratorInputContainer = this.panelPlanMetadata.locator('.input:has-text("Collaborators")');
this.planCollaboratorInput = this.planCollaboratorInputContainer.getByPlaceholder('Search collaborators or plans');
this.planNameInput = page.locator('input[name="plan-name"]');
this.planCollaboratorLoadingInput = this.planCollaboratorInputContainer.getByPlaceholder('Loading...');
this.roleSelector = page.locator(`.nav select`);
this.reSimulateButton = page.locator('.header-actions button:has-text("Re-Run")');
this.scheduleButton = page.locator('.header-actions button[aria-label="Schedule"]');
this.simulateButton = page.locator('.header-actions button:has-text("Simulate")');
this.simulationHistoryList = page.locator('.simulation-history');
this.analyzeButton = page.locator('.header-actions button[aria-label="Analyze"]');
this.schedulingGoalManageButton = page.locator(`button[name="manage-goals"]`);
this.schedulingConditionManageButton = page.locator(`button[name="manage-conditions"]`);
this.schedulingGoal = (goalName: string) => page.locator(`.scheduling-goal:has-text("${goalName}")`);
this.schedulingGoalDifferenceBadge = (goalName: string) =>
this.schedulingGoal(goalName).locator('.difference-badge');
this.schedulingGoalEnabledCheckboxSelector = (goalName: string) =>
this.schedulingGoal(goalName).getByRole('checkbox');
this.schedulingGoalsModalFilter = this.page.locator('.modal').getByPlaceholder('Filter goals');
this.schedulingConditionsModalFilter = this.page.locator('.modal').getByPlaceholder('Filter conditions');
this.schedulingConditionEnabledCheckboxSelector = (conditionName: string) =>
page.locator(`.scheduling-condition:has-text("${conditionName}")`).getByRole('checkbox');
this.schedulingGoalExpand = (goalName: string) =>
this.schedulingGoal(goalName).locator('.collapse > button').first();
this.schedulingGoalNewButton = page.locator(`button[name="new-scheduling-goal"]`);
this.schedulingConditionNewButton = page.locator(`button[name="new-scheduling-condition"]`);
this.schedulingSatisfiedActivity = page.locator('.scheduling-goal-analysis-activities-list > .satisfied-activity');
}
async uploadExternalDatasets(importFilePath: string) {
await this.panelActivityTypes.getByRole('button', { exact: true, name: 'Resources' }).click();
await this.panelActivityTypes.getByRole('button', { exact: true, name: 'Upload Resources' }).click();
await this.fillExternalDatasetFileInput(importFilePath);
await expect(this.panelActivityTypes.getByRole('button', { exact: true, name: 'Upload' })).toBeEnabled();
await this.panelActivityTypes.getByRole('button', { exact: true, name: 'Upload' }).click();
}
async waitForActivityCheckingStatus(status: Status) {
await expect(this.page.locator(this.activityCheckingStatusSelector(status))).toBeAttached({ timeout: 10000 });
await expect(this.page.locator(this.activityCheckingStatusSelector(status))).toBeVisible();
}
async waitForPlanCollaboratorLoad() {
await expect(this.planCollaboratorLoadingInput).not.toBeVisible({ timeout: 10000 });
}
async waitForSchedulingStatus(status: Status) {
await expect(this.page.locator(this.schedulingStatusSelector(status))).toBeAttached({ timeout: 10000 });
await expect(this.page.locator(this.schedulingStatusSelector(status))).toBeVisible();
}
async waitForSimulationStatus(status: Status) {
await expect(this.page.locator(this.simulationStatusSelector(status))).toBeAttached({ timeout: 10000 });
await expect(this.page.locator(this.simulationStatusSelector(status))).toBeVisible();
}
async waitForToast(message: string) {
await this.page.waitForSelector(`.toastify:has-text("${message}")`, { timeout: 10000 });
}
}
export enum PanelNames {
ACTIVITY_DIRECTIVES_TABLE = 'Activity Directives Table',
SIMULATED_ACTIVITIES_TABLE = 'Simulated Activities Table',
TIMELINE_ITEMS = 'Activity, Resource, Event Types',
CONSTRAINTS = 'Constraints',
EXPANSION = 'Expansion',
EXTERNAL_APPLICATION = 'External Application',
PLAN_METADATA = 'Plan Metadata',
SCHEDULING_GOALS = 'Scheduling Goals',
SCHEDULING_CONDITIONS = 'Scheduling Conditions',
SELECTED_ACTIVITY = 'Selected Activity',
SIMULATION = 'Simulation',
TIMELINE_EDITOR = 'Timeline Editor',
EXTERNAL_SOURCES = 'External Sources',
}