feat(webui): refine day-night themes and interaction continuity
This commit is contained in:
1 parent
12c7d116a0
commit
e8544a79a6
32 files changed
+613
-29
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { createPortal } from "react-dom";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { ComposerUsagePopover } from "@/components/thread/ComposerUsagePopover";
|
||||
import type { ContextSnapshot } from "@/lib/types";
|
||||
|
||||
@@ -66,13 +66,19 @@ describe("Context sidebar", () => {
|
||||
expect(screen.getByRole("complementary")).toBe(sidebar);
|
||||
expect(within(sidebar).getByRole("progressbar")).toHaveAttribute("aria-valuenow", "10");
|
||||
expect(within(footer).getByTestId("composer-context-usage")).toHaveAttribute("aria-expanded", "true");
|
||||
// happy-dom has no CSS timeline; model the real surface exit for this interruption.
|
||||
let finishExit!: () => void;
|
||||
const finished = new Promise<void>((resolve) => { finishExit = resolve; });
|
||||
Object.defineProperty(sidebar, "getAnimations", { value: vi.fn(() => [{ finished }]) });
|
||||
await user.click(within(footer).getByTestId("composer-context-usage"));
|
||||
expect(screen.getByRole("complementary")).toBe(sidebar);
|
||||
expect(sidebar).toBeInTheDocument();
|
||||
expect(sidebar).toHaveAttribute("inert");
|
||||
expect(sidebar.style.getPropertyValue("--file-preview-slot-width")).toBe("0px");
|
||||
// Reopening during exit retains the graph instead of remounting it.
|
||||
await user.click(within(footer).getByTestId("composer-context-usage"));
|
||||
expect(screen.getByRole("complementary")).toBe(sidebar);
|
||||
await user.click(within(footer).getByTestId("composer-context-usage"));
|
||||
await act(async () => finishExit());
|
||||
await waitFor(() => expect(screen.queryByRole("complementary")).not.toBeInTheDocument());
|
||||
view.unmount(); toolbar.remove(); footer.remove();
|
||||
});
|
||||
|
||||
@@ -241,6 +241,26 @@ describe("Settings overview and appearance", () => {
|
||||
expect(readLocalPreferences().customReadingTextSize).toBe(22);
|
||||
});
|
||||
|
||||
it("keeps an invalid Enter edit focused until corrected or cancelled", async () => {
|
||||
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, readingTextSize: "custom" });
|
||||
renderSettingsView({ initialSection: "appearance", initialSettings: settingsPayload() });
|
||||
const input = screen.getByRole("spinbutton", { name: "Custom text size" });
|
||||
act(() => input.focus());
|
||||
fireEvent.change(input, { target: { value: "40" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(input).toHaveFocus();
|
||||
expect(input).toHaveAttribute("aria-invalid", "true");
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent("Your text remains at 18 px.");
|
||||
expect(readLocalPreferences().customReadingTextSize).toBe(18);
|
||||
fireEvent.keyDown(input, { key: "Escape" });
|
||||
expect(input).toHaveValue(18);
|
||||
expect(input).not.toHaveAttribute("aria-invalid", "true");
|
||||
fireEvent.change(input, { target: { value: "22" } });
|
||||
fireEvent.keyDown(input, { key: "Enter" });
|
||||
expect(input).not.toHaveFocus();
|
||||
expect(readLocalPreferences().customReadingTextSize).toBe(22);
|
||||
});
|
||||
|
||||
it.each(["", "40"])("restores the saved custom size after another tab interrupts draft %j", async (draft) => {
|
||||
writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, readingTextSize: "custom", customReadingTextSize: 24 });
|
||||
renderSettingsView({ initialSection: "appearance", initialSettings: settingsPayload() });
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { act, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { SidebarPanel } from "@/components/ui/sidebar-panel";
|
||||
|
||||
describe("sidebar presence", () => {
|
||||
it("retains the same surface until both slot and content finish closing", async () => {
|
||||
const view = (open: boolean) => <SidebarPanel open={open} width={420} aria-label="Details"><input aria-label="Draft" /></SidebarPanel>;
|
||||
const { rerender } = render(view(true));
|
||||
const panel = screen.getByRole("complementary", { name: "Details" });
|
||||
let finishSlot!: () => void;
|
||||
let finishSurface!: () => void;
|
||||
const slot = new Promise<void>((resolve) => { finishSlot = resolve; });
|
||||
const surface = new Promise<void>((resolve) => { finishSurface = resolve; });
|
||||
Object.defineProperty(panel, "getAnimations", { value: () => [{ finished: slot }] });
|
||||
Object.defineProperty(panel.firstElementChild, "getAnimations", { value: () => [{ finished: surface }] });
|
||||
rerender(view(false));
|
||||
expect(panel).toBeInTheDocument();
|
||||
expect(panel).toHaveAttribute("inert");
|
||||
expect(panel).toHaveAttribute("aria-hidden", "true");
|
||||
await act(async () => { finishSurface(); });
|
||||
expect(panel).toBeInTheDocument();
|
||||
await act(async () => { finishSlot(); });
|
||||
expect(panel).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not let an interrupted exit discard the reopened editor", async () => {
|
||||
const view = (open: boolean) => <SidebarPanel open={open} width={420} aria-label="Details"><input aria-label="Draft" defaultValue="Unsaved" /></SidebarPanel>;
|
||||
const { rerender } = render(view(true));
|
||||
const panel = screen.getByRole("complementary", { name: "Details" });
|
||||
const input = screen.getByRole("textbox", { name: "Draft" });
|
||||
let finish!: () => void;
|
||||
const finished = new Promise<void>((resolve) => { finish = resolve; });
|
||||
Object.defineProperty(panel, "getAnimations", { value: () => [{ finished }] });
|
||||
rerender(view(false));
|
||||
rerender(view(true));
|
||||
await act(async () => { finish(); });
|
||||
expect(screen.getByRole("complementary", { name: "Details" })).toBe(panel);
|
||||
expect(screen.getByRole("textbox", { name: "Draft" })).toBe(input);
|
||||
expect(input).toHaveValue("Unsaved");
|
||||
expect(panel).not.toHaveAttribute("inert");
|
||||
});
|
||||
|
||||
it("releases immediately without surface motion, ignoring activity inside it", () => {
|
||||
const ref = vi.fn();
|
||||
const view = (open: boolean) => <SidebarPanel ref={ref} open={open} width={420} aria-label="Details"><span data-testid="activity" /></SidebarPanel>;
|
||||
const { rerender } = render(view(true));
|
||||
const panel = screen.getByRole("complementary", { name: "Details" });
|
||||
const getActivityAnimations = vi.fn();
|
||||
Object.defineProperty(screen.getByTestId("activity"), "getAnimations", { value: getActivityAnimations });
|
||||
rerender(view(false));
|
||||
expect(panel).not.toBeInTheDocument();
|
||||
expect(ref).toHaveBeenLastCalledWith(null);
|
||||
expect(getActivityAnimations).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user