Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

update e2e tests for company management

Khuram Niaz0a3451f62349
diff --git a/e2e/admin-companies.spec.ts b/e2e/admin-companies.spec.ts
index 8dd9181..63d8d48 100644
--- a/e2e/admin-companies.spec.ts
+++ b/e2e/admin-companies.spec.ts
@@ -3,6 +3,7 @@ import { type Page } from "@playwright/test";
import {
test,
expect,
+ createNewJob,
uniqueName,
type CleanupRegistry,
} from "./fixtures";
@@ -23,11 +24,18 @@ async function createCompany(
page: Page,
companyName: string,
cleanup: CleanupRegistry,
+ options?: { websiteUrl?: string; industry?: string },
) {
await page.getByTestId("add-company-btn").click();
await expect(page.getByText("Add Company")).toBeVisible();
await page.getByLabel("Company Name").fill(companyName);
+ if (options?.websiteUrl) {
+ await page.getByLabel("Website", { exact: true }).fill(options.websiteUrl);
+ }
+ if (options?.industry) {
+ await page.getByLabel("Industry", { exact: true }).fill(options.industry);
+ }
await page.getByRole("button", { name: /save/i }).click();
cleanup.company(companyName);
@@ -105,3 +113,118 @@ test.describe("Admin Companies search", () => {
).not.toBeVisible();
});
});
+
+// The list is paginated, so narrow it with the search box. Starts from a fresh
+// load: createCompany's search-clear reloads instantly while a new search waits
+// out a 300ms debounce, so a leftover row can vanish mid-click. Waiting for
+// header + one row means the filtered response has rendered.
+async function searchCompanyRow(page: Page, name: string) {
+ await navigateToCompanies(page);
+ await page.getByPlaceholder("Search companies...").fill(name);
+ await expect(page.getByRole("row")).toHaveCount(2);
+ return page.getByRole("row").filter({ hasText: name });
+}
+
+async function openRowMenuItem(page: Page, name: string, item: string) {
+ const row = await searchCompanyRow(page, name);
+ await row.getByRole("button", { name: "Toggle menu" }).click();
+ await page.getByRole("menuitem", { name: item }).click();
+}
+
+test.describe("Admin Companies", () => {
+ test("adds a company and shows its details page", async ({
+ page,
+ cleanup,
+ }) => {
+ const companyName = uniqueName("Initech");
+ const industry = uniqueName("Financial Services");
+
+ await navigateToCompanies(page);
+ await createCompany(page, companyName, cleanup, {
+ websiteUrl: "https://initech.example.com",
+ industry,
+ });
+
+ await searchCompanyRow(page, companyName);
+ await page.getByRole("link", { name: companyName, exact: true }).click();
+ await expect(page).toHaveURL(/\/dashboard\/admin\/companies\//);
+ await expect(
+ page.getByRole("heading", { name: companyName, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByText(`${industry} · initech.example.com`),
+ ).toBeVisible();
+ });
+
+ test("edits a company's name and industry", async ({ page, cleanup }) => {
+ const companyName = uniqueName("Globex");
+ const renamed = uniqueName("Globex Renamed");
+ const industry = uniqueName("Energy");
+
+ await navigateToCompanies(page);
+ await createCompany(page, companyName, cleanup);
+ await openRowMenuItem(page, companyName, "Edit Company");
+
+ const dialog = page.getByRole("dialog");
+ await expect(
+ dialog.getByRole("heading", { name: "Edit Company" }),
+ ).toBeVisible();
+ await expect(dialog.getByLabel("Company Name")).toHaveValue(companyName);
+ await dialog.getByLabel("Company Name").fill(renamed);
+ await dialog.getByLabel("Industry", { exact: true }).fill(industry);
+ // Cleanup matches on the stored value, which the rename replaces
+ cleanup.company(renamed);
+ await dialog.getByRole("button", { name: "Save" }).click();
+ await expect(dialog).not.toBeVisible();
+
+ await expect(
+ (await searchCompanyRow(page, renamed)).getByRole("link", {
+ name: renamed,
+ exact: true,
+ }),
+ ).toBeVisible();
+
+ await page.getByRole("link", { name: renamed, exact: true }).click();
+ await expect(
+ page.getByRole("heading", { name: renamed, exact: true }),
+ ).toBeVisible();
+ // Shown twice: the header subtitle and the summary card's Industry fact
+ await expect(page.getByText(industry, { exact: true })).toHaveCount(2);
+ });
+
+ test("deletes a company", async ({ page, cleanup }) => {
+ const companyName = uniqueName("Hooli");
+
+ await navigateToCompanies(page);
+ await createCompany(page, companyName, cleanup);
+ await openRowMenuItem(page, companyName, "Delete");
+
+ const alert = page.getByRole("alertdialog");
+ await expect(alert).toContainText(
+ "Are you sure you want to delete this company?",
+ );
+ await alert.getByRole("button", { name: "Delete" }).click();
+ await expect(alert).not.toBeVisible();
+
+ await expect(
+ page.getByRole("row").filter({ hasText: companyName }),
+ ).toHaveCount(0);
+ });
+
+ test("refuses to delete a company with an associated job", async ({
+ page,
+ cleanup,
+ }) => {
+ const companyName = uniqueName("Massive Dynamic");
+ const jobText = uniqueName("company delete job");
+
+ await createNewJob(page, jobText, cleanup, { company: companyName });
+ await navigateToCompanies(page);
+ await openRowMenuItem(page, companyName, "Delete");
+
+ const alert = page.getByRole("alertdialog");
+ await expect(alert).toContainText("Associated jobs exist!");
+ await expect(alert).toContainText("1 associated job");
+ await expect(alert.getByRole("button", { name: "Delete" })).toHaveCount(0);
+ });
+});