Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test: fix test (#31880)

Stephen Zhoub76c8fa853e1
diff --git a/web/app/components/rag-pipeline/components/update-dsl-modal.spec.tsx b/web/app/components/rag-pipeline/components/update-dsl-modal.spec.tsx
index 23b92f3e15f..f57bd80d7b0 100644
--- a/web/app/components/rag-pipeline/components/update-dsl-modal.spec.tsx
+++ b/web/app/components/rag-pipeline/components/update-dsl-modal.spec.tsx
@@ -1,5 +1,5 @@
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 { DSLImportStatus } from '@/models/app'
import UpdateDSLModal from './update-dsl-modal'
@@ -648,6 +648,8 @@ describe('UpdateDSLModal', () => {
})
it('should show error modal when import status is PENDING', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true })
+
mockImportDSL.mockResolvedValue({
id: 'import-id',
status: DSLImportStatus.PENDING,
@@ -660,20 +662,29 @@ describe('UpdateDSLModal', () => {
const fileInput = screen.getByTestId('file-input')
const file = new File(['test content'], 'test.pipeline', { type: 'text/yaml' })
- fireEvent.change(fileInput, { target: { files: [file] } })
- await waitFor(() => {
- const importButton = screen.getByText('common.overwriteAndImport')
- expect(importButton).not.toBeDisabled()
- }, { timeout: 1000 })
+ await act(async () => {
+ fireEvent.change(fileInput, { target: { files: [file] } })
+ // Flush microtasks scheduled by the FileReader mock (which uses queueMicrotask)
+ await new Promise<void>(resolve => queueMicrotask(resolve))
+ })
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(() => {
expect(screen.getByText('newApp.appCreateDSLErrorTitle')).toBeInTheDocument()
- }, { timeout: 1000 })
+ })
+
+ vi.useRealTimers()
})
it('should show version info in error modal', async () => {