feat(features): add test factories to all 5 features
Adds src/__factories__/<entity>.factory.ts to auth, blog, marketing-pages, navigation, media. Each factory uses defineFactory from @repo/core-testing with stable date defaults (2026-01-01) so snapshot diffs reflect SUT behavior only. Refactors mechanical inline-fixture tests to use factories. Also adds vitest.config.ts and tsconfig path alias to @repo/media (lacked both), and adds @repo/core-testing devDependency to @repo/media. Spec: §5.1, §6.3
This commit is contained in:
29
packages/navigation/src/__factories__/header.factory.test.ts
Normal file
29
packages/navigation/src/__factories__/header.factory.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { headerFactory } from "@/__factories__/header.factory";
|
||||
|
||||
describe("headerFactory", () => {
|
||||
beforeEach(() => headerFactory.reset());
|
||||
|
||||
it("returns a Header with stable defaults", () => {
|
||||
const h = headerFactory.build();
|
||||
expect(h.items).toHaveLength(0);
|
||||
expect(h.logoId).toBeUndefined();
|
||||
});
|
||||
|
||||
it("applies overrides", () => {
|
||||
const h = headerFactory.build({
|
||||
logoId: "logo-42",
|
||||
items: [{ label: "Home", href: "/", external: false }],
|
||||
});
|
||||
expect(h.logoId).toBe("logo-42");
|
||||
expect(h.items).toHaveLength(1);
|
||||
expect(h.items[0]?.label).toBe("Home");
|
||||
});
|
||||
|
||||
it("builds multiple headers independently", () => {
|
||||
const a = headerFactory.build({ items: [{ label: "A", href: "/a", external: false }] });
|
||||
const b = headerFactory.build({ items: [] });
|
||||
expect(a.items).toHaveLength(1);
|
||||
expect(b.items).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
6
packages/navigation/src/__factories__/header.factory.ts
Normal file
6
packages/navigation/src/__factories__/header.factory.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { defineFactory } from "@repo/core-testing/factory";
|
||||
import type { Header } from "../entities/header.js";
|
||||
|
||||
export const headerFactory = defineFactory<Header>(() => ({
|
||||
items: [],
|
||||
}));
|
||||
1
packages/navigation/src/__factories__/index.ts
Normal file
1
packages/navigation/src/__factories__/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { headerFactory } from "./header.factory.js";
|
||||
Reference in New Issue
Block a user