|
| 1 | +import path from "node:path"; |
| 2 | +import { expect, test } from "@playwright/test"; |
| 3 | +import { ACME, expectToast, jobCardTitles, loginCompany, reseed } from "./helpers"; |
| 4 | + |
| 5 | +// One Company session through the whole file, as a recruiter would work. |
| 6 | +test.describe.configure({ mode: "serial" }); |
| 7 | +test.beforeAll(reseed); |
| 8 | + |
| 9 | +test("wrong password is rejected", async ({ page }) => { |
| 10 | + await loginCompany(page, ACME.email, "wrong-password"); |
| 11 | + await expectToast(page, "Invalid email or password"); |
| 12 | + await expect(page).toHaveURL("/"); |
| 13 | +}); |
| 14 | + |
| 15 | +test.describe("signed in as Acme", () => { |
| 16 | + test.beforeEach(async ({ page }) => { |
| 17 | + await loginCompany(page, ACME.email, ACME.password); |
| 18 | + await expect(page).toHaveURL("/dashboard/manage-jobs"); |
| 19 | + }); |
| 20 | + |
| 21 | + test("dashboard greets the Company and lists its Jobs", async ({ page }) => { |
| 22 | + await expect(page.getByText(`Welcome, ${ACME.name}!`)).toBeVisible(); |
| 23 | + const rows = page.locator("tbody tr"); |
| 24 | + await expect(rows).toHaveCount(3); |
| 25 | + await expect(rows.filter({ hasText: "Backend Engineer (Go)" }).locator("td").nth(4)).toHaveText("1"); // applicants |
| 26 | + }); |
| 27 | + |
| 28 | + test("hiding a Job removes it from the public list", async ({ page }) => { |
| 29 | + const row = page.locator("tbody tr").filter({ hasText: "Data Analyst" }); |
| 30 | + await row.getByLabel("Visible").uncheck(); |
| 31 | + await expectToast(page, "Visibility changed"); |
| 32 | + await page.reload(); |
| 33 | + await expect(page.locator("tbody tr").filter({ hasText: "Data Analyst" }).getByLabel("Visible")).not.toBeChecked(); |
| 34 | + |
| 35 | + await page.goto("/"); |
| 36 | + await expect(jobCardTitles(page)).not.toContainText(["Data Analyst"]); |
| 37 | + }); |
| 38 | + |
| 39 | + test("posting a Job with the Quill editor", async ({ page }) => { |
| 40 | + await page.getByRole("link", { name: "Add Job" }).click(); |
| 41 | + await page.getByLabel("Job Title").fill("E2E Platform Engineer"); |
| 42 | + const editor = page.locator(".ql-editor"); |
| 43 | + await editor.click(); |
| 44 | + await page.keyboard.type("Run the "); |
| 45 | + await page.keyboard.press("ControlOrMeta+b"); |
| 46 | + await page.keyboard.type("platform"); |
| 47 | + await page.getByLabel("Job Category").selectOption("Programming"); |
| 48 | + await page.getByLabel("Job Location").selectOption("Chennai"); |
| 49 | + await page.getByLabel("Job Salary").fill("120000"); |
| 50 | + await page.getByRole("button", { name: "ADD" }).click(); |
| 51 | + await expectToast(page, "Job Added"); |
| 52 | + await expect(page.getByLabel("Job Title")).toHaveValue(""); // form cleared |
| 53 | + |
| 54 | + await page.getByRole("link", { name: "Manage Jobs" }).click(); |
| 55 | + await expect(page.locator("tbody tr").first()).toContainText("E2E Platform Engineer"); // newest first |
| 56 | + |
| 57 | + await page.goto("/"); |
| 58 | + await page.locator("#job-list ~ div > div").filter({ hasText: "E2E Platform Engineer" }).getByRole("link", { name: "Learn more" }).click(); |
| 59 | + await expect(page.locator(".rich-text strong")).toHaveText("platform"); // bold kept |
| 60 | + // The default level was accepted (shown next to the title). |
| 61 | + await expect(page.locator("span.flex").filter({ hasText: "Beginner level" })).toBeVisible(); |
| 62 | + }); |
| 63 | + |
| 64 | + test("an empty description is refused", async ({ page }) => { |
| 65 | + await page.getByRole("link", { name: "Add Job" }).click(); |
| 66 | + await page.getByLabel("Job Title").fill("No description"); |
| 67 | + await page.getByLabel("Job Salary").fill("1"); |
| 68 | + await page.getByRole("button", { name: "ADD" }).click(); |
| 69 | + await expect(page.getByText("required")).toBeVisible(); // field error under the editor |
| 70 | + }); |
| 71 | + |
| 72 | + test("accepting an Application", async ({ page }) => { |
| 73 | + await page.getByRole("link", { name: "View Applications" }).click(); |
| 74 | + const row = page.locator("tbody tr").filter({ hasText: "Alice Santoso" }); |
| 75 | + await expect(row).toContainText("Backend Engineer (Go)"); |
| 76 | + await row.getByRole("button", { name: "Change status" }).hover(); |
| 77 | + await row.getByRole("button", { name: "Accept" }).click(); |
| 78 | + await expectToast(page, "Status Changed"); |
| 79 | + await expect(row.locator("td").last()).toHaveText("Accepted"); |
| 80 | + }); |
| 81 | + |
| 82 | + test("logging out", async ({ page }) => { |
| 83 | + await page.getByRole("button", { name: "Account menu" }).hover(); |
| 84 | + await page.getByRole("button", { name: "Logout" }).click(); |
| 85 | + await expect(page).toHaveURL("/"); |
| 86 | + await page.goto("/dashboard/manage-jobs"); |
| 87 | + await expect(page).toHaveURL("/"); // no session: sent home by proxy.ts |
| 88 | + }); |
| 89 | +}); |
| 90 | + |
| 91 | +test("signing up a new Company with a logo", async ({ page }) => { |
| 92 | + await page.goto("/"); |
| 93 | + await page.getByRole("button", { name: "Recruiter Login" }).click(); |
| 94 | + await page.getByRole("button", { name: "Sign Up" }).click(); |
| 95 | + |
| 96 | + const details = page.getByRole("form", { name: "Recruiter Sign Up" }); |
| 97 | + await details.getByPlaceholder("Company Name").fill("E2E Company"); |
| 98 | + await details.getByPlaceholder("Email Id").fill("[email protected]"); |
| 99 | + await details.getByPlaceholder(/Password/).fill("secret123"); |
| 100 | + await details.getByRole("button", { name: "next" }).click(); |
| 101 | + |
| 102 | + const logo = page.getByRole("form", { name: "Upload Company Logo" }); |
| 103 | + await logo.locator('input[type="file"]').setInputFiles(path.join(__dirname, "fixtures", "logo.png")); |
| 104 | + await expect(logo.getByAltText("Company logo")).toHaveAttribute("src", /^blob:/); // preview |
| 105 | + await logo.getByRole("button", { name: "create account" }).click(); |
| 106 | + |
| 107 | + await expect(page).toHaveURL("/dashboard/manage-jobs"); |
| 108 | + await expect(page.getByText("Welcome, E2E Company!")).toBeVisible(); |
| 109 | + await expect(page.getByText("No Jobs posted yet")).toBeVisible(); |
| 110 | + // The logo was stored (on disk in e2e) and is shown in the header. |
| 111 | + await expect(page.getByRole("button", { name: "Account menu" }).locator("img")).toHaveAttribute("src", /uploads/); |
| 112 | +}); |
| 113 | + |
| 114 | +test("signing up with a taken email goes back to step one", async ({ page }) => { |
| 115 | + await page.goto("/"); |
| 116 | + await page.getByRole("button", { name: "Recruiter Login" }).click(); |
| 117 | + await page.getByRole("button", { name: "Sign Up" }).click(); |
| 118 | + const details = page.getByRole("form", { name: "Recruiter Sign Up" }); |
| 119 | + await details.getByPlaceholder("Company Name").fill("Acme Again"); |
| 120 | + await details.getByPlaceholder("Email Id").fill(ACME.email); |
| 121 | + await details.getByPlaceholder(/Password/).fill("secret123"); |
| 122 | + await details.getByRole("button", { name: "next" }).click(); |
| 123 | + await page.locator('input[type="file"]').setInputFiles(path.join(__dirname, "fixtures", "logo.png")); |
| 124 | + await page.getByRole("button", { name: "create account" }).click(); |
| 125 | + |
| 126 | + await expectToast(page, "already registered"); |
| 127 | + await expect(page.getByRole("form", { name: "Recruiter Sign Up" }).getByPlaceholder("Email Id")).toHaveValue(ACME.email); |
| 128 | +}); |
0 commit comments