Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
2.3 KB
Raw Blame
// @vitest-environment jsdom

import { useState } from "react";
import { cleanup, fireEvent, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import { renderWithI18n } from "../../test/i18n";
import { BuilderWorkspaceLayout } from "./builder-workspace-layout";

function Editor({ label }: { label: string }) {
  const [value, setValue] = useState("");
  return <textarea aria-label={label} value={value} onChange={(e) => setValue(e.target.value)} />;
}
function mount(width: number) {
  Object.defineProperty(window, "innerWidth", { configurable: true, value: width });
  return renderWithI18n(<BuilderWorkspaceLayout
    conversation={<Editor label="Message" />}
    configuration={<Editor label="Name" />}
    footer={<button>Create agent</button>}
  />);
}

afterEach(cleanup);

describe("responsive builder workspace", () => {
  it.each([320, 390, 767])("shows one pane at %ipx and retains both editors across switches", (width) => {
    mount(width);
    expect(screen.getByRole("tab", { name: "Conversation" })).toHaveAttribute("aria-selected", "true");
    expect(screen.getAllByRole("tabpanel")).toHaveLength(1);
    const message = screen.getByRole("textbox", { name: "Message" });
    fireEvent.change(message, { target: { value: "Unsent message" } });
    fireEvent.click(screen.getByRole("tab", { name: "Agent configuration" }));
    expect(screen.getAllByRole("tabpanel")).toHaveLength(1);
    const name = screen.getByRole("textbox", { name: "Name" });
    fireEvent.change(name, { target: { value: "My agent" } });
    expect(screen.getByRole("button", { name: "Create agent" })).toBeVisible();
    fireEvent.click(screen.getByRole("tab", { name: "Conversation" }));
    expect(screen.getByRole("textbox", { name: "Message" })).toBe(message);
    expect(message).toHaveValue("Unsent message");
    fireEvent.click(screen.getByRole("tab", { name: "Agent configuration" }));
    expect(screen.getByRole("textbox", { name: "Name" })).toBe(name);
    expect(name).toHaveValue("My agent");
  });

  it.each([768, 1280])("retains both desktop panels and the resize handle at %ipx", (width) => {
    const { container } = mount(width);
    expect(screen.queryByRole("tab")).toBeNull();
    expect(screen.getAllByRole("textbox")).toHaveLength(2);
    expect(container.querySelector('[data-slot="resizable-handle"]')).not.toBeNull();
  });
});