mirror of
https://github.com/langgenius/dify.git
synced 2026-02-09 15:10:13 -05:00
test: fix test (#31880)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { PropsWithChildren } from 'react'
|
import type { PropsWithChildren } from 'react'
|
||||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import { DSLImportStatus } from '@/models/app'
|
import { DSLImportStatus } from '@/models/app'
|
||||||
import UpdateDSLModal from './update-dsl-modal'
|
import UpdateDSLModal from './update-dsl-modal'
|
||||||
@@ -648,6 +648,8 @@ describe('UpdateDSLModal', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should show error modal when import status is PENDING', async () => {
|
it('should show error modal when import status is PENDING', async () => {
|
||||||
|
vi.useFakeTimers({ shouldAdvanceTime: true })
|
||||||
|
|
||||||
mockImportDSL.mockResolvedValue({
|
mockImportDSL.mockResolvedValue({
|
||||||
id: 'import-id',
|
id: 'import-id',
|
||||||
status: DSLImportStatus.PENDING,
|
status: DSLImportStatus.PENDING,
|
||||||
@@ -660,20 +662,29 @@ describe('UpdateDSLModal', () => {
|
|||||||
|
|
||||||
const fileInput = screen.getByTestId('file-input')
|
const fileInput = screen.getByTestId('file-input')
|
||||||
const file = new File(['test content'], 'test.pipeline', { type: 'text/yaml' })
|
const file = new File(['test content'], 'test.pipeline', { type: 'text/yaml' })
|
||||||
fireEvent.change(fileInput, { target: { files: [file] } })
|
|
||||||
|
|
||||||
await waitFor(() => {
|
await act(async () => {
|
||||||
const importButton = screen.getByText('common.overwriteAndImport')
|
fireEvent.change(fileInput, { target: { files: [file] } })
|
||||||
expect(importButton).not.toBeDisabled()
|
// Flush microtasks scheduled by the FileReader mock (which uses queueMicrotask)
|
||||||
}, { timeout: 1000 })
|
await new Promise<void>(resolve => queueMicrotask(resolve))
|
||||||
|
})
|
||||||
|
|
||||||
const importButton = screen.getByText('common.overwriteAndImport')
|
const importButton = screen.getByText('common.overwriteAndImport')
|
||||||
fireEvent.click(importButton)
|
expect(importButton).not.toBeDisabled()
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(importButton)
|
||||||
|
// Flush the promise resolution from mockImportDSL
|
||||||
|
await Promise.resolve()
|
||||||
|
// Advance past the 300ms setTimeout in the component
|
||||||
|
await vi.advanceTimersByTimeAsync(350)
|
||||||
|
})
|
||||||
|
|
||||||
// Wait for the error modal to be shown after setTimeout
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('newApp.appCreateDSLErrorTitle')).toBeInTheDocument()
|
expect(screen.getByText('newApp.appCreateDSLErrorTitle')).toBeInTheDocument()
|
||||||
}, { timeout: 1000 })
|
})
|
||||||
|
|
||||||
|
vi.useRealTimers()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should show version info in error modal', async () => {
|
it('should show version info in error modal', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user