test: remove redundant cases and repeated setup

This commit is contained in:
Amruth Pillai
2026-09-29 23:17:30 +02:00
parent 6cfcdea327
commit 48b27802fd
15 changed files with 106 additions and 322 deletions
@@ -4,21 +4,12 @@ import { fireEvent, render, screen } from "@testing-library/react";
import { beforeAll, describe, expect, it, vi } from "vitest";
import { i18n } from "@lingui/core";
import { I18nProvider } from "@lingui/react";
import { DatesField, readTypedDate } from "./dates-field";
import { DatesField } from "./dates-field";
beforeAll(() => {
i18n.loadAndActivate({ locale: "en-US", messages: {} });
});
describe("readTypedDate", () => {
it.each([
["", null],
["soon", undefined],
])("reads %j as %j", (text, expected) => {
expect(readTypedDate(text, "en-US")).toBe(expected);
});
});
describe("DatesField", () => {
const renderField = (dates: ResumeDates, onChange = vi.fn()) => {
render(
@@ -29,12 +20,20 @@ describe("DatesField", () => {
return onChange;
};
it("saves a typed date and clears the review note", () => {
it("saves and clears readable dates without committing invalid input or the review note", () => {
const onChange = renderField({ start: "2016-06", end: "2018", present: false, raw: "Summer 2016 - 2018" });
expect(screen.getByText(/We read "Summer 2016 - 2018"/)).toBeInTheDocument();
fireEvent.change(screen.getByRole("textbox", { name: "Start" }), { target: { value: "Jul 2016" } });
expect(onChange).toHaveBeenLastCalledWith({ start: "2016-07", end: "2018", present: false });
onChange.mockClear();
fireEvent.change(screen.getByRole("textbox", { name: "Start" }), { target: { value: "" } });
expect(onChange).toHaveBeenCalledWith({ start: null, end: "2018", present: false });
onChange.mockClear();
fireEvent.change(screen.getByRole("textbox", { name: "Start" }), { target: { value: "soon" } });
expect(onChange).not.toHaveBeenCalled();
});
});
@@ -12,7 +12,7 @@ import { cn } from "@reactive-resume/utils/style";
type DateSettings = { locale: string; format?: DateFormat | undefined };
/** What someone typed as a date: a year-month, null when cleared, or undefined when it can't be read. */
export function readTypedDate(text: string, locale: string): YearMonth | null | undefined {
function readTypedDate(text: string, locale: string): YearMonth | null | undefined {
const value = text.trim();
if (!value) return null;
const reading = readSingleDate(value, locale);