mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 04:53:49 +00:00
Deleted SettingsService, as the task is not transparently handled by a redux middleware
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
const SETTINGS_STORAGE_KEY = 'settings';
|
|
||||||
|
|
||||||
export default class SettingsService {
|
|
||||||
constructor(storage) {
|
|
||||||
this.storage = storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadSettings = () => this.storage.get(SETTINGS_STORAGE_KEY) || {};
|
|
||||||
|
|
||||||
updateSettings = (settingsToUpdate) => this.storage.set(SETTINGS_STORAGE_KEY, {
|
|
||||||
...this.loadSettings(),
|
|
||||||
...settingsToUpdate,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import RealTimeUpdates from '../RealTimeUpdates';
|
import RealTimeUpdates from '../RealTimeUpdates';
|
||||||
import Settings from '../Settings';
|
import Settings from '../Settings';
|
||||||
import { setRealTimeUpdates } from '../reducers/settings';
|
import { setRealTimeUpdates } from '../reducers/settings';
|
||||||
import SettingsService from './SettingsService';
|
|
||||||
|
|
||||||
const provideServices = (bottle, connect) => {
|
const provideServices = (bottle, connect) => {
|
||||||
// Components
|
// Components
|
||||||
@@ -10,9 +9,6 @@ const provideServices = (bottle, connect) => {
|
|||||||
bottle.serviceFactory('RealTimeUpdates', () => RealTimeUpdates);
|
bottle.serviceFactory('RealTimeUpdates', () => RealTimeUpdates);
|
||||||
bottle.decorator('RealTimeUpdates', connect([ 'settings' ], [ 'setRealTimeUpdates' ]));
|
bottle.decorator('RealTimeUpdates', connect([ 'settings' ], [ 'setRealTimeUpdates' ]));
|
||||||
|
|
||||||
// Services
|
|
||||||
bottle.service('SettingsService', SettingsService, 'Storage');
|
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
bottle.serviceFactory('setRealTimeUpdates', () => setRealTimeUpdates);
|
bottle.serviceFactory('setRealTimeUpdates', () => setRealTimeUpdates);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
import SettingsService from '../../../src/settings/services/SettingsService';
|
|
||||||
|
|
||||||
describe('SettingsService', () => {
|
|
||||||
const settings = { foo: 'bar' };
|
|
||||||
const createService = (withSettings = true) => {
|
|
||||||
const storageMock = {
|
|
||||||
set: jest.fn(),
|
|
||||||
get: jest.fn(() => withSettings ? settings : undefined),
|
|
||||||
};
|
|
||||||
const service = new SettingsService(storageMock);
|
|
||||||
|
|
||||||
return [ service, storageMock ];
|
|
||||||
};
|
|
||||||
|
|
||||||
afterEach(jest.resetAllMocks);
|
|
||||||
|
|
||||||
describe('loadSettings', () => {
|
|
||||||
it.each([
|
|
||||||
[ false, {}],
|
|
||||||
[ true, settings ],
|
|
||||||
])('returns result if found in storage', (withSettings, expectedResult) => {
|
|
||||||
const [ service, storageMock ] = createService(withSettings);
|
|
||||||
|
|
||||||
const result = service.loadSettings();
|
|
||||||
|
|
||||||
expect(result).toEqual(expectedResult);
|
|
||||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
|
||||||
expect(storageMock.set).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('updateSettings', () => {
|
|
||||||
it.each([
|
|
||||||
[ false, { hi: 'goodbye' }, { hi: 'goodbye' }],
|
|
||||||
[ true, { hi: 'goodbye' }, { foo: 'bar', hi: 'goodbye' }],
|
|
||||||
[ true, { foo: 'goodbye' }, { foo: 'goodbye' }],
|
|
||||||
])('appends provided data to existing settings', (withSettings, settingsToUpdate, expectedResult) => {
|
|
||||||
const [ service, storageMock ] = createService(withSettings);
|
|
||||||
|
|
||||||
service.updateSettings(settingsToUpdate);
|
|
||||||
|
|
||||||
expect(storageMock.get).toHaveBeenCalledTimes(1);
|
|
||||||
expect(storageMock.set).toHaveBeenCalledWith(expect.anything(), expectedResult);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user