Skip to content

Commit 85b585f

Browse files
authored
Update tests (#34)
* reorder the e2e tests directory * fix linting/formatting * add data-testid to events table * add a basic upcoming events view test * update * fix pre-commit * Revert "fix pre-commit" This reverts commit 1997364.
1 parent 42c801d commit 85b585f

File tree

8 files changed

+168
-82
lines changed

8 files changed

+168
-82
lines changed

.husky/pre-commit

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
41
# Get all staged files
52
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR)
63

74
if [ -n "$STAGED_FILES" ]; then
85
echo "Running lint with fix on staged files..."
96
# Run lint on all files (modifies files in the working directory)
107
yarn lint --fix
8+
yarn prettier:write
119

1210
echo "Re-adding originally staged files to the staging area..."
1311
# Re-add only the originally staged files

e2e/base.ts

-56
This file was deleted.

e2e/tests/login.spec.ts

-20
This file was deleted.

playwright.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineConfig, devices } from '@playwright/test';
22

33
export default defineConfig({
4-
testDir: './e2e/tests',
4+
testDir: './tests/e2e/',
55
/* Run tests in files in parallel */
66
fullyParallel: false,
77
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -11,7 +11,7 @@ export default defineConfig({
1111
/* Opt out of parallel tests on CI. */
1212
workers: process.env.CI ? 1 : undefined,
1313
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
14-
reporter: 'html',
14+
reporter: process.env.CI ? 'github' : 'html',
1515
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
1616
use: {
1717
/* Base URL to use in actions like `await page.goto('/')`. */

src/ui/pages/events/ViewEvents.page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const ViewEventsPage: React.FC = () => {
169169
{showPrevious ? 'Hide Previous Events' : 'Show Previous Events'}
170170
</Button>
171171
</div>
172-
<Table style={{ tableLayout: 'fixed', width: '100%' }}>
172+
<Table style={{ tableLayout: 'fixed', width: '100%' }} data-testid="events-table">
173173
<Table.Thead>
174174
<Table.Tr>
175175
<Table.Th>Title</Table.Th>

tests/e2e/base.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { test as base } from "@playwright/test";
2+
import {
3+
SecretsManagerClient,
4+
GetSecretValueCommand,
5+
} from "@aws-sdk/client-secrets-manager";
6+
7+
export const getSecretValue = async (
8+
secretId: string,
9+
): Promise<Record<string, string | number | boolean> | null> => {
10+
const smClient = new SecretsManagerClient();
11+
const data = await smClient.send(
12+
new GetSecretValueCommand({ SecretId: secretId }),
13+
);
14+
if (!data.SecretString) {
15+
return null;
16+
}
17+
try {
18+
return JSON.parse(data.SecretString) as Record<
19+
string,
20+
string | number | boolean
21+
>;
22+
} catch {
23+
return null;
24+
}
25+
};
26+
27+
async function getSecrets() {
28+
let response = { PLAYWRIGHT_USERNAME: "", PLAYWRIGHT_PASSWORD: "" };
29+
let keyData;
30+
if (!process.env.PLAYWRIGHT_USERNAME || !process.env.PLAYWRIGHT_PASSWORD) {
31+
keyData = await getSecretValue("infra-core-api-config");
32+
}
33+
response["PLAYWRIGHT_USERNAME"] =
34+
process.env.PLAYWRIGHT_USERNAME ||
35+
(keyData ? keyData["playwright_username"] : "");
36+
response["PLAYWRIGHT_PASSWORD"] =
37+
process.env.PLAYWRIGHT_PASSWORD ||
38+
(keyData ? keyData["playwright_password"] : "");
39+
return response;
40+
}
41+
42+
const secrets = await getSecrets();
43+
44+
export function capitalizeFirstLetter(string: string) {
45+
return string.charAt(0).toUpperCase() + string.slice(1);
46+
}
47+
48+
async function becomeUser(page) {
49+
await page.goto("https://manage.qa.acmuiuc.org/login");
50+
await page
51+
.getByRole("button", { name: "Sign in with Illinois NetID" })
52+
.click();
53+
await page.getByPlaceholder("[email protected]").click();
54+
await page
55+
.getByPlaceholder("[email protected]")
56+
.fill(secrets["PLAYWRIGHT_USERNAME"]);
57+
await page.getByPlaceholder("[email protected]").press("Enter");
58+
await page.getByPlaceholder("Password").click();
59+
await page.getByPlaceholder("Password").fill(secrets["PLAYWRIGHT_PASSWORD"]);
60+
await page.getByRole("button", { name: "Sign in" }).click();
61+
await page.getByRole("button", { name: "No" }).click();
62+
}
63+
64+
export async function getUpcomingEvents() {
65+
const data = await fetch(
66+
"https://infra-core-api.aws.qa.acmuiuc.org/api/v1/events?upcomingOnly=true",
67+
);
68+
return (await data.json()) as Record<string, string>[];
69+
}
70+
71+
export async function getAllEvents() {
72+
const data = await fetch(
73+
"https://infra-core-api.aws.qa.acmuiuc.org/api/v1/events",
74+
);
75+
return (await data.json()) as Record<string, string>[];
76+
}
77+
78+
export const test = base.extend<{ becomeUser: (page) => Promise<void> }>({
79+
becomeUser: async ({}, use) => {
80+
use(becomeUser);
81+
},
82+
});

tests/e2e/events.spec.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { expect } from "@playwright/test";
2+
import { capitalizeFirstLetter, getUpcomingEvents, test } from "./base";
3+
import { describe } from "node:test";
4+
5+
describe("Events tests", () => {
6+
test("A user can login and view the upcoming events", async ({
7+
page,
8+
becomeUser,
9+
}) => {
10+
await becomeUser(page);
11+
await page.locator("a").filter({ hasText: "Events" }).click();
12+
await expect(page.getByRole("heading")).toContainText(
13+
"Core Management Service (NonProd)",
14+
);
15+
await expect(
16+
page.getByRole("button", { name: "New Calendar Event" }),
17+
).toBeVisible();
18+
await expect(
19+
page.getByRole("button", { name: "Show Previous Events" }),
20+
).toBeVisible();
21+
22+
const table = page.getByTestId("events-table");
23+
await expect(table).toBeVisible();
24+
25+
const rows = await table.locator("tbody tr").all();
26+
const expectedTableData = await getUpcomingEvents();
27+
28+
for (let i = 0; i < rows.length; i++) {
29+
const row = rows[i];
30+
const expectedData = expectedTableData[i];
31+
const title = await row.locator("td:nth-child(1)").innerText();
32+
const location = await row.locator("td:nth-child(4)").innerText();
33+
const description = await row.locator("td:nth-child(5)").innerText();
34+
const host = await row.locator("td:nth-child(6)").innerText();
35+
const featured = await row.locator("td:nth-child(7)").innerText();
36+
const repeats = await row.locator("td:nth-child(8)").innerText();
37+
38+
expect(title).toEqual(expectedData.title);
39+
expect(location).toEqual(expectedData.location);
40+
expect(description).toEqual(expectedData.description);
41+
expect(host).toEqual(expectedData.host);
42+
expect(featured).toEqual(expectedData.featured ? "Yes" : "No");
43+
expect(repeats).toEqual(capitalizeFirstLetter(expectedData.repeats));
44+
}
45+
46+
expect(page.url()).toEqual("https://manage.qa.acmuiuc.org/events/manage");
47+
});
48+
});

tests/e2e/login.spec.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect } from "@playwright/test";
2+
import { test } from "./base";
3+
import { describe } from "node:test";
4+
5+
describe("Login tests", () => {
6+
test("A user can login and view the home screen", async ({
7+
page,
8+
becomeUser,
9+
}) => {
10+
await becomeUser(page);
11+
await expect(
12+
page.locator("a").filter({ hasText: "Management Portal DEV ENV" }),
13+
).toBeVisible();
14+
await expect(page.locator("a").filter({ hasText: "Events" })).toBeVisible();
15+
await expect(
16+
page.locator("a").filter({ hasText: "Ticketing/Merch" }),
17+
).toBeVisible();
18+
await expect(page.locator("a").filter({ hasText: "IAM" })).toBeVisible();
19+
await expect(
20+
page.getByRole("link", { name: "ACM Logo Management Portal" }),
21+
).toBeVisible();
22+
await expect(
23+
page.getByRole("link", { name: "P", exact: true }),
24+
).toBeVisible();
25+
await page.getByRole("link", { name: "P", exact: true }).click();
26+
await expect(page.getByLabel("PMy Account")).toContainText(
27+
"Name Playwright Core User",
28+
);
29+
await expect(page.getByLabel("PMy Account")).toContainText(
30+
31+
);
32+
expect(page.url()).toEqual("https://manage.qa.acmuiuc.org/home");
33+
});
34+
});

0 commit comments

Comments
 (0)