Sidebar is closed when links are clicked on mobile
All checks were successful
Production PR / QA Tests (pull_request) Successful in 44s

This commit is contained in:
Liviu Burcusel 2026-01-20 12:31:36 +01:00
parent 84252b76bb
commit 11a072e43c
Signed by: liviu
GPG key ID: 6CDB37A4AD2C610C
5 changed files with 71 additions and 14 deletions

View file

@ -267,4 +267,55 @@ describe("SidebarLayout", () => {
// and renders the menu items.
expect(text).toContain("Playground");
});
it("calls setOpenMobile(false) when clicking a sub-menu item on mobile", async () => {
const setOpenMobile = vi.fn();
useSidebarMock.mockReturnValue({
isMobile: ref(true),
state: ref("expanded"),
openMobile: ref(true),
setOpenMobile,
});
const wrapper = mount({
components: { SidebarLayout },
template: "<Suspense><SidebarLayout /></Suspense>",
});
await flushPromises();
// Find the link containing 'History' (from default data)
const link = wrapper.findAll("a").find((el) => el.text().includes("History"));
expect(link).toBeDefined();
await link!.trigger("click");
expect(setOpenMobile).toHaveBeenCalledTimes(1);
expect(setOpenMobile).toHaveBeenCalledWith(false);
});
it("does not call setOpenMobile(false) when clicking a sub-menu item on desktop", async () => {
const setOpenMobile = vi.fn();
useSidebarMock.mockReturnValue({
isMobile: ref(false),
state: ref("expanded"),
openMobile: ref(true),
setOpenMobile,
});
const wrapper = mount({
components: { SidebarLayout },
template: "<Suspense><SidebarLayout /></Suspense>",
});
await flushPromises();
// Find the link containing 'History' (from default data)
const link = wrapper.findAll("a").find((el) => el.text().includes("History"));
expect(link).toBeDefined();
await link!.trigger("click");
expect(setOpenMobile).not.toHaveBeenCalled();
});
});