-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathorganization-receiver-message-test.ts
More file actions
155 lines (141 loc) · 6.18 KB
/
organization-receiver-message-test.ts
File metadata and controls
155 lines (141 loc) · 6.18 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
import type { Locator } from "@playwright/test";
import * as fs from "fs";
import language from "../../../../src/components/Admin/MessageTesting/language.json" assert { type: "json" };
import {
errorMessageResult,
passMessageResult,
warningMessageResult,
} from "../../../../src/components/Admin/MessageTesting/MessageTestingResult.fixtures";
import { RSMessage } from "../../../../src/config/endpoints/reports";
import { MOCK_GET_TEST_MESSAGES } from "../../../mocks/message-test";
import { BasePage, BasePageTestArgs, type RouteHandlerFulfillEntry } from "../../BasePage";
/**
* Uses org ignore's FULL_ELR receiver
*/
export class OrganizationReceiverMessageTestPage extends BasePage {
static readonly API_REPORTS_TESTING = "/api/reports/testing";
static readonly API_REPORTS_TEST = "/api/reports/testing/test?*";
protected customI: number;
testMessages: RSMessage[];
readonly expectedStatusSuccess = new RegExp(`^${language.successAlertHeading}`);
readonly expectedStatusFailure = new RegExp(`^${language.errorAlertHeading}`);
readonly expectedStatusWarning = new RegExp(`^${language.warningAlertHeading}`);
readonly form: Locator;
readonly addCustomMessageButton: Locator;
readonly submitCustomMessageButton: Locator;
readonly cancelCustomMessageButton: Locator;
readonly customMessageTextArea: Locator;
readonly submitButton: Locator;
readonly submitStatus: Locator;
readonly submissionOutputMessageButton: Locator;
readonly submissionOutputMessage: Locator;
readonly submissionTestMessageButton: Locator;
readonly submissionTestMessage: Locator;
readonly submissionTransformErrorsButton: Locator;
readonly submissionTransformErrors: Locator;
readonly submissionTransformWarningsButton: Locator;
readonly submissionTransformWarnings: Locator;
constructor(testArgs: BasePageTestArgs) {
super(
{
url: "/admin/orgreceiversettings/org/ignore/receiver/FULL_ELR/action/edit/message-testing",
title: "Message testing - ReportStream",
heading: testArgs.page.getByRole("heading", {
name: "Message testing",
}),
},
testArgs,
);
this.testMessages = [];
this.customI = 0;
this.form = this.page.getByRole("form");
this.addCustomMessageButton = this.form.getByRole("button", { name: "Test custom message" });
this.submitCustomMessageButton = this.form.getByRole("button", { name: "Add" });
this.cancelCustomMessageButton = this.form.getByRole("button", { name: "Cancel" });
this.customMessageTextArea = this.form.getByRole("textbox", { name: "Custom message text" });
this.submitButton = this.form.getByRole("button", { name: "Run test" });
this.submitStatus = this.page
.getByRole("status")
.or(this.page.getByRole("alert"))
.or(this.page.getByRole("region", { name: "Information" }))
.first();
this.submissionOutputMessageButton = this.page.getByRole("button", { name: "Output message" });
this.submissionOutputMessage = this.page.getByLabel("Output message");
this.submissionTestMessageButton = this.page.getByRole("button", { name: "Test message" });
this.submissionTestMessage = this.page.getByLabel("Test message");
this.submissionTransformErrorsButton = this.page.getByRole("button", { name: "Transform errors" });
this.submissionTransformErrors = this.page.getByLabel("Transform errors");
this.submissionTransformWarningsButton = this.page.getByRole("button", { name: "Transform warnings" });
this.submissionTransformWarnings = this.page.getByLabel("Transform warnings");
this.addMockRouteHandlers([this.createMockTestMessagesHandler()]);
this.addResponseHandlers([
[
OrganizationReceiverMessageTestPage.API_REPORTS_TESTING,
async (res) => (this.testMessages = await res.json()),
],
]);
}
get isPageLoadExpected() {
return super.isPageLoadExpected && this.isAdminSession;
}
createMockTestMessagesHandler(): RouteHandlerFulfillEntry {
return [
OrganizationReceiverMessageTestPage.API_REPORTS_TESTING,
() => {
return {
json: MOCK_GET_TEST_MESSAGES,
};
},
];
}
createMockTestSubmissionHandler(resultType: "pass" | "fail" | "warn" = "pass"): RouteHandlerFulfillEntry {
let result;
switch (resultType) {
case "fail":
result = errorMessageResult;
break;
case "warn":
result = warningMessageResult;
break;
default:
result = passMessageResult;
break;
}
return [
OrganizationReceiverMessageTestPage.API_REPORTS_TEST,
() => {
return {
json: result,
};
},
];
}
addMockTestSubmissionHandler(resultType: "pass" | "fail" | "warn" = "pass") {
return this.addMockRouteHandlers([this.createMockTestSubmissionHandler(resultType)]);
}
async downloadPDF() {
// Listen for the 'download' event before firing
const [download] = await Promise.all([
this.page.waitForEvent("download"),
this.page.click('text="Download PDF"'),
]);
const filePath = await download.path();
const stats = fs.statSync(filePath);
return stats;
}
async submit() {
const p = this.route();
const reqP = this.page.waitForRequest(OrganizationReceiverMessageTestPage.API_REPORTS_TEST);
await this.submitButton.click();
await p;
return reqP;
}
async addCustomMessage(message: string) {
await this.addCustomMessageButton.click();
await this.customMessageTextArea.fill(message);
await this.submitCustomMessageButton.click();
this.customI++;
const fileName = `Custom message ${this.customI}`;
return [this.form.getByLabel(fileName), this.form.getByText(fileName)];
}
}