updated tests to align with new logic
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import UpsertAssignment from "@/app/assignment/upsertAssignment";
|
||||
import { CheckSubjectCompletion } from "@/lib/progress";
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
||||
import { router } from "expo-router";
|
||||
@@ -21,13 +20,10 @@ jest.mock("expo-router", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/progress", () => ({
|
||||
CheckSubjectCompletion: jest.fn(() => Promise.resolve()),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/asyncStorage", () => ({
|
||||
GetAssignmentNotificationId: jest.fn(() => Promise.resolve()),
|
||||
SaveAssignmentNotificationId: jest.fn(() => Promise.resolve()),
|
||||
RemoveAssignmentNotificationId: jest.fn(() => Promise.resolve()),
|
||||
}));
|
||||
|
||||
jest.mock("expo-notifications", () => ({
|
||||
@@ -76,7 +72,6 @@ test("creates an assignment and navigates back", async () => {
|
||||
sId: "subject-123",
|
||||
})
|
||||
);
|
||||
expect(CheckSubjectCompletion).toHaveBeenCalledWith("subject-123");
|
||||
expect(router.back).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import ViewDetailsAssignment from "@/app/assignment/viewDetailsAssignment";
|
||||
import { CheckSubjectCompletion } from "@/lib/progress";
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
||||
import { router } from "expo-router";
|
||||
@@ -35,10 +34,6 @@ jest.mock("expo-router", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/progress", () => ({
|
||||
CheckSubjectCompletion: jest.fn(() => Promise.resolve()),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/supabase", () => ({
|
||||
supabase: {
|
||||
auth: {
|
||||
@@ -92,7 +87,7 @@ jest.mock("@/lib/supabase", () => ({
|
||||
|
||||
const alertSpy = jest.spyOn(Alert, "alert");
|
||||
|
||||
test("deletes a task and navigates back", async () => {
|
||||
test("deletes an assignment and navigates back", async () => {
|
||||
mockAssignmentSingle.mockResolvedValue({
|
||||
data: {
|
||||
aId: "assignment-123",
|
||||
@@ -126,16 +121,21 @@ test("deletes a task and navigates back", async () => {
|
||||
expect.any(Array),
|
||||
);
|
||||
|
||||
const alertButtons = alertSpy.mock.calls[0][2];
|
||||
const confirmDeleteButton = alertButtons[1];
|
||||
const alertButtons = alertSpy.mock.calls[0]?.[2];
|
||||
expect(alertButtons).toBeDefined();
|
||||
const confirmDeleteButton = alertButtons?.[1];
|
||||
expect(confirmDeleteButton?.onPress).toBeDefined();
|
||||
|
||||
await confirmDeleteButton.onPress();
|
||||
if (!confirmDeleteButton?.onPress) {
|
||||
throw new Error("Delete confirmation button missing");
|
||||
}
|
||||
|
||||
await confirmDeleteButton.onPress();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(supabase.from).toHaveBeenCalledWith("assignments");
|
||||
expect(mockAssignmentDelete).toHaveBeenCalled();
|
||||
expect(mockAssignmentDeleteEq).toHaveBeenCalledWith("aId", "assignment-123");
|
||||
expect(CheckSubjectCompletion).toHaveBeenCalledWith("subject-123");
|
||||
expect(router.back).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import UpsertAssignment from "@/app/assignment/upsertAssignment";
|
||||
import { CheckSubjectCompletion } from "@/lib/progress";
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
||||
import { router } from "expo-router";
|
||||
@@ -26,12 +25,10 @@ jest.mock("expo-router", () => ({
|
||||
useFocusEffect: (callback: () => void) => callback(),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/progress", () => ({
|
||||
CheckSubjectCompletion: jest.fn(() => Promise.resolve()),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/asyncStorage", () => ({
|
||||
GetAssignmentNotificationId: jest.fn(() => Promise.resolve(null)),
|
||||
SaveAssignmentNotificationId: jest.fn(() => Promise.resolve()),
|
||||
RemoveAssignmentNotificationId: jest.fn(() => Promise.resolve()),
|
||||
}));
|
||||
|
||||
jest.mock("expo-notifications", () => ({
|
||||
@@ -94,7 +91,6 @@ test("updates an assignment and navigates back", async () => {
|
||||
})
|
||||
);
|
||||
expect(mockUpdateSingle).toHaveBeenCalled();
|
||||
expect(CheckSubjectCompletion).toHaveBeenCalledWith("subject-123");
|
||||
expect(router.back).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import TabLayout from "@/app/(tabs)/_layout";
|
||||
import { getSetupStatus } from "@/lib/setupStatus";
|
||||
import { supabase } from "@/lib/supabase";
|
||||
import { render, waitFor } from "@testing-library/react-native";
|
||||
|
||||
@@ -31,6 +32,10 @@ jest.mock("expo-notifications", () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/setupStatus", () => ({
|
||||
getSetupStatus: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock("@/lib/supabase", () => ({
|
||||
supabase: {
|
||||
auth: {
|
||||
@@ -48,6 +53,14 @@ jest.mock("@/lib/supabase", () => ({
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
(getSetupStatus as jest.Mock).mockResolvedValue({
|
||||
subjectId: "subject-123",
|
||||
assignmentId: "assignment-123",
|
||||
taskId: "task-123",
|
||||
completedFocusSessions: 1,
|
||||
currentStep: "sprint",
|
||||
isSetupComplete: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("redirects to login if there is no session", async () => {
|
||||
@@ -76,4 +89,4 @@ test("renders tabs when session exists", async () => {
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("tabs")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,9 @@ import { supabase } from "@/lib/supabase";
|
||||
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
||||
import { router } from "expo-router";
|
||||
|
||||
const mockInsert = jest.fn();
|
||||
const mockSingle = jest.fn();
|
||||
const mockSelect = jest.fn(() => ({ single: mockSingle }));
|
||||
const mockInsert = jest.fn(() => ({ select: mockSelect }));
|
||||
|
||||
jest.mock("expo-router", () => ({
|
||||
router: {
|
||||
@@ -33,7 +35,14 @@ jest.mock("@/lib/supabase", () => ({
|
||||
}));
|
||||
|
||||
test("creates a subject and navigates back", async () => {
|
||||
mockInsert.mockResolvedValue({ error: null });
|
||||
mockSingle.mockResolvedValue({
|
||||
data: {
|
||||
sId: "subject-123",
|
||||
title: "ikt205g26v",
|
||||
uId: "user-123",
|
||||
},
|
||||
error: null,
|
||||
});
|
||||
|
||||
const screen = render(<UpsertSubject />);
|
||||
fireEvent.changeText(screen.getByTestId("subject-title-input"), "ikt205g26v");
|
||||
@@ -47,6 +56,8 @@ test("creates a subject and navigates back", async () => {
|
||||
uId: "user-123",
|
||||
})
|
||||
);
|
||||
expect(mockSelect).toHaveBeenCalled();
|
||||
expect(mockSingle).toHaveBeenCalled();
|
||||
expect(router.back).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,10 +102,16 @@ test("deletes a subject and navigates back", async () => {
|
||||
expect.any(Array),
|
||||
);
|
||||
|
||||
const alertButtons = alertSpy.mock.calls[0][2];
|
||||
const confirmDeleteButton = alertButtons[1];
|
||||
const alertButtons = alertSpy.mock.calls[0]?.[2];
|
||||
expect(alertButtons).toBeDefined();
|
||||
const confirmDeleteButton = alertButtons?.[1];
|
||||
expect(confirmDeleteButton?.onPress).toBeDefined();
|
||||
|
||||
await confirmDeleteButton.onPress();
|
||||
if (!confirmDeleteButton?.onPress) {
|
||||
throw new Error("Delete confirmation button missing");
|
||||
}
|
||||
|
||||
await confirmDeleteButton.onPress();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(supabase.from).toHaveBeenCalledWith("subjects");
|
||||
|
||||
@@ -4,7 +4,9 @@ import { supabase } from "@/lib/supabase";
|
||||
import { fireEvent, render, waitFor } from "@testing-library/react-native";
|
||||
import { router } from "expo-router";
|
||||
|
||||
const mockInsert = jest.fn();
|
||||
const mockSingle = jest.fn();
|
||||
const mockSelect = jest.fn(() => ({ single: mockSingle }));
|
||||
const mockInsert = jest.fn(() => ({ select: mockSelect }));
|
||||
|
||||
jest.mock("expo-router", () => ({
|
||||
router: {
|
||||
@@ -40,7 +42,15 @@ jest.mock("@/lib/supabase", () => ({
|
||||
}));
|
||||
|
||||
test("creates a task and navigates back", async () => {
|
||||
mockInsert.mockResolvedValue({ error: null });
|
||||
mockSingle.mockResolvedValue({
|
||||
data: {
|
||||
tId: "task-123",
|
||||
title: "Read chapter 4",
|
||||
uId: "user-123",
|
||||
aId: "assignment-123",
|
||||
},
|
||||
error: null,
|
||||
});
|
||||
|
||||
const screen = render(<UpsertTask />);
|
||||
fireEvent.changeText(screen.getByTestId("task-title-input"), "Read chapter 4");
|
||||
@@ -55,7 +65,9 @@ test("creates a task and navigates back", async () => {
|
||||
aId: "assignment-123",
|
||||
})
|
||||
);
|
||||
expect(mockSelect).toHaveBeenCalled();
|
||||
expect(mockSingle).toHaveBeenCalled();
|
||||
expect(CheckAssignmentCompletion).toHaveBeenCalledWith("assignment-123");
|
||||
expect(router.back).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,6 +19,12 @@ const mockSubjectSingle = jest.fn();
|
||||
const mockSubjectSelectEq = jest.fn(() => ({ single: mockSubjectSingle }));
|
||||
const mockSubjectSelect = jest.fn(() => ({ eq: mockSubjectSelectEq }));
|
||||
|
||||
const mockSprintSessionsEqCompleted = jest.fn();
|
||||
const mockSprintSessionsEqSessionType = jest.fn(() => ({ eq: mockSprintSessionsEqCompleted }));
|
||||
const mockSprintSessionsEqUser = jest.fn(() => ({ eq: mockSprintSessionsEqSessionType }));
|
||||
const mockSprintSessionsEqTask = jest.fn(() => ({ eq: mockSprintSessionsEqUser }));
|
||||
const mockSprintSessionsSelect = jest.fn(() => ({ eq: mockSprintSessionsEqTask }));
|
||||
|
||||
jest.mock("expo-router", () => ({
|
||||
router: {
|
||||
back: jest.fn(),
|
||||
@@ -86,6 +92,12 @@ jest.mock("@/lib/supabase", () => ({
|
||||
};
|
||||
}
|
||||
|
||||
if (table === "sprint_sessions") {
|
||||
return {
|
||||
select: mockSprintSessionsSelect,
|
||||
};
|
||||
}
|
||||
|
||||
return {};
|
||||
}),
|
||||
},
|
||||
@@ -120,6 +132,7 @@ test("deletes a task and navigates back", async () => {
|
||||
},
|
||||
error: null,
|
||||
});
|
||||
mockSprintSessionsEqCompleted.mockResolvedValue({ count: 0, error: null });
|
||||
mockTaskDeleteEq.mockResolvedValue({ error: null, });
|
||||
|
||||
const screen = render(<ViewDetailsTask />);
|
||||
@@ -127,7 +140,7 @@ test("deletes a task and navigates back", async () => {
|
||||
await screen.findByText("Read chapter 4");
|
||||
await screen.findByText("ikt205g26v");
|
||||
|
||||
fireEvent.press(await screen.findByTestId("delete-task-button"));
|
||||
fireEvent.press(await screen.findByText("Delete"));
|
||||
|
||||
expect(alertSpy).toHaveBeenCalledWith(
|
||||
"Delete Task",
|
||||
@@ -135,10 +148,16 @@ test("deletes a task and navigates back", async () => {
|
||||
expect.any(Array),
|
||||
);
|
||||
|
||||
const alertButtons = alertSpy.mock.calls[0][2];
|
||||
const confirmDeleteButton = alertButtons[1];
|
||||
const alertButtons = alertSpy.mock.calls[0]?.[2];
|
||||
expect(alertButtons).toBeDefined();
|
||||
const confirmDeleteButton = alertButtons?.[1];
|
||||
expect(confirmDeleteButton?.onPress).toBeDefined();
|
||||
|
||||
await confirmDeleteButton.onPress();
|
||||
if (!confirmDeleteButton?.onPress) {
|
||||
throw new Error("Delete confirmation button missing");
|
||||
}
|
||||
|
||||
await confirmDeleteButton.onPress();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(supabase.from).toHaveBeenCalledWith("tasks");
|
||||
|
||||
Reference in New Issue
Block a user