From: Jérôme Benoit Date: Thu, 16 Apr 2026 14:46:01 +0000 (+0200) Subject: test(web): cover abort branches in UIClient to meet coverage threshold X-Git-Tag: v4.5~66 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=39e5ae4f68f5b626aac36e2bf662e002e90109d5;p=e-mobility-charging-stations-simulator.git test(web): cover abort branches in UIClient to meet coverage threshold --- 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() }) })