-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplicationsActionBar.cy.ts
More file actions
647 lines (553 loc) · 22.9 KB
/
ApplicationsActionBar.cy.ts
File metadata and controls
647 lines (553 loc) · 22.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
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/// <reference types="cypress" />
import { loginIfNeeded } from "../support/auth";
describe("Unity Login and check data from CHEFS", () => {
const STANDARD_TIMEOUT = 20000;
function switchToDefaultGrantsProgramIfAvailable() {
cy.get("body").then(($body) => {
const hasUserInitials = $body.find(".unity-user-initials").length > 0;
if (!hasUserInitials) {
cy.log("Skipping tenant switch: no user initials menu found");
return;
}
cy.get(".unity-user-initials").click();
cy.get("body").then(($body2) => {
const switchLink = $body2
.find("#user-dropdown a.dropdown-item")
.filter((_, el) => {
return (el.textContent || "").trim() === "Switch Grant Programs";
});
if (switchLink.length === 0) {
cy.log(
'Skipping tenant switch: "Switch Grant Programs" not present for this user/session',
);
cy.get("body").click(0, 0);
return;
}
cy.wrap(switchLink.first()).click();
cy.url({ timeout: STANDARD_TIMEOUT }).should(
"include",
"/GrantPrograms",
);
cy.get("#search-grant-programs", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.clear()
.type("Default Grants Program");
// Flatten nested `within` usage to satisfy S2004 (limit nesting depth)
cy.contains(
"#UserGrantProgramsTable tbody tr",
"Default Grants Program",
{ timeout: STANDARD_TIMEOUT },
)
.should("exist")
.within(() => {
cy.contains("button", "Select").should("be.enabled").click();
});
cy.location("pathname", { timeout: STANDARD_TIMEOUT }).should((p) => {
expect(
p.indexOf("/GrantApplications") >= 0 || p.indexOf("/auth/") >= 0,
).to.eq(true);
});
});
});
}
// TEST renders the Submission tab inside an open shadow root (Form.io).
// Enabling this makes cy.get / cy.contains pierce shadow DOM consistently across envs.
before(() => {
Cypress.config("includeShadowDom", true);
loginIfNeeded({ timeout: STANDARD_TIMEOUT });
});
it("Switch to Default Grants Program if available", () => {
switchToDefaultGrantsProgramIfAvailable();
});
it("Tests the existence and functionality of the Submitted Date From and Submitted Date To filters", () => {
const pad2 = (n: number) => String(n).padStart(2, "0");
const todayIsoLocal = () => {
const d = new Date();
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
};
const waitForRefresh = () => {
// S3923 fix: remove identical branches; assert spinner is hidden when present.
cy.get('div.spinner-grow[role="status"]', {
timeout: STANDARD_TIMEOUT,
}).then(($s) => {
cy.wrap($s)
.should("have.attr", "style")
.and("contain", "display: none");
});
};
// --- Submitted Date From ---
cy.get("input#submittedFromDate", { timeout: STANDARD_TIMEOUT })
.click({ force: true })
.clear({ force: true })
.type("2022-01-01", { force: true })
.trigger("change", { force: true })
.blur({ force: true })
.should("have.value", "2022-01-01");
waitForRefresh();
// --- Submitted Date To ---
const today = todayIsoLocal();
cy.get("input#submittedToDate", { timeout: STANDARD_TIMEOUT })
.click({ force: true })
.clear({ force: true })
.type(today, { force: true })
.trigger("change", { force: true })
.blur({ force: true })
.should("have.value", today);
waitForRefresh();
});
// With no rows selected verify the visibility of Filter, Export, Save View, and Columns.
it("Verifies the expected action buttons are visible when no rows are selected", () => {
cy.get("#GrantApplicationsTable", { timeout: STANDARD_TIMEOUT }).should(
"exist",
);
// Ensure we start from a clean selection state (0 selected)
// (Using same "select all / deselect all" toggle approach as the working 1-row test)
cy.get("div.dt-scroll-head thead input", { timeout: STANDARD_TIMEOUT })
.should("exist")
.click({ force: true })
.click({ force: true });
cy.get("#GrantApplicationsTable tbody tr.selected", {
timeout: STANDARD_TIMEOUT,
}).should("have.length", 0);
// Filter button (left action bar group)
cy.get("#btn-toggle-filter", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
);
// Right-side buttons
cy.contains(
"#dynamicButtonContainerId .dt-buttons button span",
"Export",
{ timeout: STANDARD_TIMEOUT },
).should("be.visible");
cy.contains("#dynamicButtonContainerId button.grp-savedStates", "Save View", {
timeout: STANDARD_TIMEOUT,
}).should("be.visible");
cy.contains(
"#dynamicButtonContainerId .dt-buttons button span",
"Columns",
{ timeout: STANDARD_TIMEOUT },
).should("be.visible");
// Optional sanity: action buttons that require selection should be disabled when none selected
cy.get("#externalLink", { timeout: STANDARD_TIMEOUT }).should(
"be.disabled",
); // Open
cy.get("#assignApplication", { timeout: STANDARD_TIMEOUT }).should(
"be.disabled",
); // Assign
cy.get("#approveApplications", { timeout: STANDARD_TIMEOUT }).should(
"be.disabled",
); // Approve
cy.get("#tagApplication", { timeout: STANDARD_TIMEOUT }).should(
"be.disabled",
); // Tags
cy.get("#applicationPaymentRequest", {
timeout: STANDARD_TIMEOUT,
}).should("be.disabled"); // Payment
cy.get("#applicationLink", { timeout: STANDARD_TIMEOUT }).should(
"be.disabled",
); // Info
});
// With one row selected verify the visibility of Open, Assign, Approve, Tags, Payment, Info, Filter, Export, Save View, and Columns.
it("Verifies the expected action buttons are visible when only one row is selected", () => {
cy.get("#GrantApplicationsTable", { timeout: STANDARD_TIMEOUT }).should(
"exist",
);
//Ensure we start from a clean selection state (0 selected)
cy.get("div.dt-scroll-head thead input", { timeout: STANDARD_TIMEOUT })
.should("exist")
.click({ force: true })
.click({ force: true });
cy.get("#GrantApplicationsTable tbody tr.selected", {
timeout: STANDARD_TIMEOUT,
}).should("have.length", 0);
// Select exactly 1 row (click a non-link cell, matching your earlier helper logic)
cy.get("#GrantApplicationsTable tbody tr", { timeout: STANDARD_TIMEOUT })
.should("have.length.greaterThan", 0)
.first()
.find("td")
.not(":has(a)")
.first()
.click({ force: true });
cy.get("#GrantApplicationsTable tbody tr.selected", {
timeout: STANDARD_TIMEOUT,
}).should("have.length", 1);
// Action bar (left group)
cy.get("#app_custom_buttons", { timeout: STANDARD_TIMEOUT })
.should("exist")
.scrollIntoView();
// Left-side action buttons (actual IDs on this page)
cy.get("#externalLink", { timeout: STANDARD_TIMEOUT }).should("be.visible"); // Open
cy.get("#assignApplication", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
); // Assign
cy.get("#approveApplications", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
); // Approve
cy.get("#tagApplication", { timeout: STANDARD_TIMEOUT }).should("be.visible"); // Tags
cy.get("#applicationPaymentRequest", {
timeout: STANDARD_TIMEOUT,
}).should("be.visible"); // Payment
cy.get("#applicationLink", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
); // Info
// Filter button
cy.get("#btn-toggle-filter", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
);
// Right-side buttons
cy.contains(
"#dynamicButtonContainerId .dt-buttons button span",
"Export",
{ timeout: STANDARD_TIMEOUT },
).should("be.visible");
cy.contains("#dynamicButtonContainerId button.grp-savedStates", "Save View", {
timeout: STANDARD_TIMEOUT,
}).should("be.visible");
cy.contains(
"#dynamicButtonContainerId .dt-buttons button span",
"Columns",
{ timeout: STANDARD_TIMEOUT },
).should("be.visible");
});
it("Verifies the expected action buttons are visible when two rows are selected", () => {
const BUTTON_TIMEOUT = 60000;
// Ensure table has rows
cy.get(".dt-scroll-body tbody tr", { timeout: STANDARD_TIMEOUT }).should(
"have.length.greaterThan",
1,
);
// Select two rows using non-link cells
const clickSelectableCell = (rowIdx: number, withCtrl = false) => {
cy.get(".dt-scroll-body tbody tr", { timeout: STANDARD_TIMEOUT })
.eq(rowIdx)
.find("td")
.not(":has(a)")
.first()
.click({ force: true, ctrlKey: withCtrl });
};
clickSelectableCell(0);
clickSelectableCell(1, true);
// ActionBar
cy.get("#app_custom_buttons", { timeout: STANDARD_TIMEOUT })
.should("exist")
.scrollIntoView();
// Click Payment
cy.get("#applicationPaymentRequest", { timeout: BUTTON_TIMEOUT })
.should("be.visible")
.and("not.be.disabled")
.click({ force: true });
// Wait until modal is shown
cy.get("#payment-modal", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.and("have.class", "show");
// Attempt graceful closes first
cy.get("body").type("{esc}", { force: true }); // Bootstrap listens to ESC
cy.get(".modal-backdrop", { timeout: STANDARD_TIMEOUT }).then(($bd) => {
if ($bd.length) {
cy.wrap($bd).click("topLeft", { force: true });
}
});
// Try footer Cancel if available (avoid .catch on Cypress chainable)
cy.contains("#payment-modal .modal-footer button", "Cancel", {
timeout: STANDARD_TIMEOUT,
}).then(($btn) => {
if ($btn && $btn.length > 0) {
cy.wrap($btn).scrollIntoView().click({ force: true });
} else {
cy.log("Cancel button not present, proceeding to hard-close fallback");
}
});
// Use window API (if present), then hard-close fallback
cy.window().then((win: any) => {
try {
if (typeof win.closePaymentModal === "function") {
win.closePaymentModal();
}
} catch {
/* ignore */
}
// HARD CLOSE: forcibly hide modal and remove backdrop
const $ = (win as any).jQuery || (win as any).$;
if ($) {
try {
$("#payment-modal")
.removeClass("show")
.attr("aria-hidden", "true")
.css("display", "none");
$(".modal-backdrop").remove();
$("body").removeClass("modal-open").css("overflow", ""); // restore scroll
} catch {
/* ignore */
}
}
});
// Verify modal/backdrop gone (be tolerant: assert non-interference instead of visibility only)
cy.get("#payment-modal", { timeout: STANDARD_TIMEOUT }).should(($m) => {
const isHidden = !$m.is(":visible") || !$m.hasClass("show");
expect(isHidden, "payment-modal hidden or not shown").to.eq(true);
});
cy.get(".modal-backdrop", { timeout: STANDARD_TIMEOUT }).should("not.exist");
// Right-side buttons usable
cy.get("#dynamicButtonContainerId", { timeout: STANDARD_TIMEOUT })
.should("exist")
.scrollIntoView();
cy.contains("#dynamicButtonContainerId .dt-buttons button span", "Export", {
timeout: STANDARD_TIMEOUT,
}).should("be.visible");
cy.contains(
"#dynamicButtonContainerId button.grp-savedStates",
"Save View",
{ timeout: STANDARD_TIMEOUT },
).should("be.visible");
cy.contains(
"#dynamicButtonContainerId .dt-buttons button span",
"Columns",
{ timeout: STANDARD_TIMEOUT },
).should("be.visible");
});
// Walk the Columns menu and toggle each column on, verifying the column is visible.
it("Verify all columns in the menu are visible when and toggled on.", () => {
const escapeRegex = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const clickColumnsItem = (label: string) => {
// Case-insensitive exact match so DEV "ID" and PROD "Id" both work
const re = new RegExp(`^\\s*${escapeRegex(label)}\\s*$`, "i");
cy.contains("a.dropdown-item", re, { timeout: STANDARD_TIMEOUT })
.should("exist")
.scrollIntoView()
.click({ force: true });
};
const normalize = (s: string) =>
(s || "").replace(/\s+/g, " ").trim().toLowerCase();
const getVisibleHeaderTitles = () => {
return cy
.get(".dt-scroll-head span.dt-column-title", {
timeout: STANDARD_TIMEOUT,
})
.then(($els) => {
const titles = Cypress.$($els)
.toArray()
.map((el) => (el.textContent || "").replace(/\s+/g, " ").trim())
.filter((t) => t.length > 0);
return titles;
});
};
const assertVisibleHeadersInclude = (expected: string[]) => {
getVisibleHeaderTitles().then((titles) => {
const normTitles = titles.map(normalize);
expected.forEach((e) => {
const target = normalize(e);
expect(
normTitles,
`visible headers should include "${e}" (case-insensitive)`,
).to.include(target);
});
});
};
const scrollX = (x: number) => {
cy.get(".dt-scroll-body", { timeout: STANDARD_TIMEOUT })
.should("exist")
.scrollTo(x, 0, { duration: 0, ensureScrollable: false });
};
// Close any open dropdowns/modals first
cy.get("body").then(($body) => {
if ($body.find(".dt-button-background").length > 0) {
cy.get(".dt-button-background").click({ force: true });
}
});
// Open the "Save View" dropdown
cy.get("button.grp-savedStates", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.and("contain.text", "Save View")
.click();
// Click "Reset to Default View"
cy.contains("a.dropdown-item", "Reset to Default View", {
timeout: STANDARD_TIMEOUT,
})
.should("exist")
.click({ force: true });
// Wait for table to rebuild after reset - check for default columns
cy.get(".dt-scroll-head span.dt-column-title", {
timeout: STANDARD_TIMEOUT,
}).should("have.length.gt", 5);
// Open Columns menu
cy.contains("span", "Columns", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.click();
// Wait for columns dropdown to be fully populated
cy.get("a.dropdown-item", { timeout: STANDARD_TIMEOUT }).should(
"have.length.gt",
50,
);
clickColumnsItem("% of Total Project Budget");
clickColumnsItem("Acquisition");
clickColumnsItem("Applicant Electoral District");
clickColumnsItem("Applicant Id");
clickColumnsItem("Applicant Id");
clickColumnsItem("Applicant Name");
clickColumnsItem("Applicant Name");
clickColumnsItem("Approved Amount");
clickColumnsItem("Approved Amount");
clickColumnsItem("Assessment Result");
clickColumnsItem("Assignee");
clickColumnsItem("Assignee");
clickColumnsItem("Business Number");
clickColumnsItem("Category");
clickColumnsItem("Category");
clickColumnsItem("City");
clickColumnsItem("Community");
clickColumnsItem("Community");
clickColumnsItem("Community Population");
clickColumnsItem("Contact Business Phone");
clickColumnsItem("Contact Cell Phone");
clickColumnsItem("Contact Email");
clickColumnsItem("Contact Full Name");
clickColumnsItem("Contact Title");
clickColumnsItem("Decision Date");
clickColumnsItem("Decline Rationale");
clickColumnsItem("Due Date");
clickColumnsItem("Due Diligence Status");
clickColumnsItem("Economic Region");
clickColumnsItem("Forestry Focus");
clickColumnsItem("Forestry or Non-Forestry");
clickColumnsItem("FYE Day");
clickColumnsItem("FYE Month");
clickColumnsItem("Indigenous");
clickColumnsItem("Likelihood of Funding");
clickColumnsItem("Non-Registered Organization Name");
clickColumnsItem("Notes");
clickColumnsItem("Org Book Status");
clickColumnsItem("Organization Type");
clickColumnsItem("Other Sector/Sub/Industry Description");
clickColumnsItem("Owner");
clickColumnsItem("Payout");
clickColumnsItem("Place");
clickColumnsItem("Project Electoral District");
clickColumnsItem("Project End Date");
clickColumnsItem("Project Name");
clickColumnsItem("Project Name");
clickColumnsItem("Project Start Date");
clickColumnsItem("Project Summary");
clickColumnsItem("Projected Funding Total");
clickColumnsItem("Recommended Amount");
clickColumnsItem("Red-Stop");
clickColumnsItem("Regional District");
clickColumnsItem("Registered Organization Name");
clickColumnsItem("Registered Organization Number");
clickColumnsItem("Requested Amount");
clickColumnsItem("Requested Amount");
clickColumnsItem("Risk Ranking");
clickColumnsItem("Sector");
clickColumnsItem("Signing Authority Business Phone");
clickColumnsItem("Signing Authority Cell Phone");
clickColumnsItem("Signing Authority Email");
clickColumnsItem("Signing Authority Full Name");
clickColumnsItem("Signing Authority Title");
clickColumnsItem("Status");
clickColumnsItem("Status");
clickColumnsItem("Sub-Status");
clickColumnsItem("Sub-Status");
clickColumnsItem("Submission #");
clickColumnsItem("Submission #");
clickColumnsItem("Submission Date");
clickColumnsItem("Submission Date");
clickColumnsItem("SubSector");
clickColumnsItem("Tags");
clickColumnsItem("Tags");
clickColumnsItem("Total Paid Amount $");
clickColumnsItem("Total Project Budget");
clickColumnsItem("Total Score");
clickColumnsItem("Unity Application Id");
// Close the menu and wait until the overlay is gone
cy.get("div.dt-button-background", { timeout: STANDARD_TIMEOUT })
.should("exist")
.click({ force: true });
cy.get("div.dt-button-background", { timeout: STANDARD_TIMEOUT }).should(
"not.exist",
);
// Assertions by horizontal scroll segments (human-style scan)
scrollX(0);
assertVisibleHeadersInclude([
"Applicant Name",
"Category",
"Submission #",
"Submission Date",
"Status",
"Sub-Status",
"Community",
"Requested Amount",
"Approved Amount",
"Project Name",
"Applicant Id",
]);
scrollX(1500);
assertVisibleHeadersInclude([
"Tags",
"Assignee",
"SubSector",
"Economic Region",
"Regional District",
"Registered Organization Number",
"Org Book Status",
]);
scrollX(3000);
assertVisibleHeadersInclude([
"Project Start Date",
"Project End Date",
"Projected Funding Total",
"Total Paid Amount $",
"Project Electoral District",
"Applicant Electoral District",
]);
scrollX(4500);
assertVisibleHeadersInclude([
"Forestry or Non-Forestry",
"Forestry Focus",
"Acquisition",
"City",
"Community Population",
"Likelihood of Funding",
"Total Score",
]);
scrollX(6000);
assertVisibleHeadersInclude([
"Assessment Result",
"Recommended Amount",
"Due Date",
"Owner",
"Decision Date",
"Project Summary",
"Organization Type",
"Business Number",
]);
scrollX(7500);
assertVisibleHeadersInclude([
"Due Diligence Status",
"Decline Rationale",
"Contact Full Name",
"Contact Title",
"Contact Email",
"Contact Business Phone",
"Contact Cell Phone",
]);
scrollX(9000);
assertVisibleHeadersInclude([
"Signing Authority Full Name",
"Signing Authority Title",
"Signing Authority Email",
"Signing Authority Business Phone",
"Signing Authority Cell Phone",
"Place",
"Risk Ranking",
"Notes",
"Red-Stop",
"Indigenous",
"FYE Day",
"FYE Month",
"Payout",
"Unity Application Id",
]);
});
it("Verify Logout", () => {
cy.logout();
});
});