admin/features/events/detail/admin-event-detail/AdminEventLifecycleActions.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

78 lines
2.3 KiB
TypeScript

import type { ReactNode } from 'react'
import type { AdminEventDetailData } from './types'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import AdminEventLifecycleActions from './AdminEventLifecycleActions'
vi.mock('@/components/formElements/Button', () => ({
default: ({ children, onClick, to }: { children: ReactNode; onClick?: () => void; to?: string }) => (
<button
data-to={to}
type="button"
onClick={onClick}
>
{children}
</button>
),
}))
const baseEvent = {
id: 'event-1',
status: 'pending_review',
adminApprovedAt: null,
bookedCount: 0,
} as AdminEventDetailData
afterEach(cleanup)
describe('AdminEventLifecycleActions', () => {
it('exposes approve/reject/force-publish for pending_review events', () => {
const onApprove = vi.fn()
const onOpenReject = vi.fn()
const onForcePublish = vi.fn()
render(
<AdminEventLifecycleActions
event={baseEvent}
pendingId={null}
onApprove={onApprove}
onCancel={vi.fn()}
onComplete={vi.fn()}
onDelete={vi.fn()}
onForcePublish={onForcePublish}
onOpenReject={onOpenReject}
/>
)
fireEvent.click(screen.getByRole('button', { name: 'تأیید و انتشار' }))
fireEvent.click(screen.getByRole('button', { name: 'رد' }))
fireEvent.click(screen.getByRole('button', { name: 'انتشار فوری' }))
expect(onApprove).toHaveBeenCalledTimes(1)
expect(onOpenReject).toHaveBeenCalledTimes(1)
expect(onForcePublish).toHaveBeenCalledTimes(1)
})
it('exposes complete/cancel for published events and hides reject', () => {
render(
<AdminEventLifecycleActions
event={{ ...baseEvent, status: 'published', bookedCount: 2 }}
pendingId={null}
onApprove={vi.fn()}
onCancel={vi.fn()}
onComplete={vi.fn()}
onDelete={vi.fn()}
onForcePublish={vi.fn()}
onOpenReject={vi.fn()}
/>
)
expect(screen.getByRole('button', { name: 'پایان' })).toBeTruthy()
expect(screen.getByRole('button', { name: 'لغو' })).toBeTruthy()
expect(screen.queryByRole('button', { name: 'رد' })).toBeNull()
expect(screen.queryByRole('button', { name: 'حذف' })).toBeNull()
})
})