diff --git a/src/__tests__/BerlinClock.test.tsx b/src/__tests__/BerlinClock.test.tsx
index f30e9d2..ff10d83 100644
--- a/src/__tests__/BerlinClock.test.tsx
+++ b/src/__tests__/BerlinClock.test.tsx
@@ -1,54 +1,61 @@
-import { render, screen } from '@testing-library/react';
-import { BerlinClock } from '../containers/BerlinClock';
-import { LampState } from '../types';
+import { render, screen } from "@testing-library/react";
+import { BerlinClock } from "../containers/BerlinClock";
+import { LampState } from "../types";
-describe('BerlinClock', () => {
+describe("BerlinClock", () => {
const testClock = {
secondsRow: [LampState.Y],
fiveHours: [LampState.R, LampState.R, LampState.R, LampState.O],
oneHour: [LampState.R, LampState.R, LampState.R, LampState.R],
fiveMinutes: [
- LampState.Y, LampState.Y, LampState.R,
- LampState.Y, LampState.Y, LampState.R,
- LampState.O, LampState.O, LampState.O,
- LampState.O, LampState.O,
+ LampState.Y,
+ LampState.Y,
+ LampState.R,
+ LampState.Y,
+ LampState.Y,
+ LampState.R,
+ LampState.O,
+ LampState.O,
+ LampState.O,
+ LampState.O,
+ LampState.O,
],
oneMinute: [LampState.O, LampState.O, LampState.O, LampState.O],
};
- it('renders nothing when disabled', () => {
- const { container } = render();
- expect(container.innerHTML).toBe('');
+ it("renders nothing when disabled", () => {
+ const { container } = render(
+ ,
+ );
+ expect(container.innerHTML).toBe("");
});
- it('renders all five rows when enabled', () => {
+ it("renders all five rows when enabled", () => {
render();
- expect(screen.getByTestId('seconds-row')).toBeInTheDocument();
- expect(screen.getByTestId('five-hours-row')).toBeInTheDocument();
- expect(screen.getByTestId('single-hours-row')).toBeInTheDocument();
- expect(screen.getByTestId('five-minutes-row')).toBeInTheDocument();
- expect(screen.getByTestId('single-minutes-row')).toBeInTheDocument();
+ expect(screen.getByTestId("seconds-row")).toBeInTheDocument();
+ expect(screen.getByTestId("five-hours-row")).toBeInTheDocument();
+ expect(screen.getByTestId("single-hours-row")).toBeInTheDocument();
+ expect(screen.getByTestId("five-minutes-row")).toBeInTheDocument();
+ expect(screen.getByTestId("single-minutes-row")).toBeInTheDocument();
});
- it('renders the correct number of lamps in seconds-row', () => {
+ it("renders the correct number of lamps in seconds-row", () => {
render();
- const secRow = screen.getByTestId('seconds-row');
- const lampLine = secRow.querySelector('[data-testid="lamp-line"]');
- expect(lampLine?.children).toHaveLength(1);
+ const secRow = screen.getByTestId("seconds-row");
+ expect(secRow.children).toHaveLength(1);
});
- it('renders the correct number of lamps in five-hours-row', () => {
+ it("renders the correct number of lamps in five-hours-row", () => {
render();
- const row = screen.getByTestId('five-hours-row');
- const lampLine = row.querySelector('[data-testid="lamp-line"]');
- expect(lampLine?.children).toHaveLength(4);
+ const row = screen.getByTestId("five-hours-row");
+ expect(row.children).toHaveLength(4);
});
- it('renders correct aria-labels in the seconds lamp', () => {
+ it("renders correct aria-labels in the seconds lamp", () => {
render();
- const secRow = screen.getByTestId('seconds-row');
- const span = secRow.querySelector('span');
- expect(span).toHaveAttribute('aria-label', 'Y');
+ const secRow = screen.getByTestId("seconds-row");
+ const span = secRow.querySelector("span");
+ expect(span).toHaveAttribute("aria-label", "Y");
});
});
diff --git a/src/__tests__/DigitalClock.test.tsx b/src/__tests__/DigitalClock.test.tsx
index 20e53f5..8c6b710 100644
--- a/src/__tests__/DigitalClock.test.tsx
+++ b/src/__tests__/DigitalClock.test.tsx
@@ -1,20 +1,20 @@
-import { render, screen, fireEvent } from '@testing-library/react';
-import { DigitalClock } from '../containers/DigitalClock';
-import * as utils from '../utils';
+import { render, screen, fireEvent } from "@testing-library/react";
+import { DigitalClock } from "../containers/DigitalClock";
+import * as utils from "../utils";
-vi.mock('../utils');
+vi.mock("../utils");
const mockedDateToDigital = vi.mocked(utils.dateToDigital);
const mockedDigitalToDate = vi.mocked(utils.digitalToDate);
-describe('DigitalClock', () => {
+describe("DigitalClock", () => {
const onTimeChangeMock = vi.fn();
beforeEach(() => {
vi.clearAllMocks();
- mockedDateToDigital.mockReturnValue('14:30:15');
+ mockedDateToDigital.mockReturnValue("14:30:15");
mockedDigitalToDate.mockImplementation((str: string) => {
- const parts = str.split(':');
+ const parts = str.split(":");
if (parts.length !== 3) return new Date(NaN);
const [h, m, s] = parts.map(Number);
if (isNaN(h) || isNaN(m) || isNaN(s)) return new Date(NaN);
@@ -24,58 +24,58 @@ describe('DigitalClock', () => {
});
});
- it('renders nothing when disabled', () => {
+ it("renders nothing when disabled", () => {
const { container } = render(
,
);
- expect(container.innerHTML).toBe('');
+ expect(container.innerHTML).toBe("");
});
- it('renders the digital time and input when enabled', () => {
+ it("renders the digital time and input when enabled", () => {
render(
,
);
- expect(screen.getByTestId('digital-clock')).toHaveTextContent('14:30:15');
- expect(screen.getByTestId('time-input')).toBeInTheDocument();
+ expect(screen.getByTestId("digital-clock")).toHaveTextContent("14:30:15");
+ expect(screen.getByTestId("time-input")).toBeInTheDocument();
});
- it('calls onTimeChange when a valid time is entered', () => {
+ it("calls onTimeChange when a valid time is entered", () => {
render(
,
);
- const input = screen.getByTestId('time-input');
- fireEvent.change(input, { target: { value: '12:00:00' } });
+ const input = screen.getByTestId("time-input");
+ fireEvent.change(input, { target: { value: "12:00:00" } });
expect(onTimeChangeMock).toHaveBeenCalledTimes(1);
const expectedDate = new Date(2025, 0, 1, 12, 0, 0, 0);
expect(onTimeChangeMock).toHaveBeenCalledWith(expectedDate);
- expect(input).toHaveValue('12:00:00');
+ expect(input).toHaveValue("12:00:00");
});
- it('does not call onTimeChange when an invalid time is entered', () => {
+ it("does not call onTimeChange when an invalid time is entered", () => {
render(
,
);
- const input = screen.getByTestId('time-input');
- fireEvent.change(input, { target: { value: 'notatime' } });
+ const input = screen.getByTestId("time-input");
+ fireEvent.change(input, { target: { value: "notatime" } });
expect(onTimeChangeMock).not.toHaveBeenCalled();
- expect(input).toHaveValue('notatime');
+ expect(input).toHaveValue("notatime");
});
});
diff --git a/src/__tests__/Lamp.test.tsx b/src/__tests__/Lamp.test.tsx
index 96495b1..fcb839f 100644
--- a/src/__tests__/Lamp.test.tsx
+++ b/src/__tests__/Lamp.test.tsx
@@ -1,22 +1,22 @@
-import { render } from '@testing-library/react';
-import { Lamp } from '../components/Lamp';
-import { LampState } from '../types';
+import { render } from "@testing-library/react";
+import { Lamp } from "../components/Lamp";
+import { LampState } from "../types";
-describe('Lamp', () => {
- it('renders without crashing', () => {
+describe("Lamp", () => {
+ it("renders without crashing", () => {
render();
// If it doesn't throw, we're good.
});
it.each([
- ['Y' as LampState, 'Y'],
- ['R' as LampState, 'R'],
- ['O' as LampState, 'O'],
- ['N' as LampState, 'N'],
+ ["Y" as LampState, "Y"],
+ ["R" as LampState, "R"],
+ ["O" as LampState, "O"],
+ ["N" as LampState, "N"],
])('displays aria-label "%s" for state %s', (state, expectedLabel) => {
const { container } = render();
// The root element should have the correct aria-label
const lampElement = container.firstChild as HTMLElement;
- expect(lampElement).toHaveAttribute('aria-label', expectedLabel);
+ expect(lampElement).toHaveAttribute("aria-label", expectedLabel);
});
});
diff --git a/src/__tests__/LampLine.test.tsx b/src/__tests__/LampLine.test.tsx
index 77dbec3..7264838 100644
--- a/src/__tests__/LampLine.test.tsx
+++ b/src/__tests__/LampLine.test.tsx
@@ -1,33 +1,33 @@
-import { render, screen } from '@testing-library/react';
-import { LampLine } from '../components/LampLine';
-import { LampState } from '../types';
+import { render, screen } from "@testing-library/react";
+import { LampLine } from "../components/LampLine";
+import { LampState } from "../types";
-describe('LampLine', () => {
- it('renders without crashing', () => {
+describe("LampLine", () => {
+ it("renders without crashing", () => {
render();
});
- it('renders the correct number of lamps', () => {
+ it("renders the correct number of lamps", () => {
const states = [LampState.Y, LampState.R, LampState.O];
render();
- const container = screen.getByTestId('lamp-line');
+ const container = screen.getByTestId("lamp-line");
expect(container.children).toHaveLength(states.length);
});
- it('displays correct aria-labels for each lamp', () => {
+ it("displays correct aria-labels for each lamp", () => {
const states = [LampState.Y, LampState.R, LampState.O, LampState.N];
render();
- const container = screen.getByTestId('lamp-line');
- const lampSpans = container.querySelectorAll('span');
+ const container = screen.getByTestId("lamp-line");
+ const lampSpans = container.querySelectorAll("span");
expect(lampSpans).toHaveLength(states.length);
lampSpans.forEach((span, index) => {
- expect(span).toHaveAttribute('aria-label', states[index]);
+ expect(span).toHaveAttribute("aria-label", states[index]);
});
});
- it('renders no lamps when given an empty array', () => {
+ it("renders no lamps when given an empty array", () => {
render();
- const container = screen.getByTestId('lamp-line');
+ const container = screen.getByTestId("lamp-line");
expect(container.children).toHaveLength(0);
});
});
diff --git a/src/__tests__/TimeConverter.test.tsx b/src/__tests__/TimeConverter.test.tsx
index db0d02b..12198ae 100644
--- a/src/__tests__/TimeConverter.test.tsx
+++ b/src/__tests__/TimeConverter.test.tsx
@@ -1,18 +1,29 @@
-import { render, screen, fireEvent } from '@testing-library/react';
-import { TimeConverter } from '../containers/TimeConverter';
-import { useCurrentTime } from '../hooks/useCurrentTime';
+import { render, screen, fireEvent } from "@testing-library/react";
+import { TimeConverter } from "../containers/TimeConverter";
+import { useCurrentTime } from "../hooks/useCurrentTime";
-vi.mock('../hooks/useCurrentTime');
-vi.mock('../containers/BerlinClock', () => ({
+vi.mock("../hooks/useCurrentTime");
+vi.mock("../containers/BerlinClock", () => ({
BerlinClock: ({ enabled }: { enabled: boolean }) => (
-
{enabled ? 'enabled' : 'disabled'}
+ {enabled ? "enabled" : "disabled"}
),
}));
-vi.mock('../containers/DigitalClock', () => ({
- DigitalClock: ({ enabled, currentTime, onTimeChange }: { enabled: boolean; currentTime: Date; onTimeChange: (d: Date) => void }) => (
+vi.mock("../containers/DigitalClock", () => ({
+ DigitalClock: ({
+ enabled,
+ currentTime,
+ onTimeChange,
+ }: {
+ enabled: boolean;
+ currentTime: Date;
+ onTimeChange: (d: Date) => void;
+ }) => (
{currentTime.toISOString()}
-