]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test(web): cover abort branches in UIClient to meet coverage threshold
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 16 Apr 2026 14:46:01 +0000 (16:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 16 Apr 2026 15:03:54 +0000 (17:03 +0200)
ui/web/tests/unit/UIClient.test.ts

index 81429aa699a743063affe45b37874eb6ab3f9e49..fd104b7af7e3a8e2d936f816d83df6774865e72b 100644 (file)
@@ -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()
     })
   })