Validate daily schedule start times
Disable schedule activation until the local time input matches a strict HH:MM value. Keep a defensive activation guard that surfaces a localized validation error and skips persistence when invoked with invalid state. Add red-green coverage for empty, malformed, out-of-range hour, and out-of-range minute values.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { RendererSettings, UiSnapshot } from "../src/shared/types";
|
||||
import {
|
||||
activateDailyScheduleSettings,
|
||||
buildDailyScheduleSettingsUpdate,
|
||||
persistDailyScheduleSettingsUpdate
|
||||
} from "../src/renderer/App";
|
||||
@@ -21,6 +22,22 @@ describe("daily schedule settings form", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["", "8:15", "24:00", "12:60"])("reports the invalid time %j when activation is invoked directly", async (time) => {
|
||||
const persist = vi.fn();
|
||||
const showError = vi.fn();
|
||||
|
||||
await expect(activateDailyScheduleSettings(
|
||||
time,
|
||||
"today",
|
||||
persist,
|
||||
showError,
|
||||
new Date(2026, 7, 22, 18, 30, 0, 0)
|
||||
)).resolves.toBe(false);
|
||||
|
||||
expect(showError).toHaveBeenCalledWith("Bitte eine gültige Startzeit auswählen.");
|
||||
expect(persist).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("applies persisted settings after a successful activation", async () => {
|
||||
const persisted = { dailyStartEnabled: true } as RendererSettings;
|
||||
const updateSettings = vi.fn().mockResolvedValue(persisted);
|
||||
|
||||
Reference in New Issue
Block a user