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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user