From db98c1f0779b6e13153f628c4fefeb18095d2156 Mon Sep 17 00:00:00 2001 From: Quentin Date: Mon, 2 Dec 2024 17:37:03 +0100 Subject: [PATCH] Refacto: fakeStorage is duplicated --- .../unit/module/secondary/FakeStorage.fixture.ts | 13 +++++++++++++ ...LocalStorageModuleParametersRepository.spec.ts | 15 +-------------- .../secondary/LocalWindowThemeRepository.spec.ts | 15 +-------------- 3 files changed, 15 insertions(+), 28 deletions(-) create mode 100644 src/test/webapp/unit/module/secondary/FakeStorage.fixture.ts diff --git a/src/test/webapp/unit/module/secondary/FakeStorage.fixture.ts b/src/test/webapp/unit/module/secondary/FakeStorage.fixture.ts new file mode 100644 index 00000000000..df04fa88f59 --- /dev/null +++ b/src/test/webapp/unit/module/secondary/FakeStorage.fixture.ts @@ -0,0 +1,13 @@ +export const fakeStorage = (): Storage => { + let store: { [key: string]: string } = {}; + return { + getItem: (key: string) => store[key], + setItem: (key: string, value: string) => (store[key] = value), + removeItem: (key: string) => delete store[key], + clear: () => (store = {}), + get length() { + return Object.keys(store).length; + }, + key: (index: number) => Object.keys(store)[index], + }; +}; diff --git a/src/test/webapp/unit/module/secondary/LocalStorageModuleParametersRepository.spec.ts b/src/test/webapp/unit/module/secondary/LocalStorageModuleParametersRepository.spec.ts index 7f7bdba96c6..c061c10dcf2 100644 --- a/src/test/webapp/unit/module/secondary/LocalStorageModuleParametersRepository.spec.ts +++ b/src/test/webapp/unit/module/secondary/LocalStorageModuleParametersRepository.spec.ts @@ -1,20 +1,7 @@ import { ModuleParameterType } from '@/module/domain/ModuleParameters'; import { LocalStorageModuleParametersRepository } from '@/module/secondary/LocalStorageModuleParametersRepository'; import { describe, expect, it } from 'vitest'; - -const fakeStorage = (): Storage => { - let store: { [key: string]: string } = {}; - return { - getItem: (key: string) => store[key], - setItem: (key: string, value: string) => (store[key] = value), - removeItem: (key: string) => delete store[key], - clear: () => (store = {}), - get length() { - return Object.keys(store).length; - }, - key: (index: number) => Object.keys(store)[index], - }; -}; +import { fakeStorage } from './FakeStorage.fixture'; const STORAGE_KEY_MODULE_PARAMETERS_SUFFIX = '_moduleParameters'; const STORAGE_KEY_CURRENT_FOLDER_PATH = 'currentFolderPath'; diff --git a/src/test/webapp/unit/module/secondary/LocalWindowThemeRepository.spec.ts b/src/test/webapp/unit/module/secondary/LocalWindowThemeRepository.spec.ts index 83f582e1d83..5829c7d1871 100644 --- a/src/test/webapp/unit/module/secondary/LocalWindowThemeRepository.spec.ts +++ b/src/test/webapp/unit/module/secondary/LocalWindowThemeRepository.spec.ts @@ -1,20 +1,7 @@ import { LocalWindowThemeRepository } from '@/module/secondary/LocalWindowThemeRepository'; import { describe, expect, it } from 'vitest'; import { stubWindow } from '../primary/GlobalWindow.fixture'; - -const fakeStorage = (): Storage => { - let store: { [key: string]: string } = {}; - return { - getItem: (key: string) => store[key], - setItem: (key: string, value: string) => (store[key] = value), - removeItem: (key: string) => delete store[key], - clear: () => (store = {}), - get length() { - return Object.keys(store).length; - }, - key: (index: number) => Object.keys(store)[index], - }; -}; +import { fakeStorage } from './FakeStorage.fixture'; describe('LocalWindowThemeRepository', () => { it('should return light theme if no user theme preference stored in localStorage', () => {