Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / lib / settings / service.spec.ts
blob3dd5e932bc1e4b1133e1cc8878b863c1a6590091
1 import { getInitialSettings } from '@proton/pass/store/reducers/settings';
3 import { createSettingsService } from './service';
5 describe('createSettingsService', () => {
6     const clear = jest.fn();
7     const resolve = jest.fn();
8     const sync = jest.fn();
10     beforeEach(() => {
11         clear.mockClear();
12         resolve.mockClear();
13         sync.mockClear();
14     });
16     test('clear method should proxy `options.clear`', async () => {
17         const service = createSettingsService({ clear, resolve, sync });
18         await service.clear();
20         expect(clear).toHaveBeenCalledTimes(1);
21     });
23     test('sync method should proxy `options.sync`', async () => {
24         const update = getInitialSettings();
25         const service = createSettingsService({ clear, resolve, sync });
26         await service.sync(update);
28         expect(sync).toHaveBeenCalledTimes(1);
29         expect(sync).toHaveBeenCalledWith(update);
30     });
32     test('resolve method should merge initial settings with resolved settings', async () => {
33         const settings = { test_setting: true };
34         resolve.mockResolvedValue(settings);
36         const service = createSettingsService({ clear, resolve, sync });
37         const result = await service.resolve();
39         expect(resolve).toHaveBeenCalledTimes(1);
40         expect(result).toEqual({ ...getInitialSettings(), ...settings });
41     });
43     test('resolve should return initial settings when `options.resolve` fails', async () => {
44         resolve.mockRejectedValue(new Error());
45         const service = createSettingsService({ clear, resolve, sync });
46         const result = await service.resolve();
48         expect(resolve).toHaveBeenCalledTimes(1);
49         expect(result).toEqual(getInitialSettings());
50     });
51 });