Files
ihasmail/web/src/lib/__tests__/brand.test.ts
T
jcoffey-dev cfcaf5f573 Call the instance what it calls itself, on the page that matters most
APP_NAME is a runtime variable and two of the three places showing the name
ignored it. The sign-in page fetched /api/config, received the name and used
only sourceUrl -- so a rebranded deployment still said "ihasmail" on the one
page a new user meets first. The top bar had it written in. Only the document
title read it, and it had been reading it from the session all along.

The rebranding guide documents both as things to patch yourself, one of them
with "if you change nothing else on this page, change this". It should not
have to.

The sign-in page takes the name from the answer it was already getting. The
top bar takes it from the session, where the title has taken it from since it
was written. Neither is a new request.

One shared default rather than the string written out at three call sites,
because three copies of a default is how two of them end up stale. It stands
if the config request fails, since a sign-in form with no name on it would be
worse than one with the wrong name -- and an empty or non-string name falls
back too, so a deployment that sets APP_NAME= does not get a nameless page.

Confirmed with APP_NAME set to something else: sign-in heading, top bar and
tab title all read it.
2026-09-02 15:24:36 -07:00

41 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { DEFAULT_APP_NAME } from "@/lib/brand";
/*
* The name an instance calls itself.
*
* `APP_NAME` is a runtime variable, so every place showing the name has to ask
* the server rather than have it written in. The sign-in page did not (#236's
* neighbour): it fetched `/api/config`, received the name and used only
* `sourceUrl`, so a rebranded instance still said "ihasmail" on the page a new
* user meets first. These pin the shape of the answer rather than the name.
*/
const nameFrom = (config: { appName?: unknown } | null) =>
config && typeof config.appName === "string" && config.appName.trim() ? config.appName.trim() : DEFAULT_APP_NAME;
describe("resolving the instance name", () => {
it("uses what the server says", () => {
expect(nameFrom({ appName: "Acme Mail" })).toBe("Acme Mail");
});
it("trims it, because a name with an edge of whitespace is a layout bug", () => {
expect(nameFrom({ appName: " Acme Mail " })).toBe("Acme Mail");
});
it("falls back when the request failed", () => {
// A sign-in form with no name on it is worse than one with the wrong name.
expect(nameFrom(null)).toBe(DEFAULT_APP_NAME);
});
it("falls back on a name that is empty or only spaces", () => {
expect(nameFrom({ appName: "" })).toBe(DEFAULT_APP_NAME);
expect(nameFrom({ appName: " " })).toBe(DEFAULT_APP_NAME);
});
it("falls back on a name that is not a string at all", () => {
expect(nameFrom({ appName: 42 })).toBe(DEFAULT_APP_NAME);
expect(nameFrom({})).toBe(DEFAULT_APP_NAME);
});
});