mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 06:53:12 +00:00
fix(auth): keep change-password failures inline without a global toast
This commit is contained in:
parent
7fed941435
commit
73090d05e4
2 changed files with 9 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ import type { ChangePasswordPayload } from "@/domain/auth/types/auth-user";
|
|||
export function useChangePassword(): UseMutationResult<unknown, Error, ChangePasswordPayload> {
|
||||
return useMutation({
|
||||
mutationFn: (data: ChangePasswordPayload) => authApi.changePassword(data),
|
||||
meta: { suppressErrorToast: true },
|
||||
onSuccess: () => {
|
||||
toast.success("Password updated");
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { toast } from "react-toastify";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import MyAccountPage from "@/app/(protected)/account";
|
||||
import * as authApi from "@/domain/auth/api/auth-api";
|
||||
import type { AuthUser } from "@/domain/auth/types/auth-user";
|
||||
import { createAppQueryClient } from "@/lib/query/query-client";
|
||||
import { renderWithProviders } from "@/test/test-utils";
|
||||
|
||||
const { toastSuccessMock } = vi.hoisted(() => ({ toastSuccessMock: vi.fn() }));
|
||||
|
|
@ -30,8 +32,12 @@ vi.mock("react-toastify", () => ({
|
|||
toast: { success: toastSuccessMock, error: vi.fn(), info: vi.fn() },
|
||||
}));
|
||||
|
||||
/** Uses the app's query client, so the global mutation error toast is live. */
|
||||
function renderPage() {
|
||||
return renderWithProviders(<MyAccountPage />, { route: "/account" });
|
||||
return renderWithProviders(<MyAccountPage />, {
|
||||
route: "/account",
|
||||
queryClient: createAppQueryClient(),
|
||||
});
|
||||
}
|
||||
|
||||
function field(label: RegExp) {
|
||||
|
|
@ -133,5 +139,6 @@ describe("My Account page", () => {
|
|||
expect(await screen.findByText("Current password is incorrect")).toBeInTheDocument();
|
||||
expect(field(/^current password/i)).toHaveAttribute("aria-invalid", "true");
|
||||
expect(toastSuccessMock).not.toHaveBeenCalled();
|
||||
expect(vi.mocked(toast.error)).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue