mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
test(vendors): preserve draft on roster load failure
This commit is contained in:
parent
6395905232
commit
8b07015c26
1 changed files with 27 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import type { ReactNode } from "react";
|
||||
import { useController } from "react-hook-form";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const rosterGet = vi.fn();
|
||||
|
|
@ -91,6 +92,32 @@ describe("useVendorRosterForm load-error handling", () => {
|
|||
expect(result.current.selectedCompanyId).toBeNull();
|
||||
});
|
||||
|
||||
it("preserves entered form data when selecting an existing company fetch is rejected", async () => {
|
||||
rosterGet.mockRejectedValueOnce(new Error("Internal server error"));
|
||||
const { result } = renderHook(
|
||||
() => {
|
||||
const form = useVendorRosterForm({ mode: "create" });
|
||||
const name = useController({ control: form.control, name: "name" });
|
||||
return { form, name };
|
||||
},
|
||||
{ wrapper: makeWrapper(createClient()) },
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
result.current.name.field.onChange("Draft Vendor");
|
||||
});
|
||||
expect(result.current.name.field.value).toBe("Draft Vendor");
|
||||
|
||||
await act(async () => {
|
||||
await result.current.form.selectCompany(company);
|
||||
});
|
||||
|
||||
expect(result.current.name.field.value).toBe("Draft Vendor");
|
||||
expect(result.current.form.loadErrorMessage).toBe(
|
||||
"Couldn't load that company's roster. Try again.",
|
||||
);
|
||||
});
|
||||
|
||||
it("recovers and populates the form on retry after a rejected fetch", async () => {
|
||||
rosterGet.mockRejectedValueOnce(new Error("boom"));
|
||||
const { result } = renderHook(() => useVendorRosterForm({ mode: "create" }), {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue