Skip to content

Commit

Permalink
Merge pull request #11486 from qmonmert/refactoduplication
Browse files Browse the repository at this point in the history
Refacto: fakeStorage is duplicated
  • Loading branch information
murdos authored Dec 2, 2024
2 parents 9a6a112 + db98c1f commit 0a843ed
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 0a843ed

Please sign in to comment.