test(web): add and enhance frontend automated tests across multiple modules (#32268)

Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
Coding On Star
2026-02-13 10:27:48 +08:00
committed by GitHub
parent 16df9851a2
commit b6d506828b
75 changed files with 5652 additions and 4081 deletions

View File

@ -1,11 +1,9 @@
import { act, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import copy from 'copy-to-clipboard'
import InputCopy from '../input-copy'
vi.mock('copy-to-clipboard', () => ({
default: vi.fn().mockReturnValue(true),
}))
// Suppress expected React act() warnings from CopyFeedback timer-based state updates
vi.spyOn(console, 'error').mockImplementation(() => {})
async function renderAndFlush(ui: React.ReactElement) {
const result = render(ui)
@ -15,10 +13,14 @@ async function renderAndFlush(ui: React.ReactElement) {
return result
}
const execCommandMock = vi.fn().mockReturnValue(true)
describe('InputCopy', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.useFakeTimers({ shouldAdvanceTime: true })
execCommandMock.mockReturnValue(true)
document.execCommand = execCommandMock
})
afterEach(() => {
@ -107,7 +109,7 @@ describe('InputCopy', () => {
await user.click(copyableArea)
})
expect(copy).toHaveBeenCalledWith('copy-this-value')
expect(execCommandMock).toHaveBeenCalledWith('copy')
})
it('should update copied state after clicking', async () => {
@ -119,7 +121,7 @@ describe('InputCopy', () => {
await user.click(copyableArea)
})
expect(copy).toHaveBeenCalledWith('test-value')
expect(execCommandMock).toHaveBeenCalledWith('copy')
})
it('should reset copied state after timeout', async () => {
@ -131,7 +133,7 @@ describe('InputCopy', () => {
await user.click(copyableArea)
})
expect(copy).toHaveBeenCalledWith('test-value')
expect(execCommandMock).toHaveBeenCalledWith('copy')
await act(async () => {
vi.advanceTimersByTime(1500)
@ -306,7 +308,7 @@ describe('InputCopy', () => {
await user.click(copyableArea)
})
expect(copy).toHaveBeenCalledTimes(3)
expect(execCommandMock).toHaveBeenCalledTimes(3)
})
})
})

View File

@ -3,6 +3,9 @@ import userEvent from '@testing-library/user-event'
import { afterEach } from 'vitest'
import SecretKeyModal from '../secret-key-modal'
// Suppress expected React act() warnings from Headless UI Dialog transitions and async API state updates
vi.spyOn(console, 'error').mockImplementation(() => {})
async function renderModal(ui: React.ReactElement) {
const result = render(ui)
await act(async () => {