v3: src/components sorted into feature folders, the four largest files split, and the component tests mirror the new layout — 48 components sat in one flat folder, ChatModal ran to 1301 lines, DumpCreateModal to 983, and the tests were grouped by theme, so there was no telling which component had none. Components now live in category/, chat/, comment/, dump/ (with dump/create/ for the new-dump wizard), editor/, form/, layout/ (header, page shell, floating buttons), player/, playlist/, profile/, social/ (vote, like, follow, the who-voted popover) and ui/; FeedTabBar and PresenceRow, used by the index page alone, move to pages/index/. ChatModal gives up ChatMessageItem, PendingItem, ChatEditBox and ReplyRef, the message limits and text helpers (chat/message.ts), the day and clock labels (chat/time.ts) and the draft storage (utils/chatDraft.ts, next to dumpDraft.ts). DumpCreateModal gives up StepIndicator, LocalFilePreview, TitleField and DuplicateNotice; CommentThread gives up CommentForm and CommentNode; TextEditor gives up the emoji picker popup and its skin-tone storage; MediaPlayer gives up its icons (which FilePreview imported from it), Waveform, SeekBar and the remembered volume. NewPlaylistForm, a button that opens a modal holding the form, is NewPlaylistButton now, and Thumbnail, ThumbnailPlaceholder, FilePreview and RichContentCard use named exports like everything else. The tests are split one file per component under src/test/components/<folder>/ (and src/test/pages/index/), the same 625 of them. No behaviour changes; the catalogues only move their source references.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-09-27 19:30:28 +00:00
parent de5abeceb2
commit 07d0344be7
131 changed files with 3893 additions and 3596 deletions

View File

@@ -0,0 +1,39 @@
import { describe, expect, test } from "vitest";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { FeedTabBar } from "../../../pages/index/FeedTabBar.tsx";
import type { Category } from "../../../model.ts";
import { makeCategory, makeSession } from "../../fixtures.ts";
import { currentPath, renderWithContexts } from "../../render.tsx";
const categories: Category[] = [
makeCategory({ id: "c1", slug: "music", name: "Music" }),
makeCategory({ id: "c2", slug: "cinema", name: "Cinema" }),
];
describe("FeedTabBar", () => {
test("guests don't get Followed; tabs navigate within the scope", async () => {
const user = userEvent.setup();
renderWithContexts(<FeedTabBar />, {
route: "/music/hot",
path: "/:categorySlug/:feedTab",
categories,
});
expect(screen.queryByRole("button", { name: "Followed" })).not
.toBeInTheDocument();
expect(screen.getByRole("button", { name: "Hot" })).toHaveClass("active");
await user.click(screen.getByRole("button", { name: "Journal" }));
expect(currentPath()).toBe("/music/journal");
});
test("signed in, Followed is there", () => {
renderWithContexts(<FeedTabBar />, {
session: makeSession(),
route: "/~/followed",
path: "/~/:feedTab",
});
expect(screen.getByRole("button", { name: "Followed" })).toHaveClass(
"active",
);
});
});

View File

@@ -0,0 +1,52 @@
import { describe, expect, test, vi } from "vitest";
import { act, screen } from "@testing-library/react";
import { PresenceRow } from "../../../pages/index/PresenceRow.tsx";
import { renderWithContexts } from "../../render.tsx";
describe("PresenceRow", () => {
const online = (n: number) =>
Array.from({ length: n }, (_, i) => ({
userId: `u${i}`,
username: `user${i}`,
hasAvatar: false,
}));
test("nothing when nobody's online", () => {
renderWithContexts(<PresenceRow />);
expect(document.querySelector(".index-presence")).toBeNull();
});
test("up to six seats, the rest folded into a counter", () => {
renderWithContexts(<PresenceRow />, { ws: { onlineUsers: online(9) } });
expect(screen.getAllByRole("link")).toHaveLength(5);
const more = screen.getByRole("img", { name: /4 more online/ });
expect(more).toHaveTextContent("+4");
expect(more).toHaveAttribute("title", "user5, user6, user7, user8");
});
test("six or fewer all show", () => {
renderWithContexts(<PresenceRow />, { ws: { onlineUsers: online(6) } });
expect(screen.getAllByRole("link")).toHaveLength(6);
expect(screen.queryByText(/^\+/)).not.toBeInTheDocument();
});
test("gives up seats to the tabs beside it, keeping at least an avatar and the counter", () => {
const width = vi.spyOn(HTMLElement.prototype, "clientWidth", "get")
.mockReturnValue(100);
renderWithContexts(
<div className="bar">
<div className="tabs">
<span>a</span>
</div>
<PresenceRow fitWithin=".bar" fitBeside=".tabs" />
</div>,
{ ws: { onlineUsers: online(9) } },
);
expect(screen.getAllByRole("link")).toHaveLength(3);
width.mockReturnValue(0);
act(() => {
globalThis.dispatchEvent(new Event("resize"));
});
width.mockRestore();
});
});