Skip to content

Commit e52fab3

Browse files
committed
Add testing setup and Playwright smoke test
1 parent ceb61ef commit e52fab3

5 files changed

Lines changed: 98 additions & 2 deletions

File tree

e2e/smoke.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("loads the scheduler", async ({ page }) => {
4+
await page.goto("/");
5+
6+
await expect(
7+
page.getByRole("heading", { name: "AZQUERYSUCKS" }),
8+
).toBeVisible();
9+
10+
await expect(page.getByRole("button", { name: "加入課程" })).toBeVisible();
11+
});

playwright.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from "@playwright/test";
2+
3+
export default defineConfig({
4+
testDir: "./e2e",
5+
fullyParallel: true,
6+
use: {
7+
baseURL: "http://localhost:4173/AZQUERYSUCKS/",
8+
trace: "on-first-retry",
9+
},
10+
webServer: {
11+
command:
12+
"pnpm build && pnpm start -- --host 0.0.0.0 --port 4173 --strictPort",
13+
url: "http://localhost:4173/AZQUERYSUCKS/",
14+
timeout: 180000,
15+
reuseExistingServer: !process.env.CI,
16+
},
17+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/// <reference types="@testing-library/jest-dom" />
2+
3+
import { render, screen, waitFor } from "@testing-library/react";
4+
import userEvent from "@testing-library/user-event";
5+
import { describe, expect, it } from "vitest";
6+
import { CourseInfoTable } from "@/components/course-info-table";
7+
import type { ScheduledCourse } from "@/types/course";
8+
9+
const courses: ScheduledCourse[] = [
10+
{
11+
source: "test",
12+
dept_block: "AA.資訊工程",
13+
grade: "1",
14+
seq: "001",
15+
code: "CS101",
16+
major: null,
17+
term_order: "1",
18+
class: "A",
19+
group_div: null,
20+
required: "必",
21+
credits: 3,
22+
group: "1",
23+
title: "Introduction to CS",
24+
cap: 30,
25+
teacher: "Ada",
26+
times: ["一(1-2)"],
27+
english_taught: false,
28+
},
29+
{
30+
source: "test",
31+
dept_block: "BB.數學系",
32+
grade: "2",
33+
seq: "002",
34+
code: "MATH201",
35+
major: null,
36+
term_order: "1",
37+
class: "B",
38+
group_div: null,
39+
required: "選",
40+
credits: 2,
41+
group: "1",
42+
title: "高等數學",
43+
cap: 40,
44+
teacher: "Euler",
45+
times: ["二(3-4)"],
46+
english_taught: false,
47+
},
48+
];
49+
50+
describe("CourseInfoTable", () => {
51+
it("filters by search term", async () => {
52+
const user = userEvent.setup();
53+
render(<CourseInfoTable courses={courses} />);
54+
55+
expect(screen.getByText("Introduction to CS")).toBeInTheDocument();
56+
57+
await user.type(
58+
screen.getByPlaceholderText("課名、教師、地點、代號.."),
59+
"數學",
60+
);
61+
62+
await waitFor(() => {
63+
expect(screen.queryByText("Introduction to CS")).not.toBeInTheDocument();
64+
});
65+
});
66+
});

src/test/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "@testing-library/jest-dom/vitest";

vitest.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { defineConfig } from "vitest/config";
33

44
export default defineConfig({
55
test: {
6-
environment: "node",
7-
include: ["src/**/*.test.ts"],
6+
environment: "jsdom",
7+
include: ["src/**/*.test.{ts,tsx}"],
8+
setupFiles: ["src/test/setup.ts"],
89
coverage: {
910
provider: "v8",
1011
reporter: ["text", "lcov"],

0 commit comments

Comments
 (0)