66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import React from "react";
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
|
|
// Mock next/navigation
|
|
let currentPathname = "/search";
|
|
vi.mock("next/navigation", () => ({
|
|
usePathname: () => currentPathname,
|
|
useRouter: () => ({ push: vi.fn(), replace: vi.fn(), back: vi.fn() }),
|
|
useSearchParams: () => new URLSearchParams(),
|
|
}));
|
|
|
|
vi.mock("next/link", () => ({
|
|
default: ({ children, href, ...props }: any) => <a href={href} {...props}>{children}</a>,
|
|
}));
|
|
|
|
vi.mock("../../lib/store/cartStore", () => ({
|
|
useCartStore: (selector?: any) => {
|
|
const s = { getTotalItems: () => 0 };
|
|
return typeof selector === "function" ? selector(s) : s;
|
|
},
|
|
}));
|
|
|
|
vi.mock("../../lib/store/userStore", () => ({
|
|
useUserStore: () => ({
|
|
isLoggedIn: false,
|
|
setAuthModalOpen: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
vi.mock("../../lib/store/uiStore", () => ({
|
|
useUIStore: () => vi.fn(),
|
|
}));
|
|
|
|
vi.mock("../../lib/store/settingsStore", () => ({
|
|
useSettingsStore: () => ({
|
|
getBoolean: () => true,
|
|
getText: () => "true",
|
|
}),
|
|
}));
|
|
|
|
import MobileBottomNav from "../MobileBottomNav";
|
|
|
|
describe("MobileBottomNav on /search route (UX-32)", () => {
|
|
it("opens menu bottom sheet smoothly when clicking menu button on search page", async () => {
|
|
currentPathname = "/search";
|
|
render(<MobileBottomNav />);
|
|
|
|
const menuBtn = screen.getByRole("button", { name: "منو" });
|
|
expect(menuBtn).toBeTruthy();
|
|
|
|
fireEvent.click(menuBtn);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("منوی بخشهای کنینا")).toBeTruthy();
|
|
});
|
|
|
|
const closeBtn = screen.getByRole("button", { name: "بستن ✕" });
|
|
fireEvent.click(closeBtn);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.queryByText("منوی بخشهای کنینا")).toBeNull();
|
|
});
|
|
});
|
|
});
|