Sidebar is closed when links are clicked on mobile
This commit is contained in:
parent
84252b76bb
commit
3d1627a384
5 changed files with 71 additions and 14 deletions
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue