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 { texts } from '@/texts' import AdminEventLifecycleActions from './AdminEventLifecycleActions' vi.mock('@/components/formElements/Button', () => ({ default: ({ children, onClick, to }: { children: ReactNode; onClick?: () => void; to?: string }) => ( ), })) const baseEvent = { id: 'event-1', status: 'pending_review', adminApprovedAt: null, bookedCount: 0, } as AdminEventDetailData afterEach(cleanup) describe('AdminEventLifecycleActions', () => { it('exposes approve/reject for pending_review and hides force-publish', () => { const onApprove = vi.fn() const onOpenReject = vi.fn() render( ) fireEvent.click(screen.getByRole('button', { name: 'تأیید و انتشار' })) fireEvent.click(screen.getByRole('button', { name: 'رد' })) expect(onApprove).toHaveBeenCalledTimes(1) expect(onOpenReject).toHaveBeenCalledTimes(1) expect(screen.queryByRole('button', { name: 'انتشار فوری' })).toBeNull() expect(screen.getByText(texts.events.adminLifecycleHintPendingReview)).toBeTruthy() }) it('exposes approve and force-publish for unapproved draft events', () => { const onApprove = vi.fn() const onForcePublish = vi.fn() render( ) fireEvent.click(screen.getByRole('button', { name: 'تأیید برای انتشار' })) fireEvent.click(screen.getByRole('button', { name: 'انتشار فوری' })) expect(onApprove).toHaveBeenCalledTimes(1) expect(onForcePublish).toHaveBeenCalledTimes(1) expect(screen.queryByRole('button', { name: 'رد' })).toBeNull() expect(screen.getByText(texts.events.adminLifecycleHintDraftUnapproved)).toBeTruthy() }) it('keeps force-publish for approved drafts waiting on the host', () => { render( ) expect(screen.getByText('تأییدشده؛ منتظر میزبان')).toBeTruthy() expect(screen.getByRole('button', { name: 'انتشار فوری' })).toBeTruthy() expect(screen.queryByRole('button', { name: 'تأیید برای انتشار' })).toBeNull() }) it('exposes complete/cancel for published events and hides reject', () => { render( ) expect(screen.getByRole('button', { name: 'پایان' })).toBeTruthy() expect(screen.getByRole('button', { name: 'لغو' })).toBeTruthy() expect(screen.queryByRole('button', { name: 'رد' })).toBeNull() expect(screen.queryByRole('button', { name: 'حذف' })).toBeNull() expect(screen.queryByRole('button', { name: 'انتشار فوری' })).toBeNull() }) })