diff options
| author | Adam Malczewski <[email protected]> | 2026-06-27 01:13:28 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-27 01:13:31 +0900 |
| commit | 2fa03f8d7410c2b8d6be8e10ad088863e83d7177 (patch) | |
| tree | 94e1923180ae38d571d34b578afecb0a18913c24 /src/features/settings/ui/ChatLimitField.test.ts | |
| parent | 80f99665034a0e510300793205c162fc7a46769f (diff) | |
| parent | 08b12478636f4a5c86a1f3c40a843f2906b7c82f (diff) | |
| download | dispatch-web-2fa03f8d7410c2b8d6be8e10ad088863e83d7177.tar.gz dispatch-web-2fa03f8d7410c2b8d6be8e10ad088863e83d7177.zip | |
Merge branch 'dev' into feature/heartbeat
# Conflicts:
# src/app/App.svelte
# src/app/store.svelte.ts
# src/app/store.test.ts
# src/features/workspaces/ui/WorkspaceCard.test.ts
Diffstat (limited to 'src/features/settings/ui/ChatLimitField.test.ts')
| -rw-r--r-- | src/features/settings/ui/ChatLimitField.test.ts | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/src/features/settings/ui/ChatLimitField.test.ts b/src/features/settings/ui/ChatLimitField.test.ts index 73bc449..8f8da25 100644 --- a/src/features/settings/ui/ChatLimitField.test.ts +++ b/src/features/settings/ui/ChatLimitField.test.ts @@ -6,84 +6,84 @@ import ChatLimitField from "./ChatLimitField.svelte"; // A fake save that resolves ok with the value it was given. function fakeSave(): { - saves: number[]; - last: number | null; - impl: (value: number) => Promise<ChatLimitSaveResult>; + saves: number[]; + last: number | null; + impl: (value: number) => Promise<ChatLimitSaveResult>; } { - const saves: number[] = []; - return { - saves, - last: null, - impl: async (value: number) => { - saves.push(value); - return { ok: true, chatLimit: value }; - }, - }; + const saves: number[] = []; + return { + saves, + last: null, + impl: async (value: number) => { + saves.push(value); + return { ok: true, chatLimit: value }; + }, + }; } describe("ChatLimitField", () => { - it("seeds the input from the persisted limit and disables Set while unchanged", () => { - render(ChatLimitField, { props: { chatLimit: 256, save: fakeSave().impl } }); - expect(screen.getByLabelText("Chat limit")).toHaveValue("256"); - expect(screen.getByRole("button", { name: "Set" })).toBeDisabled(); - }); + it("seeds the input from the persisted limit and disables Set while unchanged", () => { + render(ChatLimitField, { props: { chatLimit: 256, save: fakeSave().impl } }); + expect(screen.getByLabelText("Chat limit")).toHaveValue("256"); + expect(screen.getByRole("button", { name: "Set" })).toBeDisabled(); + }); - it("enables Set when the typed value differs (regression: number-binding coercion)", async () => { - const user = userEvent.setup(); - const save = fakeSave(); - render(ChatLimitField, { props: { chatLimit: 256, save: save.impl } }); + it("enables Set when the typed value differs (regression: number-binding coercion)", async () => { + const user = userEvent.setup(); + const save = fakeSave(); + render(ChatLimitField, { props: { chatLimit: 256, save: save.impl } }); - const input = screen.getByLabelText("Chat limit"); - await user.clear(input); - await user.type(input, "10"); + const input = screen.getByLabelText("Chat limit"); + await user.clear(input); + await user.type(input, "10"); - expect(screen.getByRole("button", { name: "Set" })).toBeEnabled(); - }); + expect(screen.getByRole("button", { name: "Set" })).toBeEnabled(); + }); - it("keeps Set disabled for non-numeric input", async () => { - const user = userEvent.setup(); - const save = fakeSave(); - render(ChatLimitField, { props: { chatLimit: 256, save: save.impl } }); + it("keeps Set disabled for non-numeric input", async () => { + const user = userEvent.setup(); + const save = fakeSave(); + render(ChatLimitField, { props: { chatLimit: 256, save: save.impl } }); - const input = screen.getByLabelText("Chat limit"); - await user.clear(input); - await user.type(input, "abc"); + const input = screen.getByLabelText("Chat limit"); + await user.clear(input); + await user.type(input, "abc"); - expect(screen.getByRole("button", { name: "Set" })).toBeDisabled(); - }); + expect(screen.getByRole("button", { name: "Set" })).toBeDisabled(); + }); - it("clicking Set calls save with the parsed value and shows the confirmation", async () => { - const user = userEvent.setup(); - const save = fakeSave(); - const { rerender } = render(ChatLimitField, { - props: { chatLimit: 256, save: save.impl }, - }); + it("clicking Set calls save with the parsed value and shows the confirmation", async () => { + const user = userEvent.setup(); + const save = fakeSave(); + const { rerender } = render(ChatLimitField, { + props: { chatLimit: 256, save: save.impl }, + }); - const input = screen.getByLabelText("Chat limit"); - await user.clear(input); - await user.type(input, "50"); - await user.click(screen.getByRole("button", { name: "Set" })); + const input = screen.getByLabelText("Chat limit"); + await user.clear(input); + await user.type(input, "50"); + await user.click(screen.getByRole("button", { name: "Set" })); - expect(save.saves).toEqual([50]); - // In the real app the reactive `chatLimit` prop updates to the saved value - // (the store sets it synchronously), which clears `dirty` and reveals the - // "Saved" badge. Rerender simulates that propagation. - rerender({ chatLimit: 50, save: save.impl }); - expect(screen.getByText(/Saved/i)).toBeInTheDocument(); - }); + expect(save.saves).toEqual([50]); + // In the real app the reactive `chatLimit` prop updates to the saved value + // (the store sets it synchronously), which clears `dirty` and reveals the + // "Saved" badge. Rerender simulates that propagation. + rerender({ chatLimit: 50, save: save.impl }); + expect(screen.getByText(/Saved/i)).toBeInTheDocument(); + }); - it("clamps a below-floor value when saving", async () => { - const user = userEvent.setup(); - const save = fakeSave(); - render(ChatLimitField, { props: { chatLimit: 256, save: save.impl } }); + it("clamps a below-floor value when saving", async () => { + const user = userEvent.setup(); + const save = fakeSave(); + render(ChatLimitField, { props: { chatLimit: 256, save: save.impl } }); - const input = screen.getByLabelText("Chat limit"); - await user.clear(input); - await user.type(input, "5"); // clamps to MIN (10) - await user.click(screen.getByRole("button", { name: "Set" })); + const input = screen.getByLabelText("Chat limit"); + await user.clear(input); + await user.type(input, "5"); // clamps to MIN (10) + await user.click(screen.getByRole("button", { name: "Set" })); - // The save port receives the clamped value (the view-model clamps before save). - expect(save.saves).toEqual([10]); - expect(input).toHaveValue("10"); - }); + // The save port receives the clamped value (the view-model clamps before save). + expect(save.saves).toEqual([10]); + expect(input).toHaveValue("10"); + }); }); |
