Files
portifolio-evandrodevbr/lib/whatsapp.paths.test.ts
T

98 lines
2.9 KiB
TypeScript

import {
AI_REVIEW_SUBJECT,
CASES_SUBJECT,
HOME_SUBJECT,
headerOpensWhatsApp,
isServiceOrCasePath,
RESUME_SUBJECT,
SERVICES_SUBJECT,
type WhatsAppContexts,
whatsAppSubjectForPath,
} from "./whatsapp";
/**
* Testes de caminhos-base de whatsAppSubjectForPath e isServiceOrCasePath (complemento de whatsapp.test.ts):
* o case sem tabela de nomes, as duas tabelas independentes, nome vazio e rotas sem slug.
*/
const contexts: WhatsAppContexts = {
services: { "criacao-de-sites": "um site que traz pedidos pelo WhatsApp" },
cases: { "sev-modaintima": "SEV Moda Íntima", vazio: "" },
};
describe("whatsAppSubjectForPath", () => {
it("path: /cases/<id> without contexts -> undefined", () => {
expect(whatsAppSubjectForPath("/cases/sev-modaintima")).toBeUndefined();
expect(
whatsAppSubjectForPath("/cases/sev-modaintima", undefined),
).toBeUndefined();
});
it("path: /ia without contexts and with a trailing slash -> the AI review", () => {
expect(whatsAppSubjectForPath("/ia")).toBe(AI_REVIEW_SUBJECT);
expect(whatsAppSubjectForPath("/ia/", contexts)).toBe(AI_REVIEW_SUBJECT);
});
it("path: a service slug is only looked up in the services, a case id only in the cases", () => {
expect(
whatsAppSubjectForPath("/servicos/sev-modaintima", contexts),
).toBeUndefined();
expect(
whatsAppSubjectForPath("/cases/criacao-de-sites", contexts),
).toBeUndefined();
});
it("path: a case with an empty name -> no subject (the message stays generic)", () => {
expect(whatsAppSubjectForPath("/cases/vazio", contexts)).toBeUndefined();
});
it.each([
"",
"/ia/extra",
"/IA",
"/cases/sev-modaintima/extra",
"/curriculo/extra",
"/servicos/a/b",
])("path: %j -> no subject", (pathname) => {
expect(whatsAppSubjectForPath(pathname, contexts)).toBeUndefined();
});
it.each([
["/servicos/", SERVICES_SUBJECT],
["/cases/", CASES_SUBJECT],
["/curriculo/", RESUME_SUBJECT],
["/", HOME_SUBJECT],
])(
"path: the index page %j (with or without the slash) -> its own subject",
(pathname, subject) => {
expect(whatsAppSubjectForPath(pathname, contexts)).toBe(subject);
expect(whatsAppSubjectForPath(pathname)).toBe(subject);
},
);
});
describe("isServiceOrCasePath", () => {
it.each(["", "/servicos/", "/cases/", "/cases/a/b", "/curriculo", "/ia/"])(
"path: %j -> false",
(pathname) => {
expect(isServiceOrCasePath(pathname)).toBe(false);
},
);
});
describe("headerOpensWhatsApp", () => {
it.each(["", "/servicos/a/b", "/cases/a/b", "/IA", "/curriculo/extra"])(
"path: %j -> false (the header button goes to the home form)",
(pathname) => {
expect(headerOpensWhatsApp(pathname)).toBe(false);
},
);
it.each(["/ia/", "/cases/", "/servicos/", "/curriculo/"])(
"path: the index page %j with the trailing slash -> true",
(pathname) => {
expect(headerOpensWhatsApp(pathname)).toBe(true);
},
);
});