import { describe, expect, test } from "bun:test"; import { renderToStaticMarkup } from "react-dom/server"; import { Section, SectionStack } from "./section"; function headingId(html: string): string | undefined { return html.match(/ { test("is labelled by its heading, at the requested level", () => { const html = renderToStaticMarkup(
Running
, ); const id = headingId(html); expect(id).toBeTruthy(); expect(html).toContain(`aria-labelledby="${id}"`); expect(html).toContain(" { const html = renderToStaticMarkup(
Name
, ); expect(html).toContain('data-slot="section" data-variant="group"'); expect(html).toContain('data-slot="section" data-variant="open"'); // Boxed sections are spaced, not ruled. expect(html).toMatch(/data-slot="section-stack" data-variant="group" class="[^"]*gap-8/); }); test("open stacks are divided by hairlines by default", () => { const html = renderToStaticMarkup(
, ); expect(html).toMatch(/data-slot="section-stack"[^>]*divide-y/); }); test("renders no rows container without children, and one with them", () => { expect(renderToStaticMarkup(
)).not.toContain( "section-content", ); const html = renderToStaticMarkup(
Name
, ); expect(html).toMatch(/data-slot="section-content"[^>]*\[&>\*\]:rounded-\[14px\]/); }); test("the title sits one type step above the row labels", () => { const html = renderToStaticMarkup(
, ); expect(html).toMatch(/]*class="[^"]*text-base leading-6 font-semibold/); }); test("puts the action next to the title, centred on the title line", () => { const html = renderToStaticMarkup(
Add to a schedule} />, ); expect(html).toMatch(/data-slot="section-action" class="[^"]*h-6[^"]*items-center/); }); test("on narrow widths the description clears an action that overhangs the title line", () => { const withAction = renderToStaticMarkup(
Add to a schedule} />, ); expect(withAction).toMatch( /data-slot="section-description" class="[^"]*col-span-2 mt-2 @md\/section-header:col-span-1 @md\/section-header:mt-1/, ); const plain = renderToStaticMarkup(
, ); expect(plain).toMatch(/data-slot="section-description" class="[^"]*mt-1/); expect(plain).not.toContain("col-span-2"); }); });