- Replace Proxy-based useTranslation hook with thin react-i18next wrapper
- Convert all t.section.key property access to t('section.key') function calls across 84 files
- Migrate TranslationKeys type parameters to TFunction from i18next
- Update test setup mock and test assertions for new pattern
- Preserve setLanguage with language change events for loading overlay
Closes #579
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
import { ConfirmDialog } from './ConfirmDialog'
|
|
|
|
// useTranslation is mocked globally in setup.ts (t returns the key string)
|
|
|
|
describe('ConfirmDialog', () => {
|
|
const onConfirmMock = vi.fn()
|
|
const onOpenChangeMock = vi.fn()
|
|
|
|
const defaultProps = {
|
|
open: true,
|
|
onOpenChange: onOpenChangeMock,
|
|
title: 'Test Title',
|
|
description: 'Test Description',
|
|
onConfirm: onConfirmMock,
|
|
}
|
|
|
|
it('should render correct titles and descriptions', () => {
|
|
render(<ConfirmDialog {...defaultProps} />)
|
|
|
|
expect(screen.getByText('Test Title')).toBeInTheDocument()
|
|
expect(screen.getByText('Test Description')).toBeInTheDocument()
|
|
expect(screen.getByText('common.confirm')).toBeInTheDocument()
|
|
expect(screen.getByText('common.cancel')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should call onConfirm when confirm button is clicked', () => {
|
|
render(<ConfirmDialog {...defaultProps} />)
|
|
|
|
const confirmBtn = screen.getByText('common.confirm')
|
|
fireEvent.click(confirmBtn)
|
|
|
|
expect(onConfirmMock).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should show custom confirm text if provided', () => {
|
|
render(<ConfirmDialog {...defaultProps} confirmText="Delete Now" />)
|
|
expect(screen.getByText('Delete Now')).toBeInTheDocument()
|
|
})
|
|
|
|
it('should show loading state and disable buttons', () => {
|
|
render(<ConfirmDialog {...defaultProps} isLoading={true} />)
|
|
|
|
const confirmBtn = screen.getByText('common.confirm').closest('button')
|
|
const cancelBtn = screen.getByText('common.cancel').closest('button')
|
|
|
|
expect(confirmBtn).toBeDisabled()
|
|
expect(cancelBtn).toBeDisabled()
|
|
})
|
|
})
|