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.

add e2e tests for contacts

Khuram Niaz8346511d737d
diff --git a/e2e/contacts.spec.ts b/e2e/contacts.spec.ts
new file mode 100644
index 0000000..2f914d2
--- /dev/null
+++ b/e2e/contacts.spec.ts
@@ -0,0 +1,331 @@
+import { randomUUID } from "crypto";
+import { type Locator, type Page } from "@playwright/test";
+import {
+ test,
+ expect,
+ createNewJob,
+ uniqueName,
+ type CleanupRegistry,
+} from "./fixtures";
+
+// selectOrCreate with an exact label: its substring match also hits the
+// "Filter by role" select and the "Contacts" tabpanel. Same popover-close wait.
+async function pick(
+ page: Page,
+ scope: Locator | Page,
+ label: string,
+ placeholder: string,
+ value: string,
+) {
+ await scope.getByLabel(label, { exact: true }).click();
+ const input = page.getByPlaceholder(placeholder);
+ await input.fill(value);
+ const createOption = page.getByText(`Create: ${value}`);
+ const existingOption = page.getByRole("option", { name: value, exact: true });
+ await expect(createOption.or(existingOption).first()).toBeVisible();
+ if (await existingOption.isVisible()) {
+ await existingOption.click();
+ } else {
+ await createOption.click();
+ }
+ await expect(input).not.toBeVisible({ timeout: 15000 });
+}
+
+async function navigateToContacts(page: Page) {
+ await page.goto("/dashboard/admin?tab=contacts");
+ await page.getByTestId("add-contact-btn").waitFor({ state: "visible" });
+}
+
+// The list is name-ordered and paginated, so a new row isn't guaranteed to
+// be on page 1 — narrow it with the search box before asserting.
+function contactRow(page: Page, name: string) {
+ return page.getByRole("row").filter({ hasText: name });
+}
+
+async function searchContacts(page: Page, term: string) {
+ await page.getByPlaceholder("Search contacts...").fill(term);
+}
+
+// Creates a contact from the Library Contacts tab. Company and role are
+// inline-created through their comboboxes, so each is registered for
+// teardown the moment it persists.
+async function createContact(
+ page: Page,
+ cleanup: CleanupRegistry,
+ name: string,
+ options?: { title?: string; email?: string; company?: string; role?: string },
+) {
+ await page.getByTestId("add-contact-btn").click();
+ const dialog = page.getByRole("dialog");
+ await expect(dialog.getByRole("heading", { name: "Add Contact" })).toBeVisible();
+
+ await dialog.getByLabel("Name", { exact: true }).fill(name);
+ if (options?.title) {
+ await dialog.getByLabel("Title", { exact: true }).fill(options.title);
+ }
+ if (options?.email) {
+ await dialog.getByLabel("Email", { exact: true }).fill(options.email);
+ }
+ if (options?.company) {
+ await pick(page, dialog, "Company", "Create or Search company", options.company);
+ cleanup.company(options.company);
+ }
+ if (options?.role) {
+ await pick(page, dialog, "Role", "Create or Search role", options.role);
+ cleanup.contactRole(options.role);
+ }
+
+ await dialog.getByRole("button", { name: "Save" }).click();
+ cleanup.contact(name);
+ await expect(dialog).not.toBeVisible();
+}
+
+async function openJobContactsTab(page: Page, jobId: string) {
+ await page.goto(`/dashboard/myjobs/${jobId}?tab=contacts`);
+}
+
+// Links an existing contact to a job from the job's Contacts tab, creating a
+// fresh role inline.
+async function linkContactToJob(
+ page: Page,
+ cleanup: CleanupRegistry,
+ jobId: string,
+ contactName: string,
+ roleName: string,
+) {
+ await openJobContactsTab(page, jobId);
+ await page.getByRole("button", { name: "Add Contact" }).click();
+ await pick(page, page, "Contact", "Search contact", contactName);
+ await pick(page, page, "Role", "Create or Search role", roleName);
+ cleanup.contactRole(roleName);
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+
+ const link = page.getByRole("listitem").filter({ hasText: contactName });
+ await expect(link).toBeVisible();
+ await expect(link).toContainText(roleName);
+}
+
+test.describe("Contacts Library", () => {
+ test("creates a contact with an inline company and role", async ({
+ page,
+ cleanup,
+ }) => {
+ const name = uniqueName("Dana Whitfield");
+ const company = uniqueName("contact company");
+ const role = uniqueName("Panel Lead");
+ const email = `dana-${randomUUID().slice(0, 8)}@example.com`;
+
+ await navigateToContacts(page);
+ await createContact(page, cleanup, name, { email, company, role });
+
+ await searchContacts(page, name);
+ const row = contactRow(page, name);
+ await expect(row).toContainText(company);
+ await expect(row).toContainText(role);
+
+ await page.getByRole("button", { name: `Expand ${name}` }).click();
+ await expect(page.getByRole("link", { name: email })).toBeVisible();
+ });
+
+ test("edits a contact", async ({ page, cleanup }) => {
+ const name = uniqueName("Riley Chen");
+
+ await navigateToContacts(page);
+ await createContact(page, cleanup, name, { title: "Recruiter" });
+ await searchContacts(page, name);
+
+ await contactRow(page, name)
+ .getByRole("button", { name: "Toggle menu" })
+ .click();
+ await page.getByRole("menuitem", { name: "Edit Contact" }).click();
+
+ const dialog = page.getByRole("dialog");
+ await expect(dialog.getByRole("heading", { name: "Edit Contact" })).toBeVisible();
+ await expect(dialog.getByLabel("Name", { exact: true })).toHaveValue(name);
+ await expect(dialog.getByLabel("Title", { exact: true })).toHaveValue(
+ "Recruiter",
+ );
+ await dialog
+ .getByLabel("Title", { exact: true })
+ .fill("Engineering Manager");
+ await dialog.getByRole("button", { name: "Save" }).click();
+ await expect(dialog).not.toBeVisible();
+
+ await expect(contactRow(page, name)).toContainText("Engineering Manager");
+ });
+
+ test("filters contacts by their standing role", async ({ page, cleanup }) => {
+ // Shared suffix lets one search term match both contacts below
+ const suffix = randomUUID().slice(0, 8);
+ const withRole = `Morgan Hale ${suffix}`;
+ const withoutRole = `Taylor Brooks ${suffix}`;
+ const role = uniqueName("Reference Check");
+
+ await navigateToContacts(page);
+ await createContact(page, cleanup, withRole, { role });
+ await createContact(page, cleanup, withoutRole);
+
+ // The role filter's options load on mount, so pick up the new role
+ await page.reload();
+ await searchContacts(page, suffix);
+ await expect(contactRow(page, withRole)).toBeVisible();
+ await expect(contactRow(page, withoutRole)).toBeVisible();
+
+ await page.getByLabel("Filter by role").click();
+ await page.getByRole("option", { name: role, exact: true }).click();
+
+ await expect(contactRow(page, withRole)).toBeVisible();
+ await expect(contactRow(page, withoutRole)).not.toBeVisible();
+ });
+
+ test("warns before deleting a contact linked to a job, then removes the link", async ({
+ page,
+ cleanup,
+ }) => {
+ const name = uniqueName("Jordan Pike");
+ const role = uniqueName("Interviewer");
+ const jobText = uniqueName("contact delete job");
+
+ const jobId = await createNewJob(page, jobText, cleanup);
+ await navigateToContacts(page);
+ await createContact(page, cleanup, name);
+ await linkContactToJob(page, cleanup, jobId, name, role);
+
+ await navigateToContacts(page);
+ await searchContacts(page, name);
+ const row = contactRow(page, name);
+ await expect(row).toBeVisible();
+ await row.getByRole("button", { name: "Toggle menu" }).click();
+ await page.getByRole("menuitem", { name: "Delete" }).click();
+
+ const alert = page.getByRole("alertdialog");
+ await expect(alert).toContainText("Delete this contact?");
+ await expect(alert).toContainText("linked to 1 job");
+ await alert.getByRole("button", { name: "Delete" }).click();
+ await expect(row).not.toBeVisible();
+
+ await openJobContactsTab(page, jobId);
+ await expect(page.getByText("No contacts on this job")).toBeVisible();
+ });
+
+ test("refuses to delete a role a contact holds", async ({
+ page,
+ cleanup,
+ }) => {
+ const name = uniqueName("Sam Ortiz");
+ const role = uniqueName("Referrer Role");
+
+ await navigateToContacts(page);
+ await createContact(page, cleanup, name, { role });
+
+ await page.goto("/dashboard/admin?tab=roles");
+ await page.getByPlaceholder("Search roles...").fill(role);
+ const row = page.getByRole("row").filter({ hasText: role });
+ await row.getByRole("button", { name: "Toggle menu" }).click();
+ await page.getByRole("menuitem", { name: "Delete" }).click();
+
+ const alert = page.getByRole("alertdialog");
+ await expect(alert).toContainText("Associated contacts exist!");
+ await expect(alert).toContainText("set on 1 contact");
+ await expect(alert.getByRole("button", { name: "Delete" })).toHaveCount(0);
+ });
+});
+
+test.describe("Job Contacts tab", () => {
+ test("links a contact with a role and unlinks it without deleting the contact", async ({
+ page,
+ cleanup,
+ }) => {
+ const name = uniqueName("Avery Lang");
+ const role = uniqueName("Hiring Lead");
+ const jobText = uniqueName("contact link job");
+
+ const jobId = await createNewJob(page, jobText, cleanup);
+ await navigateToContacts(page);
+ await createContact(page, cleanup, name);
+ await linkContactToJob(page, cleanup, jobId, name, role);
+
+ await page.getByRole("button", { name: `Remove ${name}` }).click();
+ await page
+ .getByRole("alertdialog")
+ .getByRole("button", { name: "Delete" })
+ .click();
+ await expect(page.getByText("No contacts on this job")).toBeVisible();
+
+ await navigateToContacts(page);
+ await searchContacts(page, name);
+ await expect(contactRow(page, name)).toBeVisible();
+ });
+
+ test("creates a new contact from the typed name and links it", async ({
+ page,
+ cleanup,
+ }) => {
+ const name = uniqueName("Casey Rowe");
+ const role = uniqueName("Recruiter Role");
+ const jobText = uniqueName("contact new job");
+
+ const jobId = await createNewJob(page, jobText, cleanup);
+ await openJobContactsTab(page, jobId);
+ await page.getByRole("button", { name: "Add Contact" }).click();
+
+ // The picker has no create path; what's typed carries into the dialog
+ await page.getByLabel("Contact", { exact: true }).click();
+ await page.getByPlaceholder("Search contact").fill(name);
+ await page.keyboard.press("Escape");
+ await page.getByRole("button", { name: "New contact" }).click();
+
+ const dialog = page.getByRole("dialog");
+ await expect(dialog.getByLabel("Name", { exact: true })).toHaveValue(name);
+ await dialog.getByRole("button", { name: "Save" }).click();
+ cleanup.contact(name);
+ await expect(dialog).not.toBeVisible();
+ await expect(page.getByLabel("Contact", { exact: true })).toContainText(
+ name,
+ );
+
+ await pick(page, page, "Role", "Create or Search role", role);
+ cleanup.contactRole(role);
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+
+ const link = page.getByRole("listitem").filter({ hasText: name });
+ await expect(link).toContainText(role);
+ });
+});
+
+test.describe("Company Contacts tab", () => {
+ test("adds a contact with the company prefilled", async ({
+ page,
+ cleanup,
+ }) => {
+ const company = uniqueName("Contacts Tab Company");
+ const name = uniqueName("Robin Vale");
+
+ await page.goto("/dashboard/admin");
+ await page.getByTestId("add-company-btn").click();
+ await page.getByLabel("Company Name").fill(company);
+ await page.getByRole("button", { name: /save/i }).click();
+ cleanup.company(company);
+ await expect(page.getByRole("dialog")).not.toBeVisible();
+
+ await page.getByPlaceholder("Search companies...").fill(company);
+ await page.getByRole("link", { name: company, exact: true }).click();
+ await expect(page).toHaveURL(/\/dashboard\/admin\/companies\//);
+
+ await page.getByRole("tab", { name: "Contacts" }).click();
+ await expect(page.getByText("No contacts at this company yet")).toBeVisible();
+ await page.getByRole("button", { name: "Add Contact" }).click();
+
+ const dialog = page.getByRole("dialog");
+ await expect(dialog.getByLabel("Company", { exact: true })).toContainText(
+ company,
+ );
+ await dialog.getByLabel("Name", { exact: true }).fill(name);
+ await dialog.getByRole("button", { name: "Save" }).click();
+ cleanup.contact(name);
+ await expect(dialog).not.toBeVisible();
+
+ await expect(page.getByText("Works here")).toBeVisible();
+ await expect(page.getByRole("row").filter({ hasText: name })).toBeVisible();
+ });
+});
diff --git a/e2e/fixtures.ts b/e2e/fixtures.ts
index ca75858..89d7623 100644
--- a/e2e/fixtures.ts
+++ b/e2e/fixtures.ts
@@ -150,6 +150,8 @@ export type CleanupRegistry = {
tag: (name: string) => void;
mcpToken: (name: string) => void;
automation: (name: string) => void;
+ contact: (name: string) => void;
+ contactRole: (name: string) => void;
};
type Fixtures = {
@@ -177,6 +179,8 @@ export const test = base.extend<Fixtures>({
const tags: string[] = [];
const mcpTokens: string[] = [];
const automations: string[] = [];
+ const contacts: string[] = [];
+ const contactRoles: string[] = [];
await use({
job: (id) => jobIds.push(id),
resume: (title) => resumes.push(title),
@@ -190,6 +194,8 @@ export const test = base.extend<Fixtures>({
tag: (name) => tags.push(name),
mcpToken: (name) => mcpTokens.push(name),
automation: (name) => automations.push(name),
+ contact: (name) => contacts.push(name),
+ contactRole: (name) => contactRoles.push(name),
});
// page.request carries the session cookie; page is still alive here
// because cleanup tears down before the page fixture.
@@ -207,6 +213,8 @@ export const test = base.extend<Fixtures>({
tags,
mcpTokens,
automations,
+ contacts,
+ contactRoles,
},
});
if (!res.ok()) {
diff --git a/src/app/api/test/cleanup/route.ts b/src/app/api/test/cleanup/route.ts
index 90b243e..8b72b0c 100644
--- a/src/app/api/test/cleanup/route.ts
+++ b/src/app/api/test/cleanup/route.ts
@@ -31,6 +31,8 @@ export async function POST(req: NextRequest) {
tags = [],
mcpTokens = [],
automations = [],
+ contacts = [],
+ contactRoles = [],
}: {
jobIds?: string[];
resumes?: string[];
@@ -44,6 +46,8 @@ export async function POST(req: NextRequest) {
tags?: string[];
mcpTokens?: string[];
automations?: string[];
+ contacts?: string[];
+ contactRoles?: string[];
} = await req.json();
// Delete automations before resumes: Automation.resumeId is a required FK, so
@@ -102,12 +106,21 @@ export async function POST(req: NextRequest) {
});
}
+ // Delete contacts before the Library teardown: they reference companies,
+ // locations and roles. Their job links cascade with them.
+ if (contacts.length > 0) {
+ await prisma.contact.deleteMany({
+ where: { name: { in: contacts }, createdBy: userId },
+ });
+ }
+
// Sources are never created by the tests (they select the seeded "Indeed"),
// so they are intentionally not cleaned up here.
await deleteLibraryByName("jobTitle", titles, userId);
await deleteLibraryByName("company", companies, userId);
await deleteLibraryByName("location", locations, userId);
await deleteLibraryByName("activityType", activityTypes, userId);
+ await deleteLibraryByName("contactRole", contactRoles, userId);
await deleteTagsByName(tags, userId);
if (mcpTokens.length > 0) {
await prisma.mcpAccessToken.deleteMany({
@@ -138,7 +151,12 @@ async function deleteTagsByName(names: string[], userId: string) {
}
}
-type RefModel = "jobTitle" | "company" | "location" | "activityType";
+type RefModel =
+ | "jobTitle"
+ | "company"
+ | "location"
+ | "activityType"
+ | "contactRole";
// Count every place a Library row can still be referenced from, so we never
// delete one that another job or resume section still uses.
@@ -155,7 +173,10 @@ async function referenceCount(
if (model === "company") {
return (
(await prisma.job.count({ where: { companyId: refId } })) +
- (await prisma.workExperience.count({ where: { companyId: refId } }))
+ (await prisma.workExperience.count({ where: { companyId: refId } })) +
+ (await prisma.contact.count({
+ where: { OR: [{ companyId: refId }, { workedAtCompanyId: refId }] },
+ }))
);
}
if (model === "activityType") {
@@ -164,10 +185,17 @@ async function referenceCount(
(await prisma.task.count({ where: { activityTypeId: refId } }))
);
}
+ if (model === "contactRole") {
+ return (
+ (await prisma.jobContact.count({ where: { roleId: refId } })) +
+ (await prisma.contact.count({ where: { roleId: refId } }))
+ );
+ }
return (
(await prisma.job.count({ where: { locationId: refId } })) +
(await prisma.workExperience.count({ where: { locationId: refId } })) +
- (await prisma.education.count({ where: { locationId: refId } }))
+ (await prisma.education.count({ where: { locationId: refId } })) +
+ (await prisma.contact.count({ where: { locationId: refId } }))
);
}