AI media harness for planning, generating, and editing locally
TypeScript
Project settings: ComboBoxes and sentence-case labels
Bitti456687623e66
diff --git a/src/App.test.tsx b/src/App.test.tsxindex c165cc6..0bdbc8d 100644--- a/src/App.test.tsx+++ b/src/App.test.tsx@@ -5,6 +5,7 @@ import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-liimport { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import App from "./App";import { ProjectCard, relativeDate } from "./components/ProjectCard";+import { chooseOption, comboValue, optionNames } from "./components/workspace/comboTestUtils";import { createProjectConfig, STORY_TRACK_ID } from "./lib/project";describe("how long ago a project was edited", () => {@@ -95,9 +96,9 @@ describe("project library controls", () => {expect(screen.queryByLabelText("Length in seconds")).toBeNull();expect(screen.queryByLabelText("Length slider")).toBeNull();const look = screen.getByRole("combobox", { name: "Look" });- expect(look).toHaveValue("");- fireEvent.change(look, { target: { value: "watercolor" } });- expect(look).toHaveValue("watercolor");+ expect(comboValue(look)).toBe("");+ chooseOption(look, /^watercolor$/i);+ expect(comboValue(look)).toBe("watercolor");expect(screen.getByRole("button", { name: "Create project" })).toBeEnabled();});@@ -188,29 +189,29 @@ describe("project library controls", () => {render(<App />);await screen.findByText("Northern Light — Brand Film");fireEvent.click(screen.getByRole("button", { name: "New project" }));- const shape = screen.getByRole("combobox", { name: /Aspect Ratio/ }) as HTMLSelectElement;- const size = screen.getByRole("combobox", { name: /Resolution/ }) as HTMLSelectElement;+ const shape = screen.getByRole("combobox", { name: "Aspect ratio" });+ const size = screen.getByRole("combobox", { name: "Resolution" });// The ladder the user asked for, in pixels rather than a name for them.- expect([...size.options].map((option) => option.textContent)).toEqual([+ expect(optionNames(size)).toEqual(["736 × 416", "960 × 544", "1152 × 640", "1376 × 768 (default)", "1920 × 1088", "2432 × 1344",]);// Every edge a multiple of 32 — the whole reason the old 720p/1080p/4K// ladder was replaced.- for (const option of [...size.options]) {- const [width, height] = option.textContent!.split(" (")[0].split(" × ").map(Number);+ for (const option of optionNames(size)) {+ const [width, height] = option.split(" (")[0].split(" × ").map(Number);expect([width % 32, height % 32]).toEqual([0, 0]);}/* A frame size is two numbers, and one of them changes with the shape. Theold labels ("1080p HD") could sit above either and say nothing. */- fireEvent.change(shape, { target: { value: "9:16" } });- expect([...size.options].map((option) => option.textContent)).toEqual([+ chooseOption(shape, "Vertical 9:16");+ expect(optionNames(size)).toEqual(["416 × 736", "544 × 960", "640 × 1152", "768 × 1376 (default)", "1088 × 1920", "1344 × 2432",]);- fireEvent.change(size, { target: { value: "544p" } });- expect(size).toHaveValue("544p");+ chooseOption(size, "544 × 960");+ expect(comboValue(size)).toBe("544p");});it("opens a newly named empty project with the agent pane showing", async () => {diff --git a/src/components/ProjectSettings.test.tsx b/src/components/ProjectSettings.test.tsxindex f7e64dc..642bc00 100644--- a/src/components/ProjectSettings.test.tsx+++ b/src/components/ProjectSettings.test.tsx@@ -5,6 +5,7 @@ import { afterEach, expect, it, vi } from "vitest";import { createProjectConfig, type CreateProjectInput, type ProjectRecord } from "../lib/project";import { ProjectWorkspace } from "./ProjectWorkspace";import { PromptComposer } from "./PromptComposer";+import { chooseOption, comboValue } from "./workspace/comboTestUtils";vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));@@ -22,14 +23,14 @@ it("opens settings from the project name, saves both settings mirrors, and restoopener.focus(); fireEvent.click(opener);const dialog = within(screen.getByRole("dialog", { name: "Project settings" }));expect(dialog.getByLabelText("Project name")).toHaveValue("Original");- expect(dialog.getByLabelText("Aspect Ratio")).toHaveValue("16:9");- expect(dialog.getByLabelText("Resolution")).toHaveValue("768p");+ expect(comboValue(dialog.getByLabelText("Aspect ratio"))).toBe("16:9");+ expect(comboValue(dialog.getByLabelText("Resolution"))).toBe("768p");expect(dialog.queryByLabelText("Length in seconds")).not.toBeInTheDocument();fireEvent.change(dialog.getByLabelText("Project name"), { target: { value: "Updated" } });- fireEvent.change(dialog.getByLabelText("Aspect Ratio"), { target: { value: "9:16" } });- fireEvent.change(dialog.getByLabelText("Resolution"), { target: { value: "544p" } });- fireEvent.change(dialog.getByLabelText("Look"), { target: { value: "watercolor" } });- fireEvent.click(dialog.getByRole("button", { name: "Save changes" }));+ chooseOption(dialog.getByLabelText("Aspect ratio"), "Vertical 9:16");+ chooseOption(dialog.getByLabelText("Resolution"), /^544 × 960/);+ chooseOption(dialog.getByLabelText("Look"), /^watercolor$/i);+ fireEvent.click(dialog.getByRole("button", { name: "Save" }));await waitFor(() => expect(screen.queryByRole("dialog", { name: "Project settings" })).not.toBeInTheDocument());const saved = onSave.mock.calls[0][0].config;expect(saved).toMatchObject({ name: "Updated", id: record.config.id,@@ -40,33 +41,33 @@ it("opens settings from the project name, saves both settings mirrors, and restoexpect(saved.generationJobs).toEqual(record.config.generationJobs);expect(opener).toHaveFocus();fireEvent.click(screen.getByRole("button", { name: "Edit project settings for Updated" }));- expect(screen.getByLabelText("Resolution")).toHaveValue("544p");+ expect(comboValue(screen.getByLabelText("Resolution"))).toBe("544p");expect(screen.queryByLabelText("Length in seconds")).not.toBeInTheDocument();- expect(screen.getByLabelText("Look")).toHaveValue("watercolor");+ expect(comboValue(screen.getByLabelText("Look"))).toBe("watercolor");});it("cancels pending edits with Escape without saving", () => {const onSave = vi.fn();render(<ProjectWorkspace project={project()} initialView="references" onBack={vi.fn()} onSave={onSave} />);fireEvent.click(screen.getByRole("button", { name: "Edit project settings for Original" }));- fireEvent.change(screen.getByLabelText("Aspect Ratio"), { target: { value: "1:1" } });+ chooseOption(screen.getByLabelText("Aspect ratio"), "Square 1:1");fireEvent.keyDown(window, { key: "Escape" });expect(screen.queryByRole("dialog", { name: "Project settings" })).not.toBeInTheDocument();expect(onSave).not.toHaveBeenCalled();fireEvent.click(screen.getByRole("button", { name: "Edit project settings for Original" }));- expect(screen.getByLabelText("Aspect Ratio")).toHaveValue("16:9");+ expect(comboValue(screen.getByLabelText("Aspect ratio"))).toBe("16:9");});it("keeps failed saves open for retry", async () => {const onSave = vi.fn().mockRejectedValueOnce(new Error("Disk unavailable")).mockResolvedValue(undefined);render(<ProjectWorkspace project={project()} initialView="references" onBack={vi.fn()} onSave={onSave} />);fireEvent.click(screen.getByRole("button", { name: "Edit project settings for Original" }));- fireEvent.change(screen.getByLabelText("Look"), { target: { value: "watercolor" } });+ chooseOption(screen.getByLabelText("Look"), /^watercolor$/i);const dialog = within(screen.getByRole("dialog", { name: "Project settings" }));- fireEvent.click(dialog.getByRole("button", { name: "Save changes" }));+ fireEvent.click(dialog.getByRole("button", { name: "Save" }));await waitFor(() => expect(dialog.getByRole("alert")).toHaveTextContent("Disk unavailable"));- expect(dialog.getByLabelText("Look")).toHaveValue("watercolor");- fireEvent.click(dialog.getByRole("button", { name: "Save changes" }));+ expect(comboValue(dialog.getByLabelText("Look"))).toBe("watercolor");+ fireEvent.click(dialog.getByRole("button", { name: "Save" }));await waitFor(() => expect(screen.queryByRole("dialog", { name: "Project settings" })).not.toBeInTheDocument());expect(onSave).toHaveBeenCalledTimes(2);});@@ -77,8 +78,8 @@ it("preserves legacy resolution and short project length when opening settings",config.brief.targetDurationSeconds = 5;const onSubmit = vi.fn(async () => undefined);render(<PromptComposer project={config} busy={false} onClose={vi.fn()} onCreate={onSubmit} />);- expect(screen.getByLabelText("Resolution")).toHaveValue("1080p");- fireEvent.click(screen.getByRole("button", { name: "Save changes" }));+ expect(comboValue(screen.getByLabelText("Resolution"))).toBe("1080p");+ fireEvent.click(screen.getByRole("button", { name: "Save" }));expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ resolution: "1080p", targetDurationSeconds: 5 }));});@@ -88,7 +89,7 @@ it.each(["", "claymation"])("creates a project with Look %s and a 60-second timeexpect(screen.queryByLabelText("Length in seconds")).not.toBeInTheDocument();expect(screen.queryByRole("slider")).not.toBeInTheDocument();expect(screen.queryByText("Used by scenes whose Look is set to None.")).not.toBeInTheDocument();- fireEvent.change(screen.getByLabelText("Look"), { target: { value: look } });+ chooseOption(screen.getByLabelText("Look"), look ? new RegExp(`^${look}$`, "i") : "None");fireEvent.click(screen.getByRole("button", { name: "Create project" }));expect(onCreate).toHaveBeenCalledWith(expect.objectContaining({ defaultLook: look || null, targetDurationSeconds: 60 }));expect(createProjectConfig(onCreate.mock.calls[0][0]).settings.defaultLook ?? null).toBe(look || null);@@ -102,7 +103,7 @@ it("preserves an automatically extended project and allows clearing its defaultrender(<PromptComposer project={config} busy={false} onClose={vi.fn()} onCreate={onSubmit} />);expect(screen.queryByRole("slider")).not.toBeInTheDocument();expect(screen.queryByLabelText("Length in seconds")).not.toBeInTheDocument();- fireEvent.change(screen.getByLabelText("Look"), { target: { value: "" } });- fireEvent.click(screen.getByRole("button", { name: "Save changes" }));+ chooseOption(screen.getByLabelText("Look"), "None");+ fireEvent.click(screen.getByRole("button", { name: "Save" }));expect(onSubmit).toHaveBeenCalledWith(expect.objectContaining({ targetDurationSeconds: 730, defaultLook: null }));});diff --git a/src/components/PromptComposer.tsx b/src/components/PromptComposer.tsxindex ceb7105..45366ce 100644--- a/src/components/PromptComposer.tsx+++ b/src/components/PromptComposer.tsx@@ -4,7 +4,7 @@ import { useShortcut } from "../lib/commands";import type { AspectRatio, CreateProjectInput, ProjectConfig, Resolution } from "../lib/project";import { PROJECT_RESOLUTIONS } from "../lib/project";import { SHOT_TAG_GROUPS } from "../lib/shot-tags";-import { ContentDialog, InfoBar, RadioGroup } from "./ui";+import { ComboBox, ContentDialog, InfoBar, RadioGroup } from "./ui";interface PromptComposerProps {busy: boolean;@@ -77,7 +77,7 @@ export function PromptComposer({ busy, onCreate: onSubmit, onClose, project, errreturn (<ContentDialogtitle={project ? "Project settings" : "New project"}- primaryText={project ? (busy ? "Saving…" : "Save changes") : (busy ? "Creating…" : "Create project")}+ primaryText={project ? (busy ? "Saving…" : "Save") : (busy ? "Creating…" : "Create project")}onPrimary={() => void submit()}primaryDisabled={blocked}closeText="Cancel"@@ -119,13 +119,13 @@ export function PromptComposer({ busy, onCreate: onSubmit, onClose, project, err</div><div className="composer__grid"><div className="composer__field">- <label htmlFor={`${id}-aspect`}>Aspect Ratio</label>- <select id={`${id}-aspect`} disabled={busy} value={aspectRatio} onChange={(event) => setAspectRatio(event.target.value as AspectRatio)}>- <option value="16:9">Widescreen 16:9</option>- <option value="9:16">Vertical 9:16</option>- <option value="1:1">Square 1:1</option>- <option value="4:5">Portrait 4:5</option>- </select>+ <label htmlFor={`${id}-aspect`}>Aspect ratio</label>+ <ComboBox<AspectRatio> id={`${id}-aspect`} disabled={busy} value={aspectRatio} onChange={setAspectRatio} options={[+ { value: "16:9", label: "Widescreen 16:9" },+ { value: "9:16", label: "Vertical 9:16" },+ { value: "1:1", label: "Square 1:1" },+ { value: "4:5", label: "Portrait 4:5" },+ ]} /></div>{/* The real pixels, not a name for them. Every rung is a multipleof 32 on both edges — what MiniMax H3 generates at — and they@@ -133,19 +133,17 @@ export function PromptComposer({ busy, onCreate: onSubmit, onClose, project, err1376×768 widescreen and 768×1376 vertical. */}<div className="composer__field"><label htmlFor={`${id}-resolution`}>Resolution</label>- <select id={`${id}-resolution`} disabled={busy} value={resolution} onChange={(event) => setResolution(event.target.value as Resolution)}>- {resolutions.map((option) => {- const { width, height } = outputDimensions(option, aspectRatio);- return <option key={option} value={option}>{width} × {height}{option === DEFAULT_RESOLUTION ? " (default)" : ""}</option>;- })}- </select>+ <ComboBox<Resolution> id={`${id}-resolution`} disabled={busy} value={resolution} onChange={setResolution} options={resolutions.map((option) => {+ const { width, height } = outputDimensions(option, aspectRatio);+ return { value: option, label: `${width} × ${height}${option === DEFAULT_RESOLUTION ? " (default)" : ""}` };+ })} /></div><div className="composer__field"><label htmlFor={`${id}-look`}>Look</label>- <select id={`${id}-look`} aria-label="Look" disabled={busy} value={defaultLook} onChange={(event) => setDefaultLook(event.target.value)}>- <option value="">None</option>- {LOOKS.map((look) => <option key={look.id} value={look.id}>{look.label}</option>)}- </select>+ <ComboBox id={`${id}-look`} disabled={busy} value={defaultLook} onChange={setDefaultLook} options={[+ { value: "", label: "None" },+ ...LOOKS.map((look) => ({ value: look.id, label: look.label })),+ ]} /></div></div>{message && <InfoBar severity="error" title={folderError ? "Choose another folder" : project ? "Couldn’t save" : "Couldn’t create the project"} message={message} />}diff --git a/src/components/workspace/comboTestUtils.ts b/src/components/workspace/comboTestUtils.tsindex 42e6be9..3a734f7 100644--- a/src/components/workspace/comboTestUtils.ts+++ b/src/components/workspace/comboTestUtils.ts@@ -4,12 +4,20 @@works: open it and click the option by its visible name instead. Itscurrent value is on the trigger as `data-value`. */-import { fireEvent, screen } from "@testing-library/react";+import { fireEvent, screen, within } from "@testing-library/react";++/** The open list of `combobox` (its aria-controls), so options elsewhere on+ * the page — a library listbox, another menu — never match. */+const listOf = (combobox: HTMLElement) => {+ const id = combobox.getAttribute("aria-controls");+ const list = id ? document.getElementById(id) : null;+ return list ? within(list) : screen;+};/** Open `combobox` and click the option named `option`. */export function chooseOption(combobox: HTMLElement, option: string | RegExp): void {fireEvent.click(combobox);- fireEvent.click(screen.getByRole("option", { name: option }));+ fireEvent.click(listOf(combobox).getByRole("option", { name: option }));}/** Open the combobox named `name` and click the option named `option`. */@@ -20,7 +28,7 @@ export function choose(name: string | RegExp, option: string | RegExp): void {/** The option labels a combobox offers (opens and closes it). */export function optionNames(combobox: HTMLElement): string[] {fireEvent.click(combobox);- const names = screen.getAllByRole("option").map((option) => option.textContent ?? "");+ const names = listOf(combobox).getAllByRole("option").map((option) => option.textContent ?? "");fireEvent.click(combobox);return names;}