fix(webui): anchor mobile settings menu below its title
This commit is contained in:
1 parent
f5c6be2608
commit
aa799cec9f
2 files changed
+114
-72
No files matched your search
@@ -38,7 +38,7 @@ function Sidebar(props: Partial<ComponentProps<typeof SettingsSidebar>>) {
|
||||
describe("Settings navigation on mobile", () => {
|
||||
installSettingsViewTestHooks();
|
||||
|
||||
it("keeps only back and the current section in the header; selects sections in a sheet", async () => {
|
||||
it("keeps the single-row header and opens a section menu beneath its title", async () => {
|
||||
mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
const restart = vi.fn();
|
||||
@@ -48,13 +48,16 @@ describe("Settings navigation on mobile", () => {
|
||||
expect(within(header).getAllByRole("button")).toHaveLength(2);
|
||||
const trigger = screen.getByRole("button", { name: "Settings: Models" });
|
||||
await user.click(trigger);
|
||||
const sheet = screen.getByRole("dialog", { name: "Settings" });
|
||||
expect(within(sheet).getByRole("button", { name: "Models", exact: true }))
|
||||
const menu = screen.getByRole("menu", { name: "Settings sections" });
|
||||
expect(trigger).toHaveAttribute("aria-haspopup", "menu");
|
||||
expect(menu).toHaveAttribute("data-side", "bottom");
|
||||
expect(within(menu).getByRole("menuitem", { name: "Models", exact: true }))
|
||||
.toHaveAttribute("aria-current", "page");
|
||||
expect(within(sheet).getByRole("navigation", { name: "Settings sections" })).toBeVisible();
|
||||
expect(within(sheet).getByRole("button", { name: "Restart" })).toBeVisible();
|
||||
await user.click(within(sheet).getByRole("button", { name: "Appearance" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(within(menu).getByRole("menuitem", { name: "Restart" })).toBeVisible();
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Close" })).not.toBeInTheDocument();
|
||||
await user.click(within(menu).getByRole("menuitem", { name: "Appearance" }));
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Settings: Appearance" })).toHaveFocus();
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
expect(restart).not.toHaveBeenCalled();
|
||||
@@ -67,40 +70,74 @@ describe("Settings navigation on mobile", () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Sidebar activeSection="image" />);
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Capabilities" }));
|
||||
expect(screen.getByRole("button", { name: "Capabilities", exact: true }))
|
||||
expect(screen.getByRole("menuitem", { name: "Capabilities", exact: true }))
|
||||
.toHaveAttribute("aria-current", "page");
|
||||
expect(screen.queryByRole("button", { name: "Restart" })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("menuitem", { name: "Restart" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each(["close", "escape", "outside"])("dismisses with %s and restores focus and pointer events", async (method) => {
|
||||
it.each(["trigger", "escape"])("dismisses with %s and restores focus without locking the page", async (method) => {
|
||||
mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
render(<Sidebar />);
|
||||
const trigger = screen.getByRole("button", { name: "Settings: Models" });
|
||||
await user.click(trigger);
|
||||
if (method === "close") await user.click(screen.getByRole("button", { name: "Close" }));
|
||||
else if (method === "escape") await user.keyboard("{Escape}");
|
||||
else {
|
||||
// The real overlay is outside the modal content; ignore the locked page behind it.
|
||||
const overlay = document.querySelector<HTMLElement>('[data-state="open"][aria-hidden="true"]');
|
||||
expect(overlay).not.toBeNull();
|
||||
await user.click(overlay!);
|
||||
}
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
if (method === "trigger") await user.click(trigger);
|
||||
else await user.keyboard("{Escape}");
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(trigger).toHaveFocus();
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
});
|
||||
|
||||
it("keeps manual restart in the sheet and closes it before handing off", async () => {
|
||||
it("dismisses on an outside click without swallowing the back action", async () => {
|
||||
mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
const back = vi.fn();
|
||||
render(<Sidebar onBackToChat={back} />);
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
const backButton = screen.getByRole("button", { name: "Back to chat" });
|
||||
await user.click(backButton);
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(back).toHaveBeenCalledOnce();
|
||||
expect(backButton).toHaveFocus();
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
});
|
||||
|
||||
it("supports keyboard section selection", async () => {
|
||||
mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
render(<Sidebar />);
|
||||
screen.getByRole("button", { name: "Settings: Models" }).focus();
|
||||
await user.keyboard("{ArrowDown}");
|
||||
expect(screen.getByRole("menuitem", { name: "Overview", exact: true })).toHaveFocus();
|
||||
await user.keyboard("{ArrowDown}{Enter}");
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Settings: Appearance" })).toHaveFocus();
|
||||
});
|
||||
|
||||
it("opens and selects sections with touch taps", async () => {
|
||||
mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
render(<Sidebar />);
|
||||
const tap = (target: HTMLElement) => user.pointer([
|
||||
{ keys: "[TouchA>]", target }, { keys: "[/TouchA]", target },
|
||||
]);
|
||||
await tap(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
await tap(screen.getByRole("menuitem", { name: "System", exact: true }));
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(screen.getByRole("button", { name: "Settings: System" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("keeps manual restart in the menu and closes it on selection", async () => {
|
||||
mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
const restart = vi.fn();
|
||||
render(<Sidebar onRestart={restart} />);
|
||||
expect(screen.queryByRole("button", { name: "Restart" })).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
await user.click(screen.getByRole("button", { name: "Restart" }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Restart" }));
|
||||
expect(restart).toHaveBeenCalledOnce();
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
});
|
||||
|
||||
@@ -116,28 +153,29 @@ describe("Settings navigation on mobile", () => {
|
||||
const runningLabel = screen.getByRole("status").textContent!;
|
||||
expect(screen.getByRole("button", { name: runningLabel, exact: true })).toBeDisabled();
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
expect(within(screen.getByRole("dialog")).getByRole("button", { name: runningLabel })).toBeDisabled();
|
||||
expect(within(screen.getByRole("menu")).getByRole("menuitem", { name: runningLabel }))
|
||||
.toHaveAttribute("aria-disabled", "true");
|
||||
await user.keyboard("{Escape}");
|
||||
rerender(<Sidebar onRestart={restart} restartPending={false} />);
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Restart" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("releases the open sheet when crossing to desktop and does not reopen on return", async () => {
|
||||
it("dismisses the open menu when crossing to desktop and does not reopen on return", async () => {
|
||||
const resize = mockMobileMedia();
|
||||
const user = userEvent.setup();
|
||||
const restart = vi.fn();
|
||||
render(<Sidebar onRestart={restart} />);
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
resize(false);
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument());
|
||||
expect(document.body.style.pointerEvents).not.toBe("none");
|
||||
expect(screen.queryByRole("button", { name: "Settings: Models" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Models", exact: true })).toBeVisible();
|
||||
await user.click(screen.getByRole("button", { name: "Restart" }));
|
||||
expect(restart).toHaveBeenCalledOnce();
|
||||
resize(true);
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Settings: Models" })).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -149,7 +187,7 @@ describe("Settings navigation on mobile", () => {
|
||||
...settingsPayload(), requires_restart: true,
|
||||
}, onBackToChat: back });
|
||||
await user.click(screen.getByRole("button", { name: "Settings: Models" }));
|
||||
await user.click(screen.getByRole("button", { name: "Appearance", exact: true }));
|
||||
await user.click(screen.getByRole("menuitem", { name: "Appearance", exact: true }));
|
||||
await user.click(screen.getByRole("button", { name: "Back to chat" }));
|
||||
const dialog = screen.getByRole("dialog", { name: "Restart before leaving?" });
|
||||
expect(back).not.toHaveBeenCalled();
|
||||
|
||||
Reference in new issue
Block a user