use base ui toast

This commit is contained in:
yyh
2026-03-25 20:38:44 +08:00
parent a7178b4d5c
commit 20dea1faa2
274 changed files with 3597 additions and 8129 deletions

View File

@ -8,6 +8,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import * as React from 'react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { toast } from '@/app/components/base/ui/toast'
import { PluginCategoryEnum, PluginSource, TaskStatus } from '../../types'
import DowngradeWarningModal from '../downgrade-warning'
import FromGitHub from '../from-github'
@ -82,12 +83,7 @@ vi.mock('../../install-plugin/base/check-task-status', () => ({
}),
}))
// Mock Toast
vi.mock('../../../base/toast', () => ({
default: {
notify: vi.fn(),
},
}))
const toastErrorSpy = vi.spyOn(toast, 'error').mockReturnValue('toast-error')
// Mock InstallFromGitHub component
vi.mock('../../install-plugin/install-from-github', () => ({
@ -203,6 +199,7 @@ const renderWithQueryClient = (ui: React.ReactElement) => {
describe('update-plugin', () => {
beforeEach(() => {
vi.clearAllMocks()
toastErrorSpy.mockClear()
mockCheck.mockResolvedValue({ status: TaskStatus.success })
})
@ -689,9 +686,6 @@ describe('update-plugin', () => {
it('should reset loading state when task status check fails', async () => {
// Arrange
const mockToastNotify = vi.fn()
vi.mocked(await import('../../../base/toast')).default.notify = mockToastNotify
mockUpdateFromMarketPlace.mockResolvedValue({
all_installed: false,
task_id: 'task-123',
@ -718,10 +712,7 @@ describe('update-plugin', () => {
expect(mockCheck).toHaveBeenCalled()
})
await waitFor(() => {
expect(mockToastNotify).toHaveBeenCalledWith({
type: 'error',
message: 'Installation failed due to dependency conflict',
})
expect(toastErrorSpy).toHaveBeenCalledWith('Installation failed due to dependency conflict')
})
// onSave should NOT be called when task fails
expect(onSave).not.toHaveBeenCalled()
@ -733,9 +724,6 @@ describe('update-plugin', () => {
it('should stop loading when upgrade API returns failed task directly', async () => {
// Arrange
const mockToastNotify = vi.fn()
vi.mocked(await import('../../../base/toast')).default.notify = mockToastNotify
mockUpdateFromMarketPlace.mockResolvedValue({
task: {
status: TaskStatus.failed,
@ -761,10 +749,7 @@ describe('update-plugin', () => {
// Assert
await waitFor(() => {
expect(mockToastNotify).toHaveBeenCalledWith({
type: 'error',
message: 'failed to init environment',
})
expect(toastErrorSpy).toHaveBeenCalledWith('failed to init environment')
})
expect(mockCheck).not.toHaveBeenCalled()
expect(onSave).not.toHaveBeenCalled()

View File

@ -12,13 +12,13 @@ import {
DialogContent,
DialogTitle,
} from '@/app/components/base/ui/dialog'
import { toast } from '@/app/components/base/ui/toast'
import Card from '@/app/components/plugins/card'
import checkTaskStatus from '@/app/components/plugins/install-plugin/base/check-task-status'
import { pluginManifestToCardPluginProps } from '@/app/components/plugins/install-plugin/utils'
import { updateFromMarketPlace } from '@/service/plugins'
import { useInvalidateReferenceSettings, usePluginTaskList, useRemoveAutoUpgrade } from '@/service/use-plugins'
import { cn } from '@/utils/classnames'
import Toast from '../../base/toast'
import useGetIcon from '../install-plugin/base/use-get-icon'
import { TaskStatus } from '../types'
import DowngradeWarningModal from './downgrade-warning'
@ -101,10 +101,7 @@ const UpdatePluginModal: FC<Props> = ({
if (response.task?.status === TaskStatus.failed) {
const failedPlugin = response.task.plugins?.find(plugin => plugin.plugin_unique_identifier === targetPackageInfo.id)
?? response.task.plugins?.[0]
Toast.notify({
type: 'error',
message: failedPlugin?.message || t('error', { ns: 'common' }),
})
toast.error(failedPlugin?.message || t('error', { ns: 'common' }))
setUploadStep(UploadStep.notStarted)
return
}
@ -124,7 +121,7 @@ const UpdatePluginModal: FC<Props> = ({
pluginUniqueIdentifier: targetPackageInfo.id,
})
if (status === TaskStatus.failed) {
Toast.notify({ type: 'error', message: error! })
toast.error(error!)
setUploadStep(UploadStep.notStarted)
return
}