admin/components/layouts/SidebarMobile.test.tsx
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

42 lines
1.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import SidebarMobile from '@/components/layouts/SidebarMobile'
vi.mock('next/navigation', () => ({ usePathname: () => '/dashboard' }))
vi.mock('next/image', () => ({
default: ({ alt }: { alt: string }) => (
<span
aria-label={alt}
role="img"
/>
),
}))
vi.mock('@/components/layouts/sidebar/SidebarNav', () => ({
default: () => <button type="button">پیشخوان</button>,
}))
vi.mock('@/components/layouts/SidebarUserFooter', () => ({ default: () => null }))
vi.mock('@/components/layouts/Loading', () => ({ default: () => null }))
describe('SidebarMobile', () => {
it('keeps the closed navigation inert and closes it with Escape', async () => {
render(<SidebarMobile />)
const trigger = screen.getByRole('button', { name: 'باز کردن منو' })
const dialog = screen.getByRole('dialog', { hidden: true })
expect(trigger).toHaveAttribute('aria-expanded', 'false')
expect(dialog).toHaveAttribute('inert')
fireEvent.click(trigger)
expect(trigger).toHaveAttribute('aria-expanded', 'true')
expect(dialog).not.toHaveAttribute('inert')
expect(document.body.style.overflow).toBe('hidden')
fireEvent.keyDown(document, { key: 'Escape' })
await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'false'))
expect(dialog).toHaveAttribute('inert')
expect(document.body.style.overflow).toBe('')
})
})