Files

66 lines
2.4 KiB
TypeScript

// WF-P8 S02 contact cards — which master-data rows a card gets. The row set
// follows the contact type, and unset fields must not become "—" rows, so this
// is worth pinning independently of the screen.
import { describe, expect, it } from "vitest";
import { contactStammdatenRows } from "./projectDetailRoute.server";
import type { ProjektKontaktDetail } from "./projectService.server";
function kontakt(over: Partial<ProjektKontaktDetail> = {}): ProjektKontaktDetail {
return {
id: "pk1",
kontaktId: "c1",
kontaktTyp: "organisation",
rolle: "auftraggeber",
primaer: true,
label: "Weber GmbH",
email: null,
telefon: null,
website: null,
ustIdNr: null,
handelsregister: null,
kundennummer: null,
kundeSeit: null,
branche: null,
mitarbeiterzahl: null,
position: null,
erreichbarkeit: null,
portalInviteEligible: false,
...over,
};
}
describe("contactStammdatenRows", () => {
it("keeps only the company fields that are set, in export order", () => {
const rows = contactStammdatenRows(
kontakt({ website: "https://weber.test", branche: "SHK", mitarbeiterzahl: 24, kundeSeit: new Date("2021-03-04T00:00:00.000Z") })
);
expect(rows).toEqual([
{ labelKey: "projects.detail.contacts.website", value: "https://weber.test" },
{ labelKey: "projects.detail.contacts.customerSince", value: "2021-03-04" },
{ labelKey: "projects.detail.contacts.industry", value: "SHK" },
{ labelKey: "projects.detail.contacts.headcount", value: "24" },
]);
});
it("gives a person the person fields, never the company ones", () => {
const rows = contactStammdatenRows(
kontakt({ kontaktTyp: "privatperson", position: "Einkauf", erreichbarkeit: "Mo-Do", branche: "SHK", ustIdNr: "DE1" })
);
expect(rows).toEqual([
{ labelKey: "projects.detail.contacts.position", value: "Einkauf" },
{ labelKey: "projects.detail.contacts.availability", value: "Mo-Do" },
]);
});
it("drops blank and whitespace-only values instead of rendering empty rows", () => {
expect(contactStammdatenRows(kontakt({ website: " ", branche: "" }))).toEqual([]);
});
it("keeps a headcount of zero, which is a value and not a missing field", () => {
expect(contactStammdatenRows(kontakt({ mitarbeiterzahl: 0 }))).toEqual([
{ labelKey: "projects.detail.contacts.headcount", value: "0" },
]);
});
});