test.web/presentation/renderers/page.shell.renderer.test.ts
test.web/presentation/renderers/page.shell.renderer.test.ts is a file in Codebase Testing. 69 lines of code and 0 definitions.
import "@banes-lab/web/presentation/records/home.record.ts";
import "@banes-lab/web/presentation/records/grammar.record.ts";
import { GRAMMAR_PAGE, HOME_PAGE } from "@banes-lab/web/core/ids/page.ids.ts";
import { HOME_PATH, tabLink } from "@banes-lab/web/core/assets/link.assets.ts";
import { describe, expect, it } from "vitest";
import { loadPage, loadedPage } from "@banes-lab/web/domain/registries/page.registry.ts";
import {
renderPage,
renderStaticPage,
renderStaticSection,
} from "@banes-lab/web/presentation/renderers/page.shell.renderer.ts";
import { COPY_PAGE_TITLE } from "@banes-lab/web/configuration/strings/clipboard.strings.ts";
import { GRAMMAR_TABS } from "@banes-lab/web/core/generated/grammar.page.generated.ts";
import { MISSING_PAGE_TITLE } from "@banes-lab/web/configuration/strings/page.strings.ts";
import { STATIC_RENDER_ATTRIBUTE } from "@banes-lab/web/configuration/constants/document.constants.ts";
import { exportText } from "@banes-lab/web/core/converters/text.converter.ts";
import { isStaticRender } from "@banes-lab/web/core/predicates/document.predicate.ts";
await loadPage(HOME_PAGE);
await loadPage(GRAMMAR_PAGE);
const UNKNOWN = "no-such-page";
const CONTENT_CLASS = "page-content";
const FOOTER_CLASS = "site-footer";
const LICENSE_SELECTOR = ".site-license";
const HOME_CLASS = "home-content";
const COPY_SELECTOR = ".copy-all";
describe("renderPage", () => {
it("wraps a registered page in the content shell followed by the site footer", () => {
const [content, footer] = renderPage(HOME_PAGE);
expect(content?.classList.contains(CONTENT_CLASS)).toBe(true);
expect(content?.querySelector(`.${HOME_CLASS}`)).not.toBeNull();
expect(footer?.classList.contains(FOOTER_CLASS)).toBe(true);
});
it("gives the footer the license notice only of a page that declares one", () => {
const [, home] = renderPage(HOME_PAGE);
const [, grammar] = renderPage(GRAMMAR_PAGE);
expect(home?.querySelector(LICENSE_SELECTOR)).toBeNull();
expect(grammar?.querySelector(LICENSE_SELECTOR)?.textContent).toContain(loadedPage(GRAMMAR_PAGE)?.license?.name);
});
it("gives every page, tabbed or not, one copy button that is kept out of the text it copies", () => {
for (const page of [HOME_PAGE, GRAMMAR_PAGE]) {
const [content] = renderPage(page);
const buttons = content?.querySelectorAll(COPY_SELECTOR) ?? [];
expect(buttons).toHaveLength(1);
expect(buttons[0]?.getAttribute("title")).toBe(COPY_PAGE_TITLE);
expect(content === undefined ? "" : exportText(content)).not.toContain(COPY_PAGE_TITLE);
}
});
it("renders the missing page with a link home for an unknown id", () => {
const [content] = renderPage(UNKNOWN);
expect(content?.textContent).toContain(MISSING_PAGE_TITLE);
expect(content?.querySelector("a")?.getAttribute("href")).toBe(HOME_PATH);
});
});
describe("renderStaticPage, renderStaticSection and isStaticRender", () => {
it("marks the document as a static render only for the duration of the render", () => {
expect(isStaticRender()).toBe(false);
const [content] = renderStaticPage(HOME_PAGE);
expect(content?.classList.contains(CONTENT_CLASS)).toBe(true);
expect(isStaticRender()).toBe(false);
expect(document.documentElement.hasAttribute(STATIC_RENDER_ATTRIBUTE)).toBe(false);
});
it("draws no section of its own for a document page or a tab whose view holds its sections", () => {
const [first] = GRAMMAR_TABS;
const grammarPath = tabLink(GRAMMAR_PAGE, first?.id ?? "");
expect(renderStaticSection(HOME_PAGE, HOME_PATH, "anything")).toBeNull();
expect(renderStaticSection(GRAMMAR_PAGE, grammarPath, first?.sections[0]?.id ?? "")).toBeNull();
expect(isStaticRender()).toBe(false);
});
});