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:
yyh
2026-03-20 16:02:22 +08:00
committed by GitHub
parent ac87704685
commit 27ed40225d
75 changed files with 391 additions and 706 deletions

View File

@ -4,7 +4,8 @@ import { DeleteConfirm } from '../delete-confirm'
const mockRefetch = vi.fn()
const mockDelete = vi.fn()
const mockToastAdd = vi.hoisted(() => vi.fn())
const mockToastSuccess = vi.hoisted(() => vi.fn())
const mockToastError = vi.hoisted(() => vi.fn())
vi.mock('../use-subscription-list', () => ({
useSubscriptionList: () => ({ refetch: mockRefetch }),
@ -14,11 +15,17 @@ vi.mock('@/service/use-triggers', () => ({
useDeleteTriggerSubscription: () => ({ mutate: mockDelete, isPending: false }),
}))
vi.mock('@/app/components/base/ui/toast', () => ({
toast: {
add: mockToastAdd,
},
}))
vi.mock('@/app/components/base/ui/toast', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/app/components/base/ui/toast')>()
return {
...actual,
toast: {
...actual.toast,
success: mockToastSuccess,
error: mockToastError,
},
}
})
beforeEach(() => {
vi.clearAllMocks()
@ -42,7 +49,7 @@ describe('DeleteConfirm', () => {
fireEvent.click(screen.getByRole('button', { name: /pluginTrigger\.subscription\.list\.item\.actions\.deleteConfirm\.confirm/ }))
expect(mockDelete).not.toHaveBeenCalled()
expect(mockToastAdd).toHaveBeenCalledWith(expect.objectContaining({ type: 'error' }))
expect(mockToastError).toHaveBeenCalledWith('pluginTrigger.subscription.list.item.actions.deleteConfirm.confirmInputWarning')
})
it('should allow deletion after matching input name', () => {
@ -87,6 +94,6 @@ describe('DeleteConfirm', () => {
fireEvent.click(screen.getByRole('button', { name: /pluginTrigger\.subscription\.list\.item\.actions\.deleteConfirm\.confirm/ }))
expect(mockToastAdd).toHaveBeenCalledWith(expect.objectContaining({ type: 'error', title: 'network error' }))
expect(mockToastError).toHaveBeenCalledWith('network error')
})
})

View File

@ -41,26 +41,17 @@ export const DeleteConfirm = (props: Props) => {
const onConfirm = () => {
if (workflowsInUse > 0 && inputName !== currentName) {
toast.add({
type: 'error',
title: t(`${tPrefix}.confirmInputWarning`, { ns: 'pluginTrigger' }),
})
toast.error(t(`${tPrefix}.confirmInputWarning`, { ns: 'pluginTrigger' }))
return
}
deleteSubscription(currentId, {
onSuccess: () => {
toast.add({
type: 'success',
title: t(`${tPrefix}.success`, { ns: 'pluginTrigger', name: currentName }),
})
toast.success(t(`${tPrefix}.success`, { ns: 'pluginTrigger', name: currentName }))
refetch?.()
onClose(true)
},
onError: (error: unknown) => {
toast.add({
type: 'error',
title: error instanceof Error ? error.message : t(`${tPrefix}.error`, { ns: 'pluginTrigger', name: currentName }),
})
toast.error(error instanceof Error ? error.message : t(`${tPrefix}.error`, { ns: 'pluginTrigger', name: currentName }))
},
})
}