// Which logo a theme shows when an organization has uploaded one, both, or none: the one rule the // layout, the settings page, the share image and the email all read (contract/logo.ts). import { describe, expect, it } from "vitest" import { logoUrl, resolveLogo, tenantLogo } from "../contract/logo.js" const light = "/acme/brand/logo/light?v=aaaaaaaaaaaaaaaa" const dark = "/acme/brand/logo/dark?v=bbbbbbbbbbbbbbbb" const app = { light: "/app-light.svg", dark: "/app-dark.svg" } describe("the logo an organization shows on a theme", () => { it("is its own when it has one for that theme", () => { const both = { logoLight: light, logoDark: dark } expect(tenantLogo(both, "light")).toEqual({ source: "tenant", variant: "light", path: light }) expect(tenantLogo(both, "dark")).toEqual({ source: "tenant", variant: "dark", path: dark }) }) it("is the only one it has, on both themes", () => { expect(tenantLogo({ logoLight: light, logoDark: null }, "dark")).toEqual({ source: "tenant", variant: "light", path: light, }) expect(tenantLogo({ logoLight: null, logoDark: dark }, "light")).toEqual({ source: "tenant", variant: "dark", path: dark, }) expect(tenantLogo({ logoLight: light, logoDark: null }, "light")?.variant).toBe("light") }) it("is none when it has none", () => { expect(tenantLogo({ logoLight: null, logoDark: null }, "dark")).toBeNull() }) }) describe("the logo a share image or an email shows", () => { it("is the organization's, with the same fallback between its two", () => { expect(resolveLogo({ logoLight: light, logoDark: null }, app, "dark")).toEqual({ source: "tenant", variant: "light", path: light, }) expect(resolveLogo({ logoLight: light, logoDark: dark }, app, "dark")).toEqual({ source: "tenant", variant: "dark", path: dark, }) }) it("is the app brand's own for that theme when the organization has none, or there is no organization", () => { expect(resolveLogo({ logoLight: null, logoDark: null }, app, "dark")).toEqual({ source: "app", variant: "dark", path: "/app-dark.svg", }) expect(resolveLogo(null, app, "light")).toEqual({ source: "app", variant: "light", path: "/app-light.svg" }) }) }) describe("the address of a stored size", () => { it("adds the size after the content tag", () => { expect(logoUrl(light, "1x")).toBe(`${light}&s=1x`) expect(logoUrl("/acme/brand/logo/light", "2x")).toBe("/acme/brand/logo/light?s=2x") }) })