Skip to content

Commit

Permalink
pruebas jose
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseCSG committed Jun 13, 2024
1 parent 334e3be commit f583eed
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/FormTextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@ import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";

describe("FormTextInput Component Test", () => {
// José Carlos Sánchez Gómez A01745810 - Test #1/10
it("Should render input", () => {
render(<FormTextInput name="name" type="text" label="Name" />);
expect(screen.getByTestId("name")).toBeInTheDocument();
});

// José Carlos Sánchez Gómez A01745810 - Test #2/10
it("Should render label", () => {
render(<FormTextInput name="name" type="text" label="Name" />);
expect(screen.getByText("Name")).toBeInTheDocument();
});

// José Carlos Sánchez Gómez A01745810 - Test #3/10
it("Should render password input", () => {
render(<FormTextInput name="password" type="password" label="Password" />);
expect(screen.getByTestId("password")).toBeInTheDocument();
});

// José Carlos Sánchez Gómez A01745810 - Test #4/10
it("Should render password label", () => {
render(<FormTextInput name="password" type="password" label="Password" />);
expect(screen.getByText("Password")).toBeInTheDocument();
});
it("Should render password show button", () => {
render(<FormTextInput name="password" type="password" label="Password" />);
expect(screen.getByText("Show")).toBeInTheDocument();
});

// José Carlos Sánchez Gómez A01745810 - Test #5/10
it("Should toggle password input", () => {
render(<FormTextInput name="password" type="password" label="Password" />);
expect(screen.getByText("Show")).toBeInTheDocument();
const input = screen.getByTestId("password") as HTMLInputElement;
const button = screen.getByText("Show");
expect(input.type).toBe("password");
Expand Down
76 changes: 76 additions & 0 deletions test/ProjectCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import ProjectCard from "@/components/ProjectCard";
import { render, screen, waitFor } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";

vi.mock("@/services/project", () => {
return {
getEmployeesInProjectById: vi.fn().mockResolvedValue([
{
id: 1,
name: "Juan",
email: "[email protected]",
jobTitle: "Nada",
department: "Nada",
photoUrl: "",
},
{
id: 2,
name: "Pedro",
email: "[email protected]",
jobTitle: "Nada",
department: "Nada",
photoUrl: "",
},
]),
};
});

describe("ProjectCard Component Test", () => {
// José Carlos Sánchez Gómez A01745810 - Test #7/10
it("Should render the project card", async () => {
const component = await ProjectCard({
id: 1,
name: "Project 1",
date: "2022-01-01",
description: "This is a test project",
});

render(component);
const projectCard = screen.getByTestId(`project-${1}`);
expect(projectCard).toBeInTheDocument();
});

// José Carlos Sánchez Gómez A01745810 - Test #8/10
it("Should render all the coworkers", async () => {
const component = await ProjectCard({
id: 1,
name: "Project 1",
date: "2022-01-01",
description: "This is a test project",
});

render(component);
await waitFor(() => {
const coworkers = screen.getAllByTestId("project-coworker");
expect(coworkers).toHaveLength(2);
});
});

// José Carlos Sánchez Gómez A01745810 - Test #9/10
it("Should render all the properties", async () => {
const component = await ProjectCard({
id: 1,
name: "Project 1",
date: "2022-01-01",
description: "This is a test project",
});

render(component);
const projectName = screen.getByTestId("project-name");
const projectDate = screen.getByTestId("project-date");
const projectDescription = screen.getByTestId("project-description");
expect(projectName).toHaveTextContent("Project 1");
expect(projectDate).toHaveTextContent("2022-01-01");
expect(projectDescription).toHaveTextContent("This is a test project");
});
});
1 change: 1 addition & 0 deletions test/Searchbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from "@testing-library/react";
import { describe, it } from "vitest";

describe("Searchbar Component Test", () => {
// José Carlos Sánchez Gómez A01745810 - Test #10/10
it("Should be rendered on the screen", () => {
render(<SearchBar placeholder="Prueba" />);
});
Expand Down
65 changes: 65 additions & 0 deletions test/services/notifications.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { vi, it, expect, describe } from "vitest";
import { getNotifications } from "@/services/notifications";

// Mock the dependencies

vi.mock("@/auth", () => ({
auth: vi.fn().mockResolvedValue({
user: {
id: "mockUserId",
},
}),
}));

vi.mock("@/db/drizzle", () => ({
default: {
select: vi.fn(() => ({
from: vi.fn().mockReturnThis(),
innerJoin: vi.fn().mockReturnThis(),
leftJoin: vi.fn().mockReturnThis(),
where: vi.fn().mockReturnThis(),
})),
},
}));

vi.mock("@/db/schema", () => ({
finalSurvey: {
id: "mockFinalSurveyId",
scheduledAt: "mockDate",
projectId: "mockProjectId",
processed: false,
},
finalSurveyAnswer: {
finalSurveyId: "mockFinalSurveyId",
userId: "mockUserId",
},
project: { id: "mockProjectId", name: "mockProjectName" },
projectMember: { projectId: "mockProjectId", userId: "mockUserId" },
rulerSurveyAnswers: { userId: "mockUserId", answeredAt: "mockDate" },
sprintSurvey: {
id: "mockSprintSurveyId",
scheduledAt: "mockDate",
projectId: "mockProjectId",
processed: false,
},
sprintSurveyAnswerProject: {
sprintSurveyId: "mockSprintSurveyId",
userId: "mockUserId",
},
}));

vi.mock("drizzle-orm", () => ({
eq: vi.fn(),
and: vi.fn(),
sql: vi.fn(),
gte: vi.fn(),
isNull: vi.fn(),
}));

// José Carlos Sánchez Gómez A01745810 - Test #6/10
describe("getNotifications", () => {
it("should return notifications", async () => {
const notifications = await getNotifications();
expect(notifications).toEqual(expect.any(Array));
});
});

0 comments on commit f583eed

Please sign in to comment.