import { CONTACT_KIND_PARAM, CONTACT_KINDS, CONTACT_SUBJECT_OPTIONS, contactKindHref, contactSubjectForKind, DEFAULT_CONTACT_SUBJECT, } from "./contact-subject"; describe("contact-subject", () => { it("starts the options with the default, 'Ainda preciso definir', so nobody is pushed into a type", () => { expect(CONTACT_SUBJECT_OPTIONS[0]).toBe(DEFAULT_CONTACT_SUBJECT); expect(DEFAULT_CONTACT_SUBJECT).toBe("Ainda preciso definir"); }); it("maps every type an offer asks for to an option of the form", () => { for (const subject of Object.values(CONTACT_KINDS)) { expect(CONTACT_SUBJECT_OPTIONS).toContain(subject); } expect(CONTACT_KINDS).toEqual({ site: "Site para empresa", sistema: "Sistemas web sob medida", revisao: "Revisão ou diagnóstico de sistema", }); }); it("looks a type up by its own keys only", () => { expect(contactSubjectForKind("site")).toBe("Site para empresa"); expect(contactSubjectForKind("revisao")).toBe( "Revisão ou diagnóstico de sistema", ); for (const unknown of [ "", "Site", "constructor", "toString", "__proto__", ]) { expect(contactSubjectForKind(unknown)).toBeUndefined(); } expect(contactSubjectForKind(null)).toBeUndefined(); expect(contactSubjectForKind(undefined)).toBeUndefined(); }); it("builds the address with the type in the search, before the fragment, so #contact still finds the section", () => { expect(contactKindHref("site")).toBe( `/?${CONTACT_KIND_PARAM}=site#contact`, ); for (const kind of Object.keys(CONTACT_KINDS) as Array< keyof typeof CONTACT_KINDS >) { const url = new URL(contactKindHref(kind), "https://example.com"); expect(url.hash).toBe("#contact"); expect(url.searchParams.get("tipo")).toBe(kind); expect(url.pathname).toBe("/"); } }); });