Skip to content

Commit

Permalink
fixed frontend tests and coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cearps committed Oct 6, 2024
1 parent 51d26d7 commit 867f185
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
12 changes: 0 additions & 12 deletions frontend/src/components/kanbans/kanban-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ export default function KanbanDisplay({
});
};

const addComment = (comment: string, taskId: number) => {
TaskAPI.addCommentObservable(kanban.id, taskId, { comment }).subscribe({
next: (comment) => {
console.log("Comment added:", comment);
},
error: (error) => {
console.error("Error adding comment:", error);
},
});
};

const onDragEnd = (result: any) => {
const { destination, source, draggableId } = result;

Expand Down Expand Up @@ -216,7 +205,6 @@ export default function KanbanDisplay({
<DetailedTaskView
task={kanban.tasks.find((task) => task.id === selectedTask)!}
onClose={handleTaskClose}
addComment={addComment}
board={kanban}
onDeleteTask={handleDeleteTask}
/>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/kanbans/kanban-task-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getTaskStatus } from "../../utilities/kanban-category-mapping";
import TaskAPI from "../../api/taskAPI";
import KanbanTaskComment from "./kanban-task-comment";
import Select from "react-select";
import { error } from "console";

const DetailedTaskView = ({
task,
Expand Down
38 changes: 38 additions & 0 deletions frontend/test/api/userAPI.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,42 @@ describe("isAuthenticatedObservable", () => {
expect(localStorage.getItem("token")).toBeNull();
});
});

describe("createUser", () => {
it("should throw an error if the response status is not 200", async () => {
const newUser: NewUserData = {
userTag: "userTag",
email: "new@example.com",
password: "password",
};

const mockErrorResponse = {
data: { description: "User creation failed" },
status: 400,
};

mockedAxios.post.mockResolvedValueOnce(mockErrorResponse);

await expect(UserAPI.createUser(newUser)).rejects.toThrow(
"User creation failed"
);
});
});

describe("loginUser", () => {
it("should throw an error if login fails", async () => {
const loginData = { email: "user@example.com", password: "password" };

const mockErrorResponse = {
data: { description: "Invalid credentials" },
status: 401,
};

mockedAxios.post.mockResolvedValueOnce(mockErrorResponse);

await expect(UserAPI.loginUser(loginData)).rejects.toThrow(
"Invalid credentials"
);
});
});
});
10 changes: 0 additions & 10 deletions frontend/test/components/kanbans/kanban-task-detail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe("DetailedTaskView", () => {
tasks: [mockTask],
};

const addComment = jest.fn();
const onClose = jest.fn();
const onDeleteTask = jest.fn();

Expand All @@ -40,7 +39,6 @@ describe("DetailedTaskView", () => {
<DetailedTaskView
task={mockTask}
board={mockBoard}
addComment={addComment}
onClose={onClose}
onDeleteTask={onDeleteTask}
/>
Expand All @@ -52,7 +50,6 @@ describe("DetailedTaskView", () => {
<DetailedTaskView
task={mockTask}
board={mockBoard}
addComment={addComment}
onClose={onClose}
onDeleteTask={onDeleteTask}
/>
Expand All @@ -65,7 +62,6 @@ describe("DetailedTaskView", () => {
<DetailedTaskView
task={mockTask}
board={mockBoard}
addComment={addComment}
onClose={onClose}
onDeleteTask={onDeleteTask}
/>
Expand All @@ -81,7 +77,6 @@ describe("DetailedTaskView", () => {
<DetailedTaskView
task={mockTask}
board={mockBoard}
addComment={addComment}
onClose={onClose}
onDeleteTask={onDeleteTask}
/>
Expand All @@ -98,7 +93,6 @@ describe("DetailedTaskView", () => {
<DetailedTaskView
task={mockTask}
board={mockBoard}
addComment={addComment}
onClose={onClose}
onDeleteTask={onDeleteTask}
/>
Expand All @@ -113,7 +107,6 @@ describe("DetailedTaskView", () => {
<DetailedTaskView
task={mockTask}
board={mockBoard}
addComment={addComment}
onClose={onClose}
onDeleteTask={onDeleteTask}
/>
Expand All @@ -123,8 +116,6 @@ describe("DetailedTaskView", () => {
screen.getAllByPlaceholderText("Leave a comment...")[0];
fireEvent.change(commentInput, { target: { value: "New Comment" } });
fireEvent.click(screen.getAllByText("Comment")[0]);

expect(addComment).toHaveBeenCalledWith("New Comment", mockTask.id);
});

it("renders without crashing and displays task details", () => {
Expand All @@ -151,7 +142,6 @@ describe("DetailedTaskView", () => {
const commentInput = screen.getByPlaceholderText("Leave a comment...");
fireEvent.change(commentInput, { target: { value: "New comment" } });
fireEvent.click(screen.getByText("Comment"));
expect(addComment).toHaveBeenCalledWith("New comment", mockTask.id);
});

it("does not close when clicking inside the task card", () => {
Expand Down

0 comments on commit 867f185

Please sign in to comment.