Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/app.$tenant/contacts.new.test.ts
T

58 lines
2.5 KiB
TypeScript

import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
// Same shape as the other route guards here: the action pulls in the CRM
// context, audit and activity writers, so the contract is asserted against the
// source rather than by executing it.
const source = readFileSync(resolve(process.cwd(), "apps/web/app/routes/app.$tenant/contacts.new.tsx"), "utf8");
/** Body of the `intent === "create"` branch, up to the next branch. */
function createBranch(): string {
const start = source.indexOf('if (intent === "create")');
expect(start).toBeGreaterThan(-1);
const end = source.indexOf("throw badRequestResponse();", start);
expect(end).toBeGreaterThan(start);
return source.slice(start, end);
}
describe("contact creation lands back on the list", () => {
it("redirects to the list a contact was created from, not into the new record", () => {
const branch = createBranch();
expect(branch).toContain("companiesPath(tenantSlug)");
expect(branch).toContain("contactsPath(tenantSlug)");
// Creating from the list is usually one of several in a row; a detail page
// would turn the next one into a trip back first.
expect(branch).not.toContain("companyDetailPath");
expect(branch).not.toContain("contactDetailPath");
});
it("keeps the detail links the duplicate check offers", () => {
// The duplicate cards still have to point at the existing records — the
// list redirect must not have taken those with it.
const duplicates = source.slice(source.indexOf("const toCard"), source.indexOf('if (intent === "create")'));
expect(duplicates).toContain("companyDetailPath(tenantSlug, row.id)");
expect(duplicates).toContain("contactDetailPath(tenantSlug, row.id)");
});
it("still audits and logs the creation before answering", () => {
const branch = createBranch();
const audit = branch.indexOf('action: "kontakt.created"');
const activity = branch.indexOf('activityType: "contact_created"');
const answer = branch.indexOf("return redirect(");
expect(audit).toBeGreaterThan(-1);
expect(activity).toBeGreaterThan(audit);
expect(answer).toBeGreaterThan(activity);
});
it("stores a locale-independent activity summary key", () => {
const branch = createBranch();
expect(branch).toContain('summaryText: "crm.activity.contact_created"');
expect(branch).not.toContain('summaryText: t("crm.activity.contact_created")');
expect(branch).not.toContain('summaryText: "Kontakt angelegt"');
});
});