mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
refactor(web): update frontend toast call sites to use the new shortcut API (#33808)
Signed-off-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -7,8 +7,8 @@ import Actions from '../actions'
|
||||
import Form from '../form'
|
||||
import Header from '../header'
|
||||
|
||||
const { mockToastAdd } = vi.hoisted(() => ({
|
||||
mockToastAdd: vi.fn(),
|
||||
const { mockToastError } = vi.hoisted(() => ({
|
||||
mockToastError: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/base/ui/toast', async (importOriginal) => {
|
||||
@ -17,7 +17,7 @@ vi.mock('@/app/components/base/ui/toast', async (importOriginal) => {
|
||||
...actual,
|
||||
toast: {
|
||||
...actual.toast,
|
||||
add: mockToastAdd,
|
||||
error: mockToastError,
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -346,7 +346,7 @@ describe('Form', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockToastAdd.mockReset()
|
||||
mockToastError.mockReset()
|
||||
})
|
||||
|
||||
describe('Rendering', () => {
|
||||
@ -455,10 +455,7 @@ describe('Form', () => {
|
||||
|
||||
// Assert - validation error should be shown
|
||||
await waitFor(() => {
|
||||
expect(mockToastAdd).toHaveBeenCalledWith({
|
||||
type: 'error',
|
||||
title: '"field1" is required',
|
||||
})
|
||||
expect(mockToastError).toHaveBeenCalledWith('"field1" is required')
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -577,10 +574,7 @@ describe('Form', () => {
|
||||
fireEvent.submit(form)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockToastAdd).toHaveBeenCalledWith({
|
||||
type: 'error',
|
||||
title: '"field1" is required',
|
||||
})
|
||||
expect(mockToastError).toHaveBeenCalledWith('"field1" is required')
|
||||
})
|
||||
})
|
||||
|
||||
@ -594,7 +588,7 @@ describe('Form', () => {
|
||||
|
||||
// Assert - wait a bit and verify onSubmit was not called
|
||||
await waitFor(() => {
|
||||
expect(mockToastAdd).toHaveBeenCalled()
|
||||
expect(mockToastError).toHaveBeenCalled()
|
||||
})
|
||||
expect(onSubmit).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@ -4,8 +4,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { z } from 'zod'
|
||||
import Form from '../form'
|
||||
|
||||
const { mockToastAdd } = vi.hoisted(() => ({
|
||||
mockToastAdd: vi.fn(),
|
||||
const { mockToastError } = vi.hoisted(() => ({
|
||||
mockToastError: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/app/components/base/ui/toast', async (importOriginal) => {
|
||||
@ -14,7 +14,7 @@ vi.mock('@/app/components/base/ui/toast', async (importOriginal) => {
|
||||
...actual,
|
||||
toast: {
|
||||
...actual.toast,
|
||||
add: mockToastAdd,
|
||||
error: mockToastError,
|
||||
},
|
||||
}
|
||||
})
|
||||
@ -57,7 +57,7 @@ const defaultProps = {
|
||||
describe('Form (process-documents)', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mockToastAdd.mockReset()
|
||||
mockToastError.mockReset()
|
||||
})
|
||||
|
||||
// Verify basic rendering of form structure
|
||||
@ -119,12 +119,7 @@ describe('Form (process-documents)', () => {
|
||||
fireEvent.submit(form)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockToastAdd).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'error',
|
||||
title: '"name" Name is required',
|
||||
}),
|
||||
)
|
||||
expect(mockToastError).toHaveBeenCalledWith('"name" Name is required')
|
||||
})
|
||||
})
|
||||
|
||||
@ -137,7 +132,7 @@ describe('Form (process-documents)', () => {
|
||||
await waitFor(() => {
|
||||
expect(defaultProps.onSubmit).toHaveBeenCalled()
|
||||
})
|
||||
expect(mockToastAdd).not.toHaveBeenCalled()
|
||||
expect(mockToastError).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -34,10 +34,7 @@ const Form = ({
|
||||
const issues = result.error.issues
|
||||
const firstIssue = issues[0]
|
||||
const errorMessage = `"${firstIssue.path.join('.')}" ${firstIssue.message}`
|
||||
toast.add({
|
||||
type: 'error',
|
||||
title: errorMessage,
|
||||
})
|
||||
toast.error(errorMessage)
|
||||
return errorMessage
|
||||
}
|
||||
return undefined
|
||||
|
||||
Reference in New Issue
Block a user