+ );
+ },
}));
const mockedUseCurrentTime = vi.mocked(useCurrentTime);
@@ -72,12 +65,10 @@ describe("TimeConverter", () => {
expect(screen.getByTestId("berlin-clock")).toHaveTextContent("enabled");
});
- it("calls setCurrentTime when DigitalClock triggers onTimeChange", () => {
+ it("renders the digital clock input with the correct initial value", () => {
render();
- fireEvent.click(screen.getByTestId("set-time"));
- expect(setCurrentTimeMock).toHaveBeenCalledWith(
- new Date(2025, 0, 1, 12, 0, 0),
- );
+ const input = screen.getByTestId("time-input") as HTMLInputElement;
+ expect(input.value).toBe("14:30:15");
});
// ──────────────────────────────────────────────────────────
@@ -101,22 +92,18 @@ describe("TimeConverter", () => {
render();
- // Initially the digital clock shows the manual time 12:00:00
- expect(screen.getByTestId("digital-clock-time")).toHaveTextContent(
- new Date(2025, 0, 1, 12, 0, 0).toISOString(),
- );
+ // Initially the digital clock input shows the manual time 12:00:00
+ const input = screen.getByTestId("time-input") as HTMLInputElement;
+ expect(input.value).toBe("12:00:00");
// Click the "Use system time" checkbox
fireEvent.click(screen.getByTestId("use-system-time"));
- // The component SHOULD have called setCurrentDate with the system time
- // (currently it does NOT, so this assertion fails)
+ // The component should have called setCurrentDate with the system time
expect(setCurrentDate).toHaveBeenCalledWith(new Date(2025, 0, 1, 15, 0, 0));
- // And the digital clock should now show the system time 15:00:00
- expect(screen.getByTestId("digital-clock-time")).toHaveTextContent(
- new Date(2025, 0, 1, 15, 0, 0).toISOString(),
- );
+ // And the input should now show the system time 15:00:00
+ expect(input.value).toBe("15:00:00");
vi.useRealTimers();
});
diff --git a/src/containers/DigitalClock.tsx b/src/containers/DigitalClock.tsx
index 55f60bb..fd2d2c9 100644
--- a/src/containers/DigitalClock.tsx
+++ b/src/containers/DigitalClock.tsx
@@ -25,7 +25,6 @@ export function DigitalClock({
return (