mirror of
https://github.com/langgenius/dify.git
synced 2026-04-19 18:27:27 +08:00
test: update Item and Conversion component tests to use alert dialog roles and async assertions
This commit is contained in:
@ -105,8 +105,10 @@ describe('Item Component', () => {
|
||||
|
||||
// Act
|
||||
fireEvent.click(screen.getByText('common.operation.delete'))
|
||||
const dialog = screen.getByTestId('confirm-overlay')
|
||||
const confirmButton = within(dialog).getByText('common.operation.delete')
|
||||
const dialog = screen.getByRole('alertdialog', {
|
||||
name: /common\.operation\.delete.*Test Extension.*\?/i,
|
||||
})
|
||||
const confirmButton = within(dialog).getByRole('button', { name: 'common.operation.delete' })
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
// Assert
|
||||
@ -123,8 +125,10 @@ describe('Item Component', () => {
|
||||
|
||||
// Act
|
||||
fireEvent.click(screen.getByText('common.operation.delete'))
|
||||
const dialog = screen.getByTestId('confirm-overlay')
|
||||
const confirmButton = within(dialog).getByText('common.operation.delete')
|
||||
const dialog = screen.getByRole('alertdialog', {
|
||||
name: /common\.operation\.delete.*Test Extension.*\?/i,
|
||||
})
|
||||
const confirmButton = within(dialog).getByRole('button', { name: 'common.operation.delete' })
|
||||
fireEvent.click(confirmButton)
|
||||
|
||||
// Assert
|
||||
@ -133,14 +137,16 @@ describe('Item Component', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should close delete confirmation when clicking cancel button', () => {
|
||||
it('should close delete confirmation when clicking cancel button', async () => {
|
||||
// Act
|
||||
render(<Item data={mockData} onUpdate={mockOnUpdate} />)
|
||||
fireEvent.click(screen.getByText('common.operation.delete'))
|
||||
fireEvent.click(screen.getByText('common.operation.cancel'))
|
||||
|
||||
// Assert
|
||||
expect(screen.queryByText(/common\.operation\.delete.*Test Extension.*\?/i)).not.toBeInTheDocument()
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText(/common\.operation\.delete.*Test Extension.*\?/i)).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not call delete API when canceling deletion', () => {
|
||||
|
||||
@ -472,21 +472,23 @@ describe('Conversion', () => {
|
||||
const convertButton = screen.getByRole('button', { name: /datasetPipeline\.operations\.convert/i })
|
||||
fireEvent.click(convertButton)
|
||||
|
||||
// Real Confirm renders title and content via portal
|
||||
// AlertDialog renders title and content via portal.
|
||||
expect(screen.getByText('datasetPipeline.conversion.confirm.title')).toBeInTheDocument()
|
||||
expect(screen.getByText('datasetPipeline.conversion.confirm.content')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should hide confirm modal when cancel is clicked', () => {
|
||||
it('should hide confirm modal when cancel is clicked', async () => {
|
||||
render(<Conversion />)
|
||||
|
||||
const convertButton = screen.getByRole('button', { name: /datasetPipeline\.operations\.convert/i })
|
||||
fireEvent.click(convertButton)
|
||||
expect(screen.getByText('datasetPipeline.conversion.confirm.title')).toBeInTheDocument()
|
||||
|
||||
// Real Confirm renders cancel button with i18n text
|
||||
// AlertDialog close is async because it unmounts after state updates.
|
||||
fireEvent.click(screen.getByRole('button', { name: 'common.operation.cancel' }))
|
||||
expect(screen.queryByText('datasetPipeline.conversion.confirm.title')).not.toBeInTheDocument()
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('datasetPipeline.conversion.confirm.title')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user