feat: ensure نوبتها menu remains always expanded in the sidebar
This commit is contained in:
@@ -20,19 +20,19 @@ describe("Sidebar — expandable نوبتها menu", () => {
|
|||||||
} as any);
|
} as any);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders نوبتها as a collapsible parent and reveals sub-items on click", () => {
|
it("keeps نوبتها always expanded regardless of route and click", () => {
|
||||||
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
|
renderWithProviders(<Sidebar />, { route: "/admin/dashboard" });
|
||||||
|
|
||||||
// منوی والد به شکل دکمه
|
// منوی والد به شکل دکمه
|
||||||
const parent = screen.getByRole("button", { name: /نوبتها/ });
|
const parent = screen.getByRole("button", { name: /نوبتها/ });
|
||||||
expect(parent).toBeInTheDocument();
|
expect(parent).toBeInTheDocument();
|
||||||
|
|
||||||
// در ابتدا (مسیر داشبورد) بسته است → زیرمنوها نیستند
|
// حتی خارج از مسیر نوبتها، زیرمنوها همیشه دیده میشوند
|
||||||
expect(screen.queryByText("نوبت ها")).toBeNull();
|
expect(screen.getByText("نوبت ها")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("افزودن نوبت")).toBeInTheDocument();
|
||||||
|
|
||||||
|
// کلیک روی والد آن را جمع نمیکند
|
||||||
fireEvent.click(parent);
|
fireEvent.click(parent);
|
||||||
|
|
||||||
// پس از باز شدن، دو زیرمنو دیده میشوند
|
|
||||||
expect(screen.getByText("نوبت ها")).toBeInTheDocument();
|
expect(screen.getByText("نوبت ها")).toBeInTheDocument();
|
||||||
expect(screen.getByText("افزودن نوبت")).toBeInTheDocument();
|
expect(screen.getByText("افزودن نوبت")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -509,7 +509,12 @@ function NavItem({
|
|||||||
const { icon: Icon, label, to, children } = item;
|
const { icon: Icon, label, to, children } = item;
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const childActive = !!children?.some((c) => location.pathname === c.to);
|
const childActive = !!children?.some((c) => location.pathname === c.to);
|
||||||
const [open, setOpen] = useState(childActive);
|
// منوی «نوبتها» همیشه باز میماند و جمع نمیشود.
|
||||||
|
const alwaysOpen = !!children?.some((c) =>
|
||||||
|
c.to.startsWith("/admin/appointments"),
|
||||||
|
);
|
||||||
|
const [openState, setOpen] = useState(childActive);
|
||||||
|
const open = alwaysOpen || openState;
|
||||||
|
|
||||||
// منوی ساده — رفتار قبلی بدون تغییر.
|
// منوی ساده — رفتار قبلی بدون تغییر.
|
||||||
if (!children || children.length === 0) {
|
if (!children || children.length === 0) {
|
||||||
@@ -553,7 +558,7 @@ function NavItem({
|
|||||||
className={`nav-item${childActive ? " active" : ""}`}
|
className={`nav-item${childActive ? " active" : ""}`}
|
||||||
aria-expanded={open}
|
aria-expanded={open}
|
||||||
title={!sidebarOpen ? label : undefined}
|
title={!sidebarOpen ? label : undefined}
|
||||||
onClick={() => setOpen((o) => !o)}
|
onClick={() => !alwaysOpen && setOpen((o) => !o)}
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
background: "none",
|
background: "none",
|
||||||
|
|||||||
Reference in New Issue
Block a user