From 6aa3ca6b3d9bdb88daf27a6bb5258e99cec92dc6 Mon Sep 17 00:00:00 2001 From: Abhijay Jain Date: Wed, 12 Aug 2026 13:50:59 +0530 Subject: [PATCH] fix(ui): suppress extension loading toast when all extensions succeed (#11016) Signed-off-by: Abhijay Jain --- .../src/utils/extensionErrorUtils.test.ts | 49 +++++++++++++++++++ ui/desktop/src/utils/extensionErrorUtils.ts | 5 ++ 2 files changed, 54 insertions(+) create mode 100644 ui/desktop/src/utils/extensionErrorUtils.test.ts diff --git a/ui/desktop/src/utils/extensionErrorUtils.test.ts b/ui/desktop/src/utils/extensionErrorUtils.test.ts new file mode 100644 index 000000000..e5108912f --- /dev/null +++ b/ui/desktop/src/utils/extensionErrorUtils.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { showExtensionLoadResults } from './extensionErrorUtils'; + +vi.mock('../toasts', () => ({ + toastService: { + error: vi.fn(), + extensionLoading: vi.fn(), + dismiss: vi.fn(), + }, +})); + +import { toastService } from '../toasts'; + +describe('showExtensionLoadResults', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('shows nothing when results are empty', () => { + showExtensionLoadResults([]); + expect(toastService.error).not.toHaveBeenCalled(); + expect(toastService.extensionLoading).not.toHaveBeenCalled(); + }); + + it('dismisses stale toast when all extensions succeed', () => { + showExtensionLoadResults([ + { name: 'ext-a', success: true }, + { name: 'ext-b', success: true }, + ]); + expect(toastService.dismiss).toHaveBeenCalledWith('extension-loading'); + expect(toastService.error).not.toHaveBeenCalled(); + expect(toastService.extensionLoading).not.toHaveBeenCalled(); + }); + + it('shows individual error toast for a single failed extension', () => { + showExtensionLoadResults([{ name: 'ext-a', success: false, error: 'connection refused' }]); + expect(toastService.error).toHaveBeenCalledOnce(); + expect(toastService.extensionLoading).not.toHaveBeenCalled(); + }); + + it('shows grouped toast when multiple extensions load and at least one fails', () => { + showExtensionLoadResults([ + { name: 'ext-a', success: true }, + { name: 'ext-b', success: false, error: 'timeout' }, + ]); + expect(toastService.extensionLoading).toHaveBeenCalledOnce(); + expect(toastService.error).not.toHaveBeenCalled(); + }); +}); diff --git a/ui/desktop/src/utils/extensionErrorUtils.ts b/ui/desktop/src/utils/extensionErrorUtils.ts index 0b3a8536a..bd473c754 100644 --- a/ui/desktop/src/utils/extensionErrorUtils.ts +++ b/ui/desktop/src/utils/extensionErrorUtils.ts @@ -44,6 +44,11 @@ export function showExtensionLoadResults(results: ExtensionLoadResult[] | null | const failedExtensions = results.filter((r) => !r.success); + if (failedExtensions.length === 0) { + toastService.dismiss('extension-loading'); + return; + } + if (results.length === 1 && failedExtensions.length === 1) { const failed = failedExtensions[0]; const errorMsg = failed.error || 'Unknown error';