Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 218 additions & 0 deletions apps/web/src/components/TodoPanel.browser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import "../index.css";

import { page } from "vitest/browser";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { render } from "vitest-browser-react";
import type { RenderResult } from "vitest-browser-react";

import { Sidebar, SidebarProvider } from "./ui/sidebar";
import { TodoPanel } from "./TodoPanel";
import type { TodoCategory, TodoItem, TodoMutation } from "@t3tools/contracts";

const mockCategories: TodoCategory[] = [
{
id: "cat-1",
name: "Backend",
color: "#3b82f6",
createdAt: "2025-01-01T00:00:00.000Z",
},
{
id: "cat-2",
name: "Frontend",
color: "#ef4444",
createdAt: "2025-01-02T00:00:00.000Z",
},
{
id: "cat-3",
name: "Empty Cat",
color: "#10b981",
createdAt: "2025-01-03T00:00:00.000Z",
},
];

const mockItems: TodoItem[] = [
{
id: "item-1",
categoryId: "cat-1",
title: "Set up database schema",
description: "Design and implement the PostgreSQL schema for user and project tables.",
status: "todo",
sortOrder: 0,
createdAt: "2025-01-01T00:00:00.000Z",
updatedAt: "2025-01-01T00:00:00.000Z",
},
{
id: "item-2",
categoryId: "cat-1",
title: "Add authentication middleware",
description: "Implement JWT-based auth middleware with refresh token support.",
status: "in_progress",
sortOrder: 1,
createdAt: "2025-01-01T00:00:00.000Z",
updatedAt: "2025-01-02T00:00:00.000Z",
},
{
id: "item-3",
categoryId: "cat-2",
title: "Build login page",
status: "done",
sortOrder: 0,
createdAt: "2025-01-01T00:00:00.000Z",
updatedAt: "2025-01-03T00:00:00.000Z",
completedAt: "2025-01-03T00:00:00.000Z",
},
{
id: "item-4",
categoryId: "cat-1",
title: "Add rate limiting",
description: "",
status: "done",
sortOrder: 2,
createdAt: "2025-01-02T00:00:00.000Z",
updatedAt: "2025-01-04T00:00:00.000Z",
completedAt: "2025-01-04T00:00:00.000Z",
},
];

let currentCategories: TodoCategory[];
let currentItems: TodoItem[];

vi.mock("~/hooks/useTodos", () => ({
useTodos: () => ({
get categories() {
return currentCategories;
},
get items() {
return currentItems;
},
loading: false,
error: null,
reload: vi.fn(),
mutate: vi.fn(async (_mutations: TodoMutation[]) => {
return Promise.resolve();
}),
}),
}));

let screen: RenderResult;

beforeEach(async () => {
currentCategories = [...mockCategories];
currentItems = [...mockItems];
document.body.innerHTML = "";
screen = await render(
<SidebarProvider defaultOpen={true}>
<div className="flex-1" />
<Sidebar side="right" collapsible="none">
<TodoPanel />
</Sidebar>
</SidebarProvider>,
);
});

afterEach(async () => {
await screen.unmount();
});

describe("TodoPanel rendering", () => {
it("renders categories, items, and done section", async () => {
await expect.element(page.getByText("Backend").first()).toBeInTheDocument();
await expect.element(page.getByText("Frontend").first()).toBeInTheDocument();
await expect.element(page.getByText("Empty Cat")).toBeInTheDocument();
await expect.element(page.getByText("Set up database schema")).toBeInTheDocument();
await expect.element(page.getByText("Add authentication middleware")).toBeInTheDocument();
await expect.element(page.getByText("Done")).toBeInTheDocument();
await expect.element(page.getByText("Build login page")).toBeInTheDocument();
await expect.element(page.getByText("Add rate limiting")).toBeInTheDocument();
await expect.element(page.getByText("No items").first()).toBeInTheDocument();
});

it("shows empty state when no categories or items", async () => {
currentCategories = [];
currentItems = [];
await screen.rerender(
<SidebarProvider defaultOpen={true}>
<div className="flex-1" />
<Sidebar side="right" collapsible="none">
<TodoPanel />
</Sidebar>
</SidebarProvider>,
);

await expect.element(page.getByText(/No categories yet/)).toBeInTheDocument();
});
});

describe("TodoPanel interactions", () => {
it("hide-empty toggle hides and shows empty categories", async () => {
await expect.element(page.getByText("Empty Cat")).toBeInTheDocument();
await page.getByTitle("Hide empty categories").click();
await expect.element(page.getByText("Empty Cat")).not.toBeInTheDocument();
await page.getByTitle("Show empty categories").click();
await expect.element(page.getByText("Empty Cat")).toBeInTheDocument();
});

it("collapses and expands categories", async () => {
const backendButton = page.getByRole("button", { name: "Backend" });
await expect.element(page.getByText("Set up database schema")).toBeInTheDocument();
await backendButton.click();
await expect.element(page.getByText("Set up database schema")).not.toBeInTheDocument();
await backendButton.click();
await expect.element(page.getByText("Set up database schema")).toBeInTheDocument();
});

it("shows add-item input on category add button", async () => {
await page.getByTitle("Add item").first().click();
await expect.element(page.getByPlaceholder("Item title...")).toBeInTheDocument();
});

it("cycles item status via status button", async () => {
const statusButton = page.getByTitle("Status: todo");
await expect.element(statusButton).toBeVisible();
await statusButton.click();
});

it("cycles done item back to todo via click", async () => {
await page.getByTitle("Click to return to todo").first().click();
});
});

describe("TodoPanel detail panel", () => {
async function openDetail() {
await page.getByText("Set up database schema").click();
await expect.element(page.getByText("Item Detail")).toBeInTheDocument();
}

it("opens and closes detail panel", async () => {
await openDetail();
// Verify the detail panel is actually within the viewport
await expect.element(page.getByText("Item Detail")).toBeVisible();
// Close it
await page.getByText("×").click();
await expect.element(page.getByText("Item Detail")).not.toBeInTheDocument();
});

it("shows item title, description, and category badge in detail panel", async () => {
await openDetail();
await expect
.element(
page.getByText("Design and implement the PostgreSQL schema for user and project tables."),
)
.toBeInTheDocument();
await expect.element(page.getByText("Backend").first()).toBeInTheDocument();
});

it("enters edit mode with textarea and editing indicator", async () => {
await openDetail();
await page
.getByText("Design and implement the PostgreSQL schema for user and project tables.")
.click();
await expect.element(page.getByRole("textbox")).toBeInTheDocument();
await expect.element(page.getByText(/Editing/)).toBeInTheDocument();
});

it("shows placeholder for items without description", async () => {
await page.getByText("Build login page").click();
await expect.element(page.getByText(/Click to add description/)).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion apps/web/src/components/TodoPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ function ItemDetailPanel({
};

return (
<div className="absolute left-full top-0 w-72 h-full border-l border-border bg-card z-10 overflow-y-auto">
<div className="absolute right-full top-0 w-72 h-full border-r border-border bg-card z-10 overflow-y-auto">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep detail panel hidden when the sidebar closes

In the real layout AppSidebarLayout mounts this panel inside a right collapsible="offcanvas" sidebar controlled by todoOpen; when a user opens an item and then closes the Todo sidebar, the sidebar container is shifted right by its own width, but this right-full child is shifted back into the viewport (viewportWidth - 18rem to viewportWidth). That leaves the item detail panel floating over the app even though the Todo sidebar is closed, instead of disappearing with the sidebar.

Useful? React with 👍 / 👎.

<div className="flex items-center gap-2 px-3 py-2 border-b border-border">
<button
onClick={onClose}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/vitest.browser.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default mergeConfig(
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: "chromium" }],
instances: [{ browser: "chromium", viewport: { width: 1400, height: 900 } }],
headless: true,
api: {
strictPort: false,
Expand Down