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 create resume unit tests

Khuram Niaz7a8778cad145
diff --git a/__tests__/CreateResume.spec.tsx b/__tests__/CreateResume.spec.tsx
new file mode 100644
index 0000000..8b08b3d
--- /dev/null
+++ b/__tests__/CreateResume.spec.tsx
@@ -0,0 +1,82 @@
+import CreateResume from "@/components/profile/CreateResume";
+import { Resume } from "@/models/profile.model";
+import { render, screen, fireEvent, waitFor } from "@testing-library/react";
+import "@testing-library/jest-dom";
+
+describe("CreateResume Component", () => {
+ const mockReloadResumes = jest.fn();
+ const mockSetResumeDialogOpen = jest.fn();
+ const mockSetNewResumeId = jest.fn();
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+ afterEach(() => {
+ jest.clearAllMocks();
+ });
+ const renderComponent = (resumeToEdit?: Resume) => {
+ render(
+ <CreateResume
+ resumeDialogOpen={true}
+ setResumeDialogOpen={mockSetResumeDialogOpen}
+ resumeToEdit={resumeToEdit}
+ reloadResumes={mockReloadResumes}
+ setNewResumeId={mockSetNewResumeId}
+ />
+ );
+ };
+ it("should render the dialog when resumeDialogOpen is true", () => {
+ renderComponent();
+ expect(screen.getByRole("dialog")).toBeInTheDocument();
+ expect(screen.getByText(/create resume/i)).toBeInTheDocument();
+ });
+
+ it("should display the correct title when editing a resume", () => {
+ const mockResumeToEdit = {
+ id: "resume-id",
+ title: "Test Resume",
+ FileId: "file-id",
+ } as Resume;
+
+ renderComponent(mockResumeToEdit);
+
+ expect(screen.getByText(/edit resume title/i)).toBeInTheDocument();
+
+ const titleInput = screen.getByTestId("resume-title-input");
+ expect(titleInput).toHaveValue("Test Resume");
+ });
+
+ it("should display the correct title when creating a new resume", () => {
+ renderComponent();
+
+ expect(screen.getByText(/create resume/i)).toBeInTheDocument();
+
+ const titleInput = screen.getByTestId("resume-title-input");
+ expect(titleInput).toHaveValue("");
+ });
+
+ it("should call setResumeDialogOpen with false when cancel button is clicked", () => {
+ renderComponent();
+
+ const cancelButton = screen.getByRole("button", { name: /cancel/i });
+
+ fireEvent.click(cancelButton);
+
+ expect(mockSetResumeDialogOpen).toHaveBeenCalledWith(false);
+ });
+
+ it("should display validation errors when form is invalid", async () => {
+ renderComponent();
+
+ const titleInput = screen.getByTestId("resume-title-input");
+ fireEvent.change(titleInput, { target: { value: "Temporary Title" } });
+ fireEvent.change(titleInput, { target: { value: "" } });
+
+ const saveButton = screen.getByRole("button", { name: /save/i });
+ expect(saveButton).toBeDisabled();
+ fireEvent.click(saveButton);
+
+ await waitFor(() => {
+ expect(screen.getByText(/resume title is required/i)).toBeInTheDocument();
+ });
+ });
+});
diff --git a/__tests__/ProfileContainer.spec.tsx b/__tests__/ProfileContainer.spec.tsx
new file mode 100644
index 0000000..fa34690
--- /dev/null
+++ b/__tests__/ProfileContainer.spec.tsx
@@ -0,0 +1,45 @@
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import "@testing-library/jest-dom";
+import ProfileContainer from "@/components/profile/ProfileContainer";
+import React from "react";
+
+jest.mock("@/actions/profile.actions", () => ({
+ getResumeList: jest.fn(() =>
+ Promise.resolve({
+ data: [],
+ total: 0,
+ success: true,
+ message: "",
+ })
+ ),
+}));
+
+describe("ProfileContainer Component", () => {
+ beforeEach(async () => {
+ jest.clearAllMocks();
+ await act(async () => {
+ render(<ProfileContainer />);
+ });
+ });
+
+ afterEach(() => {
+ jest.clearAllMocks();
+ });
+ it("should render the profile container component", () => {
+ expect(screen.getByText(/profile/i)).toBeInTheDocument();
+ });
+
+ it("should open the create resume dialog upon clicking create resume button", async () => {
+ const createResumeButton = screen.getByRole("button", {
+ name: /create resume/i,
+ });
+ await act(async () => {
+ fireEvent.click(createResumeButton);
+ });
+
+ expect(screen.getByRole("dialog")).toBeInTheDocument();
+ expect(
+ screen.getByRole("heading", { level: 2, name: /create resume/i })
+ ).toBeInTheDocument();
+ });
+});
diff --git a/src/components/profile/CreateResume.tsx b/src/components/profile/CreateResume.tsx
index b681150..3a7bdd8 100644
--- a/src/components/profile/CreateResume.tsx
+++ b/src/components/profile/CreateResume.tsx
@@ -133,6 +133,7 @@ function CreateResume({
<Input
{...field}
placeholder="Ex: Full Stack Developer Angular, Java"
+ data-testid="resume-title-input"
/>
</FormControl>
<FormMessage>
diff --git a/src/components/profile/ProfileContainer.tsx b/src/components/profile/ProfileContainer.tsx
index 0fa86b3..842363c 100644
--- a/src/components/profile/ProfileContainer.tsx
+++ b/src/components/profile/ProfileContainer.tsx
@@ -11,7 +11,7 @@ import { toast } from "../ui/use-toast";
import { PlusCircle } from "lucide-react";
import { Button } from "../ui/button";
-function ActivitiesContainer() {
+const ProfileContainer = () => {
const recordsPerPage = APP_CONSTANTS.RECORDS_PER_PAGE;
const [resumes, setResumes] = useState<Resume[]>([]);
@@ -131,6 +131,6 @@ function ActivitiesContainer() {
</CardContent>
</Card>
);
-}
+};
-export default ActivitiesContainer;
+export default ProfileContainer;