Files
kandev/apps/web/e2e/tests/settings/settings-gear-only.spec.ts
T
2026-06-08 17:40:54 +01:00

69 lines
2.8 KiB
TypeScript

import { test, expect } from "../../fixtures/test-base";
// Settings has no nav "Settings" section; direct settings routes keep the
// gear-gated tree open so a hard refresh preserves settings navigation context.
test.describe("Settings sidebar takeover", () => {
test("direct settings routes open the tree, and the gear can close it", async ({ testPage }) => {
await testPage.goto("/settings");
const gear = testPage.getByTestId("sidebar-settings-gear");
const takeover = testPage.getByTestId("app-sidebar-settings-mode");
// Direct settings routes preserve sidebar context after a hard refresh.
await expect(gear).toBeVisible();
await expect(takeover).toBeVisible();
// Gear closes the takeover even though we're sitting on a settings page.
await gear.click();
await expect(takeover).toHaveCount(0);
// Gear opens the takeover again.
await gear.click();
await expect(takeover).toBeVisible();
// Enter a section: navigates to a settings sub-page; takeover stays open.
await takeover.locator('a[href="/settings/agents"]').first().click();
await expect(testPage).toHaveURL(/\/settings\/agents/);
await expect(takeover).toBeVisible();
// Clicking the gear again must close the tree even though we're still on a
// settings page (the previous bug left it open).
await gear.click();
await expect(takeover).toHaveCount(0);
});
test("navigating off settings (Kandev brand → Home) closes the takeover", async ({
testPage,
}) => {
await testPage.goto("/settings");
const takeover = testPage.getByTestId("app-sidebar-settings-mode");
const sidebar = testPage.getByTestId("app-sidebar");
await expect(takeover).toBeVisible();
// The Kandev brand navigates Home; leaving the settings surface must close
// the takeover (the bug left the tree up after going Home).
await sidebar.locator('[aria-label="Kandev home"]').first().click();
await expect(testPage).not.toHaveURL(/\/settings/);
await expect(takeover).toHaveCount(0);
});
test("the gear expands a collapsed sidebar and reveals the tree", async ({ testPage }) => {
await testPage.goto("/");
const sidebar = testPage.getByTestId("app-sidebar");
const takeover = testPage.getByTestId("app-sidebar-settings-mode");
// Collapse the rail first.
await sidebar.getByRole("button", { name: "Collapse sidebar" }).click();
await expect(sidebar).toHaveAttribute("data-collapsed", "true");
// Clicking the gear while collapsed must expand the rail AND show the tree:
// a collapsed rail can't host the settings tree.
await testPage.getByTestId("sidebar-settings-gear").click();
await expect(sidebar).toHaveAttribute("data-collapsed", "false");
await expect(takeover).toBeVisible();
});
});