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.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Add more addJob form tests
Khuram Niazd1eb9571c752
diff --git a/__tests__/AddJob.spec.tsx b/__tests__/AddJob.spec.tsxindex 5aa97de..409e834 100644--- a/__tests__/AddJob.spec.tsx+++ b/__tests__/AddJob.spec.tsx@@ -1,36 +1,67 @@import { AddJob } from "@/components/myjobs/AddJob";import { JOB_SOURCES } from "@/lib/data/jobSourcesData";import { JOB_STATUSES } from "@/lib/data/jobStatusesData";-import { getMockList } from "@/lib/mock.utils";+import { getMockJobDetails, getMockList } from "@/lib/mock.utils";import "@testing-library/jest-dom";import { screen, render, waitFor } from "@testing-library/react";import { getCurrentUser } from "@/utils/user.utils";import userEvent from "@testing-library/user-event";import { format } from "date-fns";-+import { addJob } from "@/actions/job.actions";jest.mock("@/utils/user.utils", () => ({getCurrentUser: jest.fn(),}));+jest.mock("@/actions/job.actions", () => ({+ addJob: jest.fn().mockResolvedValue({ success: true }),+}));++jest.mock("next/navigation", () => ({+ redirect: jest.fn(),+}));+global.ResizeObserver = jest.fn().mockImplementation(() => ({observe: jest.fn(),unobserve: jest.fn(),disconnect: jest.fn(),}));-describe("AddCompany Component", () => {+document.createRange = () => {+ const range = new Range();++ range.getBoundingClientRect = jest.fn().mockReturnValue({+ bottom: 0,+ height: 0,+ left: 0,+ right: 0,+ top: 0,+ width: 0,+ });++ range.getClientRects = () => {+ return {+ item: () => null,+ length: 0,+ [Symbol.iterator]: jest.fn(),+ };+ };++ return range;+};++describe("AddJob Component", () => {const mockUser = { id: "user-id" };const mockJobStatuses = JOB_STATUSES;const mockJobSources = JOB_SOURCES;const mockResetEditJob = jest.fn();- const user = userEvent.setup();- let container: HTMLElement | null;-+ const user = userEvent.setup({ skipHover: true });+ window.HTMLElement.prototype.scrollIntoView = jest.fn(); // Fixes the issue with combobox+ window.HTMLElement.prototype.hasPointerCapture = jest.fn();beforeEach(async () => {- jest.clearAllMocks();const mockCompanies = (await getMockList(1, 10, "companies")).data;const mockJobTitles = (await getMockList(1, 10, "jobTitles")).data;const mockLocations = (await getMockList(1, 10, "locations")).data;+ jest.clearAllMocks();render(<AddJobjobStatuses={mockJobStatuses}@@ -69,12 +100,8 @@ describe("AddCompany Component", () => {expect(dateApplied).toBeDisabled();expect(dateApplied).toHaveTextContent("Pick a date");});- it("should open the dialog when clicked on add job button with title 'Edit Job'", () => {- // const menuButton = screen.getByTestId("job-actions-menu-btn");- // user.click(editJobButton);- // const dialogTitle = screen.getByTestId("add-job-dialog-title");- // expect(dialogTitle).toBeInTheDocument();- // expect(dialogTitle).toHaveTextContent("Edit Job");+ it("should open the dialog when clicked on add job button with title 'Edit Job'", async () => {+ // TODO: To be tested with job container and jobs table component});it("should show relevant react-hook-form errors", async () => {const saveBtn = screen.getByTestId("save-job-btn");@@ -93,11 +120,110 @@ describe("AddCompany Component", () => {await user.click(cancelBtn);expect(dialog).not.toBeInTheDocument();});- it("should closes the dialog and submit to save job when clicked on save button", () => {});- it("should load and show the job title combobox list", () => {});- it("should load and show the company combobox list", () => {});- it("should load and show the location combobox list", () => {});- it("should load and show the job source combobox list", () => {});- it("should load and show the salary range select list", () => {});- it("should load and show the status select list", () => {});+ it("should load and show the job title combobox list", async () => {+ const jobTitleCombobox = screen.getByLabelText("Job Title");+ await user.click(jobTitleCombobox);+ const options = screen.getAllByRole("option");+ expect(options.length).toBeGreaterThan(0);+ expect(options[0].textContent).toBe("Frontend Developer");+ });+ it("should load and show the company combobox list", async () => {+ const companyCombobox = screen.getByLabelText("Company");+ await user.click(companyCombobox);+ const options = screen.getAllByRole("option");+ expect(options.length).toBeGreaterThan(0);+ expect(options[0].textContent).toBe("Google");+ });+ it("should load and show the location combobox list", async () => {+ const locationCombobox = screen.getByLabelText("Job Location");+ await user.click(locationCombobox);+ const options = screen.getAllByRole("option");+ expect(options.length).toBeGreaterThan(0);+ expect(options[0].textContent).toBe("San Francisco");+ });+ it("should load and show the job source combobox list", async () => {+ const sourceCombobox = screen.getByLabelText("Job Source");+ await user.click(sourceCombobox);+ const options = screen.getAllByRole("option");+ expect(options.length).toBeGreaterThan(0);+ expect(options[0].textContent).toBe("Indeed");+ });+ it("should load and show the salary range select list", async () => {+ const salaryRangeSelect = screen.getByLabelText("Salary Range");+ await user.click(salaryRangeSelect);+ const options = screen.getAllByRole("option");+ expect(options.length).toBeGreaterThan(0);+ expect(options[0].textContent).toBe("0 - 10,000");+ });+ it("should load and show the status select list", async () => {+ const statusSelect = screen.getByLabelText("Status");+ await user.click(statusSelect);+ const options = screen.getAllByRole("option");+ expect(options.length).toBeGreaterThan(0);+ expect(options[0].textContent).toBe("Draft");+ });+ it("should closes the dialog and submit to save job when clicked on save button", async () => {+ const jobTitleInput = screen.getByRole("combobox", {+ name: /job title/i,+ }) as HTMLSelectElement;+ await user.click(jobTitleInput);+ const selectedJobTitle = screen.getByRole("option", {+ name: "Full Stack Developer",+ });+ await user.click(selectedJobTitle);++ const companyInput = screen.getByRole("combobox", { name: /company/i });+ await user.click(companyInput);+ const selectedCompany = screen.getByRole("option", {+ name: "Amazon",+ });+ await user.click(selectedCompany);++ const locationInput = screen.getByRole("combobox", {+ name: /job location/i,+ });+ await user.click(locationInput);+ const selectedLocation = screen.getByRole("option", {+ name: "Remote",+ });+ await user.click(selectedLocation);++ const sourceInput = screen.getByRole("combobox", {+ name: /job source/i,+ });+ await user.click(sourceInput);+ const selectedSource = screen.getByRole("option", {+ name: "Indeed",+ });+ await user.click(selectedSource);++ const editableDiv = screen.getByLabelText("Job Description");+ const pTag = editableDiv.querySelector("div > p");+ if (pTag) {+ pTag.textContent = "New Job Description";+ }++ const dialog = await screen.findByRole("dialog");+ const saveBtn = screen.getByTestId("save-job-btn");+ await user.click(saveBtn);++ await waitFor(() => {+ expect(addJob).toHaveBeenCalledTimes(1);+ expect(dialog).not.toBeInTheDocument();+ expect(addJob).toHaveBeenCalledWith({+ title: "1xx",+ company: "2zz",+ location: "1yy",+ type: "FT",+ source: "1359dac4-a397-4461-b747-382706dcbe79",+ status: "d7ba200a-6dc1-4ea8-acff-29ebb0d4676a",+ dueDate: expect.any(Date),+ dateApplied: undefined,+ salaryRange: "1",+ jobDescription: "<p>New Job Description</p>",+ jobUrl: undefined,+ applied: false,+ });+ });+ });});diff --git a/src/components/TiptapEditor.tsx b/src/components/TiptapEditor.tsxindex 4339c31..c07ccf7 100644--- a/src/components/TiptapEditor.tsx+++ b/src/components/TiptapEditor.tsx@@ -89,7 +89,11 @@ const Tiptap = ({ field }: { field: ControllerRenderProps<any, any> }) => {</Toggle></div>)}- <EditorContent placeholder="enter here..." editor={editor} />+ <EditorContent+ aria-labelledby="job-description-label"+ placeholder="enter here..."+ editor={editor}+ /></div>);};diff --git a/src/components/myjobs/AddJob.tsx b/src/components/myjobs/AddJob.tsxindex 88d4d72..6abe84b 100644--- a/src/components/myjobs/AddJob.tsx+++ b/src/components/myjobs/AddJob.tsx@@ -418,7 +418,9 @@ export function AddJob({name="jobDescription"render={({ field }) => (<FormItem className="flex flex-col">- <FormLabel>Job Description</FormLabel>+ <FormLabel id="job-description-label">+ Job Description+ </FormLabel><FormControl><TiptapEditor field={field} /></FormControl>diff --git a/src/lib/data/myJobsData.ts b/src/lib/data/myJobsData.tsindex 6c122ae..1c5387f 100644--- a/src/lib/data/myJobsData.ts+++ b/src/lib/data/myJobsData.ts@@ -7,14 +7,14 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {id: "2",userId: "xyz",Company: {- id: "2",+ id: "2zz",label: "Amazon",value: "amazon",createdBy: "xyz",logoUrl: "/icons/amazon-logo.svg",},JobTitle: {- id: "1",+ id: "1xx",label: "Full Stack Developer",value: "full stack developer",createdBy: "xyz",@@ -22,7 +22,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Draft", value: "draft" },JobSource: { id: "1", label: "Indeed", value: "indeed" },appliedDate: new Date("2024-06-19"),@@ -43,7 +48,7 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {logoUrl: "/icons/google-logo.svg",},JobTitle: {- id: "1",+ id: "1xx",label: "Full Stack Developer",value: "full stack developer",createdBy: "xyz",@@ -51,7 +56,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Rejected", value: "rejected" },JobSource: { id: "1", label: "Indeed", value: "indeed" },appliedDate: new Date("2024-06-20"),@@ -72,7 +82,7 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {logoUrl: "/icons/facebook-logo.svg",},JobTitle: {- id: "1",+ id: "1xx",label: "Full Stack Developer",value: "full stack developer",createdBy: "xyz",@@ -80,7 +90,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Applied", value: "applied" },JobSource: { id: "1", label: "Indeed", value: "indeed" },appliedDate: new Date("2024-06-19"),@@ -101,7 +116,7 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {logoUrl: "/icons/netflix-logo.svg",},JobTitle: {- id: "1",+ id: "1xx",label: "Full Stack Developer",value: "full stack developer",createdBy: "xyz",@@ -109,7 +124,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Applied", value: "applied" },JobSource: { id: "2", label: "Linkedin", value: "linkedin" },appliedDate: new Date("2024-06-18"),@@ -157,7 +177,7 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {id: "7",userId: "xyz",Company: {- id: "2",+ id: "2zz",label: "Amazon",value: "amazon",createdBy: "xyz",@@ -172,7 +192,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Applied", value: "applied" },JobSource: { id: "1", label: "Indeed", value: "indeed" },appliedDate: new Date("2024-06-19"),@@ -201,7 +226,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Applied", value: "applied" },JobSource: { id: "1", label: "Indeed", value: "indeed" },appliedDate: new Date("2024-06-19"),@@ -264,7 +294,12 @@ export const MY_JOBS_DATA: { data: JobResponse[]; total: number } = {jobType: "FT",jobUrl: "",applied: true,- Location: { id: "1", label: "Remote", value: "remote", createdBy: "xyz" },+ Location: {+ id: "1yy",+ label: "Remote",+ value: "remote",+ createdBy: "xyz",+ },Status: { id: "1", label: "Applied", value: "applied" },JobSource: { id: "2", label: "Linkedin", value: "linkedin" },appliedDate: new Date("2024-06-19"),