Skip to content

Commit

Permalink
Refacto: fakeStorage is duplicated
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed Dec 2, 2024
1 parent 490ec05 commit db98c1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
13 changes: 13 additions & 0 deletions src/test/webapp/unit/module/secondary/FakeStorage.fixture.ts
Original file line number Diff line number Diff line change
@@ -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],
};
};
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit db98c1f

Please sign in to comment.