Open History to see the last commit
1import type { ProjectScript, ResolvedKeybindingsConfig } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4
5import ProjectScriptsControl from "./ProjectScriptsControl";
6
7const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = [];
8const PRIMARY_SCRIPT: ProjectScript = {
9 id: "dev",
10 name: "Dev",
11 command: "vp dev",
12 icon: "play",
13 runOnWorktreeCreate: false,
14};
15
16function renderControl(scripts: ReadonlyArray<ProjectScript>) {
17 return renderToStaticMarkup(
18 <ProjectScriptsControl
19 scripts={scripts}
20 keybindings={EMPTY_KEYBINDINGS}
21 onRunScript={() => {}}
22 onAddScript={async () => undefined as never}
23 onUpdateScript={async () => undefined as never}
24 onDeleteScript={async () => undefined as never}
25 />,
26 );
27}
28
29function buttonTag(html: string, ariaLabel: string) {
30 return html.match(new RegExp(`<button[^>]*aria-label="${ariaLabel}"[^>]*>`))?.[0];
31}
32
33function expectResponsiveXsControl(markup: string | undefined) {
34 expect(markup).toBeDefined();
35 expect(markup).toContain("h-7");
36 expect(markup).toContain("gap-1");
37 expect(markup).toContain("text-sm");
38 expect(markup).toContain("sm:h-6");
39 expect(markup).toContain("sm:text-xs");
40 expect(markup).toContain("w-7");
41 expect(markup).toContain("px-0");
42 expect(markup).toContain("sm:w-6");
43 expect(markup).toContain("@3xl/header-actions:w-auto!");
44 expect(markup).toContain("@3xl/header-actions:px-[calc(--spacing(2)-1px)]");
45}
46
47describe("ProjectScriptsControl compact controls", () => {
48 it("keeps the primary Run control compact and expands it with its label", () => {
49 const html = renderControl([PRIMARY_SCRIPT]);
50
51 expectResponsiveXsControl(buttonTag(html, "Run Dev"));
52 expect(html).toContain(
53 'class="sr-only @3xl/header-actions:not-sr-only @3xl/header-actions:ml-0.5"',
54 );
55 });
56
57 it("keeps the standalone Add control compact and expands it with its label", () => {
58 const html = renderControl([]);
59
60 expectResponsiveXsControl(buttonTag(html, "Add action"));
61 expect(html).toContain(
62 'class="sr-only @3xl/header-actions:not-sr-only @3xl/header-actions:ml-0.5"',
63 );
64 });
65});