-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasicEmail.cy.ts
More file actions
385 lines (323 loc) · 11.5 KB
/
basicEmail.cy.ts
File metadata and controls
385 lines (323 loc) · 11.5 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
// cypress/e2e/basicEmail.cy.ts
describe("Send an email", () => {
const TEST_EMAIL_TO = Cypress.env("TEST_EMAIL_TO") as string;
const TEST_EMAIL_CC = Cypress.env("TEST_EMAIL_CC") as string;
const TEST_EMAIL_BCC = Cypress.env("TEST_EMAIL_BCC") as string;
const TEMPLATE_NAME = "Test Case 1";
const STANDARD_TIMEOUT = 20000;
// Only suppress the noisy ResizeObserver error that Unity throws in TEST.
// Everything else should still fail the test.
Cypress.on("uncaught:exception", (err) => {
const msg = err && err.message ? err.message : "";
if (msg.indexOf("ResizeObserver loop limit exceeded") >= 0) {
return false;
}
return true;
});
const now = new Date();
const timestamp =
now.getFullYear() +
"-" +
String(now.getMonth() + 1).padStart(2, "0") +
"-" +
String(now.getDate()).padStart(2, "0") +
" " +
String(now.getHours()).padStart(2, "0") +
":" +
String(now.getMinutes()).padStart(2, "0") +
":" +
String(now.getSeconds()).padStart(2, "0");
const TEST_EMAIL_SUBJECT = `Smoke Test Email ${timestamp}`;
function ensureLoggedInToGrantApplications() {
// Headless runs specs sequentially in the same browser process.
// Do not assume logged-out or logged-in. Detect UI state like chefsdata.cy.ts does.
cy.visit(Cypress.env("webapp.url"));
cy.get("body", { timeout: STANDARD_TIMEOUT }).then(($body) => {
// Already authenticated
if ($body.find('button:contains("VIEW APPLICATIONS")').length > 0) {
cy.contains("VIEW APPLICATIONS", { timeout: STANDARD_TIMEOUT }).click({
force: true,
});
return;
}
// Not authenticated
if ($body.find('button:contains("LOGIN")').length > 0) {
cy.contains("LOGIN", { timeout: STANDARD_TIMEOUT })
.should("exist")
.click({ force: true });
cy.get("body", { timeout: STANDARD_TIMEOUT }).then(($loginBody) => {
// IDIR chooser may or may not appear
if ($loginBody.find(':contains("IDIR")').length > 0) {
cy.contains("IDIR", { timeout: STANDARD_TIMEOUT }).click({
force: true,
});
}
cy.get("body", { timeout: STANDARD_TIMEOUT }).then(($authBody) => {
// Only type creds if the login form is actually present
if ($authBody.find("#user").length > 0) {
cy.get("#user", { timeout: STANDARD_TIMEOUT }).type(
Cypress.env("test1username"),
);
cy.get("#password", { timeout: STANDARD_TIMEOUT }).type(
Cypress.env("test1password"),
);
cy.contains("Continue", { timeout: STANDARD_TIMEOUT }).click({
force: true,
});
} else {
cy.log("Already authenticated");
}
});
});
return;
}
throw new Error("Unable to determine authentication state");
});
cy.location("pathname", { timeout: 30000 }).should(
"include",
"/GrantApplications",
);
}
function switchToDefaultGrantsProgramIfAvailable() {
cy.get("body").then(($body) => {
const hasUserInitials = $body.find(".unity-user-initials").length > 0;
if (!hasUserInitials) {
cy.log("Skipping tenant: 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 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");
cy.get("#UserGrantProgramsTable", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.within(() => {
cy.contains("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);
});
});
});
}
function openSavedEmailFromHistoryBySubject(subject: string) {
cy.get("body", { timeout: STANDARD_TIMEOUT }).then(($body) => {
const historyTableById = $body.find("#EmailHistoryTable");
if (historyTableById.length > 0) {
cy.get("#EmailHistoryTable", { timeout: STANDARD_TIMEOUT })
.scrollIntoView()
.should("be.visible")
.within(() => {
cy.contains("td", subject, { timeout: STANDARD_TIMEOUT })
.should("exist")
.click();
});
return;
}
cy.contains("td", subject, { timeout: STANDARD_TIMEOUT })
.should("exist")
.click();
});
}
function confirmSendDialogIfPresent() {
cy.get("body", { timeout: STANDARD_TIMEOUT }).should(($b) => {
const hasBootstrapShownModal = $b.find(".modal.show").length > 0;
const hasSwal = $b.find(".swal2-container").length > 0;
const hasConfirmBtn = $b.find("#btn-confirm-send").length > 0;
expect(hasBootstrapShownModal || hasSwal || hasConfirmBtn).to.eq(true);
});
cy.get("body", { timeout: STANDARD_TIMEOUT }).then(($b) => {
const hasSwal = $b.find(".swal2-container").length > 0;
if (hasSwal) {
cy.get(".swal2-container", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
);
cy.contains(".swal2-container", "Are you sure", {
timeout: STANDARD_TIMEOUT,
}).should("exist");
if ($b.find(".swal2-confirm").length > 0) {
cy.get(".swal2-confirm", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.click();
} else {
cy.contains(".swal2-container button", "Yes", {
timeout: STANDARD_TIMEOUT,
}).click();
}
return;
}
const hasBootstrapShownModal = $b.find(".modal.show").length > 0;
if (hasBootstrapShownModal) {
cy.get(".modal.show", { timeout: STANDARD_TIMEOUT })
.should("be.visible")
.within(() => {
cy.contains("Are you sure you want to send this email?", {
timeout: STANDARD_TIMEOUT,
}).should("exist");
if (Cypress.$("#btn-confirm-send").length > 0) {
cy.get("#btn-confirm-send", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.click();
} else {
cy.contains("button", "Confirm", {
timeout: STANDARD_TIMEOUT,
}).click();
}
});
return;
}
cy.get("#btn-confirm-send", { timeout: STANDARD_TIMEOUT })
.should("exist")
.click({ force: true });
});
}
it("Login", () => {
ensureLoggedInToGrantApplications();
});
it("Switch to Default Grants Program if available", () => {
switchToDefaultGrantsProgramIfAvailable();
});
it("Handle IDIR if required", () => {
cy.get("body").then(($body) => {
if ($body.find("#social-idir").length > 0) {
cy.get("#social-idir").should("be.visible").click();
}
});
cy.location("pathname", { timeout: 30000 }).should(
"include",
"/GrantApplications",
);
});
it("Open an application from the list", () => {
cy.url().should("include", "/GrantApplications");
cy.get(
'#GrantApplicationsTable tbody a[href^="/GrantApplications/Details?ApplicationId="]',
{ timeout: STANDARD_TIMEOUT },
).should("have.length.greaterThan", 0);
cy.get(
'#GrantApplicationsTable tbody a[href^="/GrantApplications/Details?ApplicationId="]',
)
.first()
.click();
cy.url().should("include", "/GrantApplications/Details");
});
it("Open Emails tab", () => {
cy.get("#emails-tab", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.click();
cy.contains("Emails", { timeout: STANDARD_TIMEOUT }).should("exist");
cy.contains("Email History", { timeout: STANDARD_TIMEOUT }).should("exist");
});
it("Open New Email form", () => {
cy.get("#btn-new-email", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.click();
cy.contains("Email To", { timeout: STANDARD_TIMEOUT }).should("exist");
});
it("Select Email Template", () => {
cy.intercept("GET", "/api/app/template/*/template-by-id").as(
"loadTemplate",
);
cy.get("#template", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.select(TEMPLATE_NAME);
cy.wait("@loadTemplate", { timeout: STANDARD_TIMEOUT });
cy.get("#template")
.find("option:selected")
.should("have.text", TEMPLATE_NAME);
});
it("Set Email To address", () => {
cy.get("#EmailTo", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.clear()
.type(TEST_EMAIL_TO);
cy.get("#EmailTo").should("have.value", TEST_EMAIL_TO);
});
it("Set Email CC address", () => {
cy.get("#EmailCC", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.clear()
.type(TEST_EMAIL_CC);
cy.get("#EmailCC").should("have.value", TEST_EMAIL_CC);
});
it("Set Email BCC address", () => {
cy.get("#EmailBCC", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.clear()
.type(TEST_EMAIL_BCC);
cy.get("#EmailBCC").should("have.value", TEST_EMAIL_BCC);
});
it("Set Email Subject", () => {
cy.get("#EmailSubject", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.clear()
.type(TEST_EMAIL_SUBJECT);
cy.get("#EmailSubject").should("have.value", TEST_EMAIL_SUBJECT);
});
it("Save the email", () => {
cy.get("#btn-save", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.click();
cy.get("#btn-new-email", { timeout: STANDARD_TIMEOUT }).should(
"be.visible",
);
});
it("Select saved email from Email History", () => {
openSavedEmailFromHistoryBySubject(TEST_EMAIL_SUBJECT);
cy.get("#EmailTo", { timeout: STANDARD_TIMEOUT }).should("be.visible");
cy.get("#EmailCC").should("be.visible");
cy.get("#EmailBCC").should("be.visible");
cy.get("#EmailSubject").should("be.visible");
cy.get("#btn-send", { timeout: STANDARD_TIMEOUT }).should("exist");
cy.get("#btn-save", { timeout: STANDARD_TIMEOUT }).should("exist");
});
it("Send the email", () => {
cy.get("#btn-send", { timeout: STANDARD_TIMEOUT })
.should("exist")
.should("be.visible")
.should("not.be.disabled")
.click();
});
it("Confirm send email in dialog", () => {
confirmSendDialogIfPresent();
});
it("Verify Logout", () => {
cy.logout();
});
});