The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { render } from "../../../test/render"; |
| 2 | import { |
| 3 | DEFAULT_SNOOZE_PRESETS, |
| 4 | DEFAULT_UNIFIED_SETTINGS, |
| 5 | MAX_SNOOZE_PRESETS, |
| 6 | type SnoozePresetSetting, |
| 7 | } from "@t3tools/contracts/settings"; |
| 8 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 9 | import { page, userEvent } from "vite-plus/test/browser"; |
| 10 | |
| 11 | import "../../index.css"; |
| 12 | import type { ScopedSettingsPatch } from "./scopedSettings"; |
| 13 | |
| 14 | const state = vi.hoisted(() => ({ |
| 15 | presets: [] as ReadonlyArray<SnoozePresetSetting>, |
| 16 | updateSettings: vi.fn<(patch: ScopedSettingsPatch) => void>(), |
| 17 | })); |
| 18 | |
| 19 | vi.mock(import("./useScopedSettings"), async (original) => ({ |
| 20 | ...(await original()), |
| 21 | useScopedSettings: (() => ({ |
| 22 | ...DEFAULT_UNIFIED_SETTINGS, |
| 23 | snoozePresets: state.presets, |
| 24 | })) as never, |
| 25 | useScopedSettingsMixed: () => false, |
| 26 | useUpdateScopedSettings: () => state.updateSettings, |
| 27 | })); |
| 28 | vi.mock(import("./settingsLayout"), async (original) => ({ |
| 29 | ...(await original()), |
| 30 | SettingsRow: ({ children }) => <div>{children}</div>, |
| 31 | })); |
| 32 | |
| 33 | import { SnoozePresetsRow } from "./SnoozePresetsSettings"; |
| 34 | |
| 35 | describe("SnoozePresetsRow", () => { |
| 36 | it("keeps the option that fills the list at the bottom until focus leaves", async () => { |
| 37 | // One short of the limit; the next option offered is "In 30 minutes", which sorts first. |
| 38 | state.presets = [ |
| 39 | ...DEFAULT_SNOOZE_PRESETS, |
| 40 | { kind: "at", day: "saturday", time: "09:00" }, |
| 41 | { kind: "after", minutes: 24 * 60 }, |
| 42 | ]; |
| 43 | expect(state.presets).toHaveLength(MAX_SNOOZE_PRESETS - 1); |
| 44 | // The row reads no route state. |
| 45 | await using screen = await render(<SnoozePresetsRow />, { router: false }); |
| 46 | state.updateSettings.mockReset().mockImplementation((patch) => { |
| 47 | state.presets = patch.snoozePresets ?? state.presets; |
| 48 | void screen.rerender(<SnoozePresetsRow />); |
| 49 | }); |
| 50 | |
| 51 | const add = page.getByRole("button", { name: "Add option" }); |
| 52 | await userEvent.click(add); |
| 53 | |
| 54 | // A disabled button drops focus, which the list reads as leaving it and sorts mid-edit. |
| 55 | await expect.element(add).toHaveFocus(); |
| 56 | await expect.element(add).toHaveAttribute("aria-disabled", "true"); |
| 57 | const added = page.getByRole("group", { name: `Snooze option ${MAX_SNOOZE_PRESETS}` }); |
| 58 | await expect.element(added.getByRole("textbox", { name: "Amount" })).toHaveValue("30"); |
| 59 | }); |
| 60 | }); |