feat: visitor pages, My QR, sign-in frame and shell refinements #39
No files matched your search
@@ -6,7 +6,7 @@ Verify for every task: `cd solvway-admin-portal && npx vitest run; echo VITEST=$
|
||||
|
||||
## 1. Shell
|
||||
|
||||
- [ ] 1.1 Header trail without repeats: `Breadcrumbs` shows nothing on a page whose URL is the matched leaf's own URL, and shows the leaf as a link on a sub-page.
|
||||
- [x] 1.1 Header trail without repeats: `Breadcrumbs` shows nothing on a page whose URL is the matched leaf's own URL, and shows the leaf as a link on a sub-page.
|
||||
- Depends on: none
|
||||
- Scope: `solvway-admin-portal/app/components/app/Breadcrumbs*`
|
||||
- [ ] 1.2 Sidebar sections: an `ADMIN_MODULES` list in `aclSidebar.ts`, the work and Administration split in `Sidebar` (full sidebar and drawer: divider and label; rail: divider only; no section when it has no items), and the "Administration" label in `defaultMessages.ts`.
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { SidebarLink } from "@/app/lib/aclSidebar";
|
||||
import { MessagesProvider } from "@/app/lib/i18n/MessagesProvider";
|
||||
|
||||
// fix-admin-shell-foundation: header breadcrumbs derived from the sidebar tree. Group names are
|
||||
// text; the module crumb is the current page on its own url and a link back to it on a sub-page.
|
||||
// text; on the module's own url there is no trail (refine-visitor-pages-and-shell), and on a
|
||||
// sub-page the module crumb is a link back to it.
|
||||
|
||||
const state = vi.hoisted(() => ({ links: [] as SidebarLink[], pathname: "/" }));
|
||||
|
||||
@@ -47,15 +48,14 @@ describe("Breadcrumbs", () => {
|
||||
expect(screen.queryByRole("link", { name: "Sales & Orders" })).toBeNull();
|
||||
});
|
||||
|
||||
it("marks the list page itself as the current page, not a link", () => {
|
||||
// The page title already names a list page, so its own trail is not repeated (refine-visitor-pages-and-shell).
|
||||
it("shows nothing on the list page itself", () => {
|
||||
state.links = LINKS;
|
||||
state.pathname = "/orders/web";
|
||||
|
||||
render(<Breadcrumbs />);
|
||||
const { container } = render(<Breadcrumbs />);
|
||||
|
||||
expect(screen.queryByRole("link", { name: "Sales Listing" })).toBeNull();
|
||||
expect(screen.getByText("Sales Listing")).toHaveAttribute("aria-current", "page");
|
||||
expect(screen.getByRole("navigation", { name: "breadcrumb" })).toHaveTextContent("Sales & Orders");
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it("shows nothing on the dashboard", () => {
|
||||
@@ -78,7 +78,7 @@ describe("Breadcrumbs", () => {
|
||||
|
||||
it("uses the same translated labels as the sidebar", () => {
|
||||
state.links = [{ name: "BO_USERS", url: "", children: [{ name: "BO_MESSAGES", url: "/messages", children: [] }] }];
|
||||
state.pathname = "/messages";
|
||||
state.pathname = "/messages/7";
|
||||
|
||||
render(
|
||||
<MessagesProvider locale="zh_CN" messages={{ BO_MESSAGES: "消息" }}>
|
||||
@@ -86,7 +86,7 @@ describe("Breadcrumbs", () => {
|
||||
</MessagesProvider>,
|
||||
);
|
||||
|
||||
expect(screen.getByText("消息")).toHaveAttribute("aria-current", "page");
|
||||
expect(screen.getByRole("link", { name: "消息" })).toHaveAttribute("href", "/messages");
|
||||
expect(screen.getByRole("navigation", { name: "breadcrumb" })).toHaveTextContent("Users");
|
||||
});
|
||||
});
|
||||
@@ -97,11 +97,11 @@ describe("Breadcrumbs pick the most specific match", () => {
|
||||
{ name: "Event", url: "", children: [{ name: "Event POS", url: "/pos", children: [] }] },
|
||||
{ name: "Sales", url: "", children: [{ name: "Branch Counter", url: "/pos/counter", children: [] }] },
|
||||
];
|
||||
state.pathname = "/pos/counter";
|
||||
state.pathname = "/pos/counter/5";
|
||||
|
||||
render(<Breadcrumbs />);
|
||||
|
||||
expect(screen.getByText("Branch Counter")).toHaveAttribute("aria-current", "page");
|
||||
expect(screen.getByRole("link", { name: "Branch Counter" })).toHaveAttribute("href", "/pos/counter");
|
||||
expect(screen.getByRole("navigation", { name: "breadcrumb" })).not.toHaveTextContent("Event");
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SidebarLink } from "@/app/lib/aclSidebar";
|
||||
|
||||
// refine-visitor-pages-and-shell: no trail on a leaf's own page (the page title says it already).
|
||||
|
||||
const state = vi.hoisted(() => ({ links: [] as SidebarLink[], pathname: "/" }));
|
||||
|
||||
vi.mock("next/navigation", () => ({ usePathname: () => state.pathname }));
|
||||
vi.mock("@/app/lib/useAclSidebar", () => ({ useAclSidebar: () => state.links }));
|
||||
|
||||
import Breadcrumbs from "./Breadcrumbs";
|
||||
|
||||
const LINKS: SidebarLink[] = [
|
||||
{
|
||||
name: "Event",
|
||||
url: "",
|
||||
children: [{ name: "Events", url: "/events", children: [] }],
|
||||
},
|
||||
];
|
||||
|
||||
afterEach(() => {
|
||||
state.pathname = "/";
|
||||
});
|
||||
|
||||
describe("Breadcrumbs trail without repeats", () => {
|
||||
it("shows no trail on the Events list", () => {
|
||||
state.links = LINKS;
|
||||
state.pathname = "/events";
|
||||
|
||||
const { container } = render(<Breadcrumbs />);
|
||||
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it("shows Events as a link to the list on the new event page", () => {
|
||||
state.links = LINKS;
|
||||
state.pathname = "/events/new";
|
||||
|
||||
render(<Breadcrumbs />);
|
||||
|
||||
expect(screen.getByRole("link", { name: "Events" })).toHaveAttribute("href", "/events");
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbList,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
} from "@/app/components/ui/breadcrumb";
|
||||
|
||||
@@ -24,6 +23,7 @@ export default function Breadcrumbs() {
|
||||
if (!leaf || leaf.url === "/") return null;
|
||||
|
||||
const url = matchedUrl(leaf, pathname)!;
|
||||
if (pathname === url) return null;
|
||||
|
||||
return (
|
||||
<Breadcrumb className="hidden md:block">
|
||||
@@ -35,13 +35,9 @@ export default function Breadcrumbs() {
|
||||
</Fragment>
|
||||
))}
|
||||
<BreadcrumbItem>
|
||||
{pathname === url ? (
|
||||
<BreadcrumbPage>{t(leaf.name)}</BreadcrumbPage>
|
||||
) : (
|
||||
<BreadcrumbLink asChild>
|
||||
<Link href={url}>{t(leaf.name)}</Link>
|
||||
</BreadcrumbLink>
|
||||
)}
|
||||
<BreadcrumbLink asChild>
|
||||
<Link href={url}>{t(leaf.name)}</Link>
|
||||
</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
</BreadcrumbList>
|
||||
</Breadcrumb>
|
||||
|
||||
@@ -2,10 +2,10 @@ import { render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
const nav = vi.hoisted(() => ({ replace: vi.fn(), refresh: vi.fn() }));
|
||||
const nav = vi.hoisted(() => ({ replace: vi.fn(), refresh: vi.fn(), pathname: "/orders/web" }));
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({ replace: nav.replace, refresh: nav.refresh }),
|
||||
usePathname: () => "/orders/web",
|
||||
usePathname: () => nav.pathname,
|
||||
}));
|
||||
|
||||
// The mobile drawer (fix-admin-shell-foundation) renders the same aclMenu-derived tree as the sidebar.
|
||||
@@ -144,8 +144,19 @@ describe("Header mobile navigation", () => {
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
|
||||
});
|
||||
|
||||
it("shows breadcrumbs for the current page", () => {
|
||||
// On a list page the trail is empty: the page title already names it (refine-visitor-pages-and-shell).
|
||||
it("shows no breadcrumbs on a list page", () => {
|
||||
render(<Header />);
|
||||
expect(screen.getByRole("navigation", { name: "breadcrumb" })).toHaveTextContent("Sales Listing");
|
||||
expect(screen.queryByRole("navigation", { name: "breadcrumb" })).toBeNull();
|
||||
});
|
||||
|
||||
it("shows the list page as a link back on a sub-page", () => {
|
||||
nav.pathname = "/orders/web/1";
|
||||
try {
|
||||
render(<Header />);
|
||||
expect(screen.getByRole("link", { name: "Sales Listing" })).toHaveAttribute("href", "/orders/web");
|
||||
} finally {
|
||||
nav.pathname = "/orders/web";
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user