Updated the alert message in the UserEditModal component to improve code readability by formatting the function call across multiple lines. This change enhances maintainability and aligns with the project's coding standards.
125 lines
4.0 KiB
TypeScript
125 lines
4.0 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 { texts } from '@/texts'
|
|
|
|
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 for pending_review and hides force-publish', () => {
|
|
const onApprove = vi.fn()
|
|
const onOpenReject = vi.fn()
|
|
|
|
render(
|
|
<AdminEventLifecycleActions
|
|
event={baseEvent}
|
|
pendingId={null}
|
|
onApprove={onApprove}
|
|
onCancel={vi.fn()}
|
|
onComplete={vi.fn()}
|
|
onDelete={vi.fn()}
|
|
onForcePublish={vi.fn()}
|
|
onOpenReject={onOpenReject}
|
|
/>
|
|
)
|
|
|
|
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(
|
|
<AdminEventLifecycleActions
|
|
event={{ ...baseEvent, status: 'draft', adminApprovedAt: null }}
|
|
pendingId={null}
|
|
onApprove={onApprove}
|
|
onCancel={vi.fn()}
|
|
onComplete={vi.fn()}
|
|
onDelete={vi.fn()}
|
|
onForcePublish={onForcePublish}
|
|
onOpenReject={vi.fn()}
|
|
/>
|
|
)
|
|
|
|
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(
|
|
<AdminEventLifecycleActions
|
|
event={{ ...baseEvent, status: 'draft', adminApprovedAt: '2026-01-01T00:00:00.000Z' }}
|
|
pendingId={null}
|
|
onApprove={vi.fn()}
|
|
onCancel={vi.fn()}
|
|
onComplete={vi.fn()}
|
|
onDelete={vi.fn()}
|
|
onForcePublish={vi.fn()}
|
|
onOpenReject={vi.fn()}
|
|
/>
|
|
)
|
|
|
|
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(
|
|
<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()
|
|
expect(screen.queryByRole('button', { name: 'انتشار فوری' })).toBeNull()
|
|
})
|
|
})
|