From 39e5ae4f68f5b626aac36e2bf662e002e90109d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 16 Apr 2026 16:46:01 +0200 Subject: [PATCH] test(web): cover abort branches in UIClient to meet coverage threshold --- ui/web/tests/unit/UIClient.test.ts | 34 ++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/ui/web/tests/unit/UIClient.test.ts b/ui/web/tests/unit/UIClient.test.ts index 81429aa6..fd104b7a 100644 --- a/ui/web/tests/unit/UIClient.test.ts +++ b/ui/web/tests/unit/UIClient.test.ts @@ -432,17 +432,43 @@ describe('UIClient', () => { }) describe('setConfiguration', () => { - it('should close existing WebSocket and open new connection', () => { - const client = UIClient.getInstance(createUIServerConfig()) - const oldWs = MockWebSocket.lastInstance! + let client: UIClient + let oldWs: MockWebSocket + + beforeEach(() => { + client = UIClient.getInstance(createUIServerConfig()) + oldWs = MockWebSocket.lastInstance! oldWs.simulateOpen() + }) + it('should close existing WebSocket and open new connection', () => { client.setConfiguration(createUIServerConfig({ port: 9090 })) expect(oldWs.close).toHaveBeenCalled() const newWs = MockWebSocket.lastInstance! expect(newWs).not.toBe(oldWs) - expect(newWs.url).toBe('ws://localhost:9090') + }) + + it('should suppress close events from old connection', () => { + client.setConfiguration(createUIServerConfig({ port: 9090 })) + oldWs.simulateClose() + expect(toastMock.info).not.toHaveBeenCalled() + }) + + it('should suppress error events from old connection', () => { + const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined) + client.setConfiguration(createUIServerConfig({ port: 9090 })) + oldWs.simulateError() + expect(toastMock.error).not.toHaveBeenCalled() + expect(consoleSpy).not.toHaveBeenCalled() + consoleSpy.mockRestore() + }) + + it('should suppress open events from old connection', () => { + toastMock.success.mockClear() + client.setConfiguration(createUIServerConfig({ port: 9090 })) + oldWs.simulateOpen() + expect(toastMock.success).not.toHaveBeenCalled() }) }) -- 2.43.0