Skip to content

Commit b0cc9e4

Browse files
committed
add a basic upcoming events view test
1 parent 138e773 commit b0cc9e4

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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('/')`. */

tests/e2e/base.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,22 @@ async function becomeUser(page) {
5757
await page.getByRole("button", { name: "No" }).click();
5858
}
5959

60+
export async function getUpcomingEvents() {
61+
const data = await fetch('https://infra-core-api.aws.qa.acmuiuc.org/api/v1/events?upcomingOnly=true');
62+
return await data.json() as Record<string, string>[];
63+
}
64+
65+
export async function getAllEvents() {
66+
const data = await fetch('https://infra-core-api.aws.qa.acmuiuc.org/api/v1/events');
67+
return await data.json() as Record<string, string>[];
68+
}
69+
70+
export function capitalizeFirstLetter(string: string) {
71+
return string.charAt(0).toUpperCase() + string.slice(1);
72+
}
73+
6074
export const test = base.extend<{ becomeUser: (page) => Promise<void> }>({
61-
becomeUser: async ({}, use) => {
75+
becomeUser: async ({ }, use) => {
6276
use(becomeUser);
6377
},
6478
});

tests/e2e/events.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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('Core Management Service (NonProd)');
13+
await expect(page.getByRole('button', { name: 'New Calendar Event' })).toBeVisible();
14+
await expect(page.getByRole('button', { name: 'Show Previous Events' })).toBeVisible();
15+
16+
const table = page.getByTestId('events-table');
17+
await expect(table).toBeVisible();
18+
19+
const rows = await table.locator('tbody tr').all();
20+
const expectedTableData = await getUpcomingEvents();
21+
22+
for (let i = 0; i < rows.length; i++) {
23+
const row = rows[i];
24+
const expectedData = expectedTableData[i];
25+
26+
const title = await row.locator('td:nth-child(1)').innerText();
27+
const location = await row.locator('td:nth-child(4)').innerText();
28+
const description = await row.locator('td:nth-child(5)').innerText();
29+
const host = await row.locator('td:nth-child(6)').innerText();
30+
const featured = await row.locator('td:nth-child(7)').innerText();
31+
const repeats = await row.locator('td:nth-child(8)').innerText();
32+
33+
expect(title).toEqual(expectedData.title);
34+
expect(location).toEqual(expectedData.location);
35+
expect(description).toEqual(expectedData.description);
36+
expect(host).toEqual(expectedData.host);
37+
expect(featured).toEqual(expectedData.featured ? "Yes" : "No");
38+
expect(repeats).toEqual(capitalizeFirstLetter(expectedData.repeats));
39+
}
40+
41+
expect(page.url()).toEqual("https://manage.qa.acmuiuc.org/events/manage");
42+
});
43+
});

0 commit comments

Comments
 (0)