admin/components/paginated-list/PaginatedListToolbar.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

57 lines
1.6 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 { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import PaginatedListToolbar from '@/components/paginated-list/PaginatedListToolbar'
afterEach(cleanup)
const baseProps = {
activeFilterCount: 0,
bulkActions: undefined,
dynamicButtonText: 'افزودن',
hasFilters: false,
selectedKeys: new Set<string>(),
selectionMode: 'none' as const,
onBack: vi.fn(),
onDynamicButtonClick: vi.fn(),
onOpenFilters: vi.fn(),
onClearSelection: vi.fn(),
}
describe('PaginatedListToolbar', () => {
it('announces selected rows and clears the selection', () => {
const onClearSelection = vi.fn()
render(
<PaginatedListToolbar
{...baseProps}
bulkActions={<button type="button">بایگانی</button>}
selectedKeys={new Set(['1', '2'])}
selectionMode="multiple"
onClearSelection={onClearSelection}
/>
)
expect(screen.getByRole('status')).toHaveTextContent('۲ سطر انتخاب شده')
expect(screen.getByRole('button', { name: 'بایگانی' })).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'لغو انتخاب' }))
expect(onClearSelection).toHaveBeenCalledTimes(1)
})
it('shows mobile filters button when filters exist', () => {
const onOpenFilters = vi.fn()
render(
<PaginatedListToolbar
{...baseProps}
hasFilters
activeFilterCount={2}
onOpenFilters={onOpenFilters}
/>
)
fireEvent.click(screen.getByRole('button', { name: /فیلترها/ }))
expect(onOpenFilters).toHaveBeenCalledTimes(1)
})
})