mirror of
https://github.com/langgenius/dify.git
synced 2026-04-15 18:06:36 +08:00
fix: web tests
This commit is contained in:
parent
8760286a27
commit
aa8376b5d2
@ -1,6 +1,6 @@
|
||||
import type { App } from '@/types/app'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { trackEvent } from '@/app/components/base/amplitude'
|
||||
|
||||
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
|
||||
@ -121,7 +121,6 @@ const renderModal = () => {
|
||||
|
||||
describe('CreateAppModal', () => {
|
||||
const mockSetItem = vi.fn()
|
||||
const originalLocalStorage = window.localStorage
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@ -153,13 +152,6 @@ describe('CreateAppModal', () => {
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
Object.defineProperty(window, 'localStorage', {
|
||||
value: originalLocalStorage,
|
||||
writable: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('creates an app, notifies success, and fires callbacks', async () => {
|
||||
const mockApp: Partial<App> = { id: 'app-1', mode: AppModeEnum.ADVANCED_CHAT }
|
||||
mockCreateApp.mockResolvedValue(mockApp as App)
|
||||
|
||||
@ -116,9 +116,13 @@ vi.mock('@/service/tag', () => ({
|
||||
fetchTagList: vi.fn().mockResolvedValue([{ id: 'tag-1', name: 'Test Tag', type: 'app' }]),
|
||||
}))
|
||||
|
||||
vi.mock('@/config', () => ({
|
||||
NEED_REFRESH_APP_LIST_KEY: 'needRefreshAppList',
|
||||
}))
|
||||
vi.mock('@/config', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/config')>()
|
||||
return {
|
||||
...actual,
|
||||
NEED_REFRESH_APP_LIST_KEY: 'needRefreshAppList',
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/hooks/use-pay', () => ({
|
||||
CheckModal: () => null,
|
||||
|
||||
@ -259,8 +259,8 @@ describe('WorkflowMain', () => {
|
||||
expect(mockSetFeatures).toHaveBeenCalledWith(expect.objectContaining({
|
||||
file: expect.objectContaining({ enabled: true }),
|
||||
}))
|
||||
expect(mockSetConversationVariables).toHaveBeenCalledWith([{ id: 'conversation-1' }])
|
||||
expect(mockSetEnvironmentVariables).toHaveBeenCalledWith([{ id: 'env-1' }])
|
||||
expect(mockSetConversationVariables).toHaveBeenCalledWith([expect.objectContaining({ id: 'conversation-1' })])
|
||||
expect(mockSetEnvironmentVariables).toHaveBeenCalledWith([expect.objectContaining({ id: 'env-1' })])
|
||||
})
|
||||
|
||||
it('should only update the workflow store slices present in the payload', () => {
|
||||
@ -274,7 +274,7 @@ describe('WorkflowMain', () => {
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /update-conversation-only/i }))
|
||||
|
||||
expect(mockSetConversationVariables).toHaveBeenCalledWith([{ id: 'conversation-only' }])
|
||||
expect(mockSetConversationVariables).toHaveBeenCalledWith([expect.objectContaining({ id: 'conversation-only' })])
|
||||
expect(mockSetFeatures).not.toHaveBeenCalled()
|
||||
expect(mockSetEnvironmentVariables).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@ -36,6 +36,7 @@ vi.mock('@/context/app-context', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/base/ui/avatar', () => ({
|
||||
Avatar: ({ name }: { name: string }) => <div data-testid="avatar">{name}</div>,
|
||||
default: ({ name }: { name: string }) => <div data-testid="avatar">{name}</div>,
|
||||
}))
|
||||
|
||||
|
||||
@ -26,10 +26,30 @@ vi.mock('@/app/components/header/account-setting/model-provider-page/model-param
|
||||
default: () => <div data-testid="model-parameter-modal" />,
|
||||
}))
|
||||
|
||||
vi.mock('../_base/components/config-vision', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('../../_base/components/variable/var-reference-picker', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('../components/config-prompt', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('../components/panel-memory-section', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('../components/panel-output-section', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('../components/reasoning-format-config', () => ({
|
||||
default: () => null,
|
||||
}))
|
||||
|
||||
type MockUseConfigReturn = ReturnType<typeof mockUseConfig>
|
||||
|
||||
const createMockModelProvider = (provider: string): ModelProvider => ({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user