import { afterEach, describe, expect, test } from "@rstest/core"; import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { ScheduledTaskScheduleInput, type ScheduleValue, } from "@/components/workspace/scheduled-task-schedule-input"; import { I18nProvider } from "@/core/i18n/context"; afterEach(cleanup); describe("ScheduledTaskScheduleInput", () => { test.each([1, 30, 59])( "preserves an existing %s-second interval until explicitly edited", (everySeconds) => { const emitted: ScheduleValue[] = []; render( emitted.push(value)} /> , ); const amountInput = screen.getByRole("spinbutton"); expect(amountInput.value).toBe(String(everySeconds)); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(everySeconds); fireEvent.focus(amountInput); fireEvent.blur(amountInput); expect(amountInput.value).toBe(String(everySeconds)); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(everySeconds); fireEvent.change(amountInput, { target: { value: "9" } }); expect(amountInput.value).toBe("9"); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(60); fireEvent.blur(amountInput); expect(amountInput.value).toBe("60"); }, ); test("keeps interval text editable until blur applies the floor", () => { const emitted: ScheduleValue[] = []; render( emitted.push(value)} /> , ); const amountInput = screen.getByRole("spinbutton"); expect((amountInput as HTMLInputElement).value).toBe("90"); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(90); fireEvent.change(amountInput, { target: { value: "9" } }); expect((amountInput as HTMLInputElement).value).toBe("9"); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(60); fireEvent.change(amountInput, { target: { value: "" } }); expect((amountInput as HTMLInputElement).value).toBe(""); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(60); fireEvent.blur(amountInput); expect((amountInput as HTMLInputElement).value).toBe("60"); expect(emitted.at(-1)?.schedule_spec.every_seconds).toBe(60); }); });