summaryrefslogtreecommitdiffhomepage
path: root/src/features/settings/ui/ChatLimitField.test.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-26 22:21:55 +0900
committerAdam Malczewski <[email protected]>2026-06-26 22:23:39 +0900
commitc333fcec32b1f90bf0da6bb14d2609c20e38a74f (patch)
tree0db3ec77a6838c4f800c362df0de3c6cd8544431 /src/features/settings/ui/ChatLimitField.test.ts
parent1285564f12238b22f6b39b9f3fbcecaca8456911 (diff)
downloaddispatch-web-c333fcec32b1f90bf0da6bb14d2609c20e38a74f.tar.gz
dispatch-web-c333fcec32b1f90bf0da6bb14d2609c20e38a74f.zip
style: switch from tabs to 2-space indentation (incl. svelte)
Diffstat (limited to 'src/features/settings/ui/ChatLimitField.test.ts')
-rw-r--r--src/features/settings/ui/ChatLimitField.test.ts128
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");
+ });
});