Files
Reactive-Resume/apps/web/src/libs/resume/make-section-item.test.ts
T
Amruth Pillai 6a01207b6b test: add unit and component tests across the monorepo
Adds ~1000 tests to bring the previously-untested packages and apps
under coverage:

- packages/utils — string, color, date, file, level, locale, sanitize,
  field, html, network-icons, rate-limit, url, url-security, monorepo,
  resume/patch, resume/docx/link-utils, style helpers (~97% on the
  testable utility files)
- packages/ui — 28 component test files plus the use-controlled-state,
  use-mobile, use-confirm, use-prompt hooks (95% statements)
- packages/pdf — shared template helpers (filtering, columns, picture,
  metrics, section-links, page-size, rich-text-html, section-title)
- packages/schema — resumeDataSchema, page, templates, default
- packages/fonts — expanded coverage on font helpers
- packages/ai — resume sanitize and extraction template
- packages/api — resume-access-policy
- apps/web — error-message, locale, theme, pwa, dialogs/store, and
  the resume/move-item / section-actions / make-section-item helpers

Adds jsdom polyfills (ResizeObserver, IntersectionObserver,
scrollIntoView, matchMedia) and an explicit React Testing Library
cleanup hook to vitest.setup.ts so portal- and overlay-based components
work without per-test setup.
2026-05-10 20:00:07 +02:00

51 lines
1.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { makeSectionItem } from "./make-section-item";
describe("makeSectionItem", () => {
it("clones the provided item but generates a fresh id", () => {
const original = { id: "original-id", name: "Skill" };
const result = makeSectionItem({ id: "default", name: "" }, original);
expect(result.name).toBe("Skill");
expect(result.id).not.toBe("original-id");
expect(result.id.length).toBeGreaterThan(0);
});
it("uses defaultItem when no item is provided", () => {
const defaultItem = { id: "default", name: "", level: 0 };
const result = makeSectionItem(defaultItem);
expect(result.name).toBe("");
expect(result.level).toBe(0);
expect(result.id).not.toBe("default");
});
it("does not mutate the input item when duplicating", () => {
const original = { id: "original-id", value: "test" };
const before = JSON.stringify(original);
makeSectionItem({ id: "default", value: "" }, original);
expect(JSON.stringify(original)).toBe(before);
});
it("does not mutate the defaultItem", () => {
const defaultItem = { id: "default", value: "x" };
const before = JSON.stringify(defaultItem);
makeSectionItem(defaultItem);
expect(JSON.stringify(defaultItem)).toBe(before);
});
it("generates a unique id per call", () => {
const a = makeSectionItem({ id: "default", name: "" });
const b = makeSectionItem({ id: "default", name: "" });
expect(a.id).not.toBe(b.id);
});
it("preserves all other fields when duplicating", () => {
const item = { id: "x", a: 1, b: { c: 2 }, d: [3] };
const result = makeSectionItem({ id: "default", a: 0, b: { c: 0 }, d: [] }, item);
expect(result.a).toBe(1);
expect(result.b).toEqual({ c: 2 });
expect(result.d).toEqual([3]);
});
});