style: format code with single quotes and add Lamp styling
This commit is contained in:
committed by
Loic Coenen (aider)
parent
2c84312947
commit
d8348a64ea
@@ -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(
|
||||
<DigitalClock
|
||||
enabled={false}
|
||||
currentTime={new Date(2025,0,1,14,30,15)}
|
||||
currentTime={new Date(2025, 0, 1, 14, 30, 15)}
|
||||
onTimeChange={onTimeChangeMock}
|
||||
/>,
|
||||
);
|
||||
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(
|
||||
<DigitalClock
|
||||
enabled={true}
|
||||
currentTime={new Date(2025,0,1,14,30,15)}
|
||||
currentTime={new Date(2025, 0, 1, 14, 30, 15)}
|
||||
onTimeChange={onTimeChangeMock}
|
||||
/>,
|
||||
);
|
||||
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(
|
||||
<DigitalClock
|
||||
enabled={true}
|
||||
currentTime={new Date(2025,0,1,14,30,15)}
|
||||
currentTime={new Date(2025, 0, 1, 14, 30, 15)}
|
||||
onTimeChange={onTimeChangeMock}
|
||||
/>,
|
||||
);
|
||||
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(
|
||||
<DigitalClock
|
||||
enabled={true}
|
||||
currentTime={new Date(2025,0,1,14,30,15)}
|
||||
currentTime={new Date(2025, 0, 1, 14, 30, 15)}
|
||||
onTimeChange={onTimeChangeMock}
|
||||
/>,
|
||||
);
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user