From 895b9635fc5e6756e1f822298cca4355f2515849 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 4 Apr 2026 01:15:41 +0200 Subject: [PATCH] refactor(ui): use EMPTY_VALUE_PLACEHOLDER in Utils.ts and test assertions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Replace remaining hardcoded 'Ø' in getWebSocketStateName() and 4 test assertions with the centralized EMPTY_VALUE_PLACEHOLDER constant. Consolidate duplicate Constants import in Utils.ts. --- ui/web/src/composables/Utils.ts | 10 +++++++--- ui/web/tests/unit/CSConnector.test.ts | 3 ++- ui/web/tests/unit/CSData.test.ts | 7 ++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index 99a4ee51..11d6f7de 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -5,7 +5,11 @@ import { useToast } from 'vue-toast-notification' import type { ChargingStationData, ConfigurationData, UUIDv4 } from '@/types' -import { SHARED_TOGGLE_BUTTON_KEY_PREFIX, TOGGLE_BUTTON_KEY_PREFIX } from './Constants' +import { + EMPTY_VALUE_PLACEHOLDER, + SHARED_TOGGLE_BUTTON_KEY_PREFIX, + TOGGLE_BUTTON_KEY_PREFIX, +} from './Constants' import { UIClient } from './UIClient' export const configurationKey: InjectionKey> = Symbol('configuration') @@ -88,7 +92,7 @@ export const deleteLocalStorageByKeyPattern = (pattern: string): void => { /** * Returns a human-readable name for a WebSocket ready state. * @param state - The WebSocket readyState value - * @returns The state name or 'Ø' for unknown/undefined states + * @returns The state name or EMPTY_VALUE_PLACEHOLDER for unknown/undefined states */ export const getWebSocketStateName = (state: number | undefined): string => { switch (state) { @@ -101,7 +105,7 @@ export const getWebSocketStateName = (state: number | undefined): string => { case WebSocket.OPEN: return 'Open' default: - return 'Ø' + return EMPTY_VALUE_PLACEHOLDER } } diff --git a/ui/web/tests/unit/CSConnector.test.ts b/ui/web/tests/unit/CSConnector.test.ts index 14e70ee3..a24f7969 100644 --- a/ui/web/tests/unit/CSConnector.test.ts +++ b/ui/web/tests/unit/CSConnector.test.ts @@ -9,6 +9,7 @@ import type { UIClient } from '@/composables' import CSConnector from '@/components/charging-stations/CSConnector.vue' import { useUIClient } from '@/composables' +import { EMPTY_VALUE_PLACEHOLDER } from '@/composables/Constants' import { OCPP16ChargePointStatus } from '@/types' import { toastMock } from '../setup' @@ -78,7 +79,7 @@ describe('CSConnector', () => { connector: createConnectorStatus({ status: undefined }), }) const cells = wrapper.findAll('td') - expect(cells[1].text()).toBe('Ø') + expect(cells[1].text()).toBe(EMPTY_VALUE_PLACEHOLDER) }) it('should display No when transaction not started', () => { diff --git a/ui/web/tests/unit/CSData.test.ts b/ui/web/tests/unit/CSData.test.ts index 303c1cd1..900d472b 100644 --- a/ui/web/tests/unit/CSData.test.ts +++ b/ui/web/tests/unit/CSData.test.ts @@ -11,6 +11,7 @@ import type { ChargingStationData } from '@/types' import CSConnector from '@/components/charging-stations/CSConnector.vue' import CSData from '@/components/charging-stations/CSData.vue' import { useUIClient } from '@/composables' +import { EMPTY_VALUE_PLACEHOLDER } from '@/composables/Constants' import { OCPPVersion } from '@/types' import { toastMock } from '../setup' @@ -94,7 +95,7 @@ describe('CSData', () => { }) const wrapper = mountCSData(station) const cells = wrapper.findAll('td') - expect(cells[9].text()).toBe('Ø') + expect(cells[9].text()).toBe(EMPTY_VALUE_PLACEHOLDER) }) it('should display WebSocket state as Open when OPEN', () => { @@ -112,7 +113,7 @@ describe('CSData', () => { it('should display WebSocket state as Ø for undefined state', () => { const wrapper = mountCSData(createChargingStationData({ wsState: undefined })) const cells = wrapper.findAll('td') - expect(cells[3].text()).toBe('Ø') + expect(cells[3].text()).toBe(EMPTY_VALUE_PLACEHOLDER) }) it('should display registration status', () => { @@ -124,7 +125,7 @@ describe('CSData', () => { const station = createChargingStationData({ bootNotificationResponse: undefined }) const wrapper = mountCSData(station) const cells = wrapper.findAll('td') - expect(cells[4].text()).toBe('Ø') + expect(cells[4].text()).toBe(EMPTY_VALUE_PLACEHOLDER) }) it('should display WebSocket state as Connecting when CONNECTING', () => { -- 2.43.0