1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { Container } from 'inversify';
|
18 | import { WindowService } from './window/window-service';
|
19 | import { MockWindowService } from './window/test/mock-window-service';
|
20 | import { LocalStorageService, StorageService } from './storage-service';
|
21 | import { expect } from 'chai';
|
22 | import { ILogger } from '../common/logger';
|
23 | import { MockLogger } from '../common/test/mock-logger';
|
24 | import * as sinon from 'sinon';
|
25 | import { MessageService, MessageClient } from '../common/';
|
26 |
|
27 | let storageService: StorageService;
|
28 |
|
29 | before(() => {
|
30 | const testContainer = new Container();
|
31 | testContainer.bind(ILogger).toDynamicValue(ctx => {
|
32 | const logger = new MockLogger();
|
33 | |
34 |
|
35 |
|
36 |
|
37 | sinon.stub(logger, 'warn').callsFake(async () => { });
|
38 | return logger;
|
39 | });
|
40 | testContainer.bind(StorageService).to(LocalStorageService).inSingletonScope();
|
41 | testContainer.bind(WindowService).to(MockWindowService).inSingletonScope();
|
42 | testContainer.bind(LocalStorageService).toSelf().inSingletonScope();
|
43 |
|
44 | testContainer.bind(MessageClient).toSelf().inSingletonScope();
|
45 | testContainer.bind(MessageService).toSelf().inSingletonScope();
|
46 |
|
47 | storageService = testContainer.get(StorageService);
|
48 | });
|
49 |
|
50 | describe('storage-service', () => {
|
51 |
|
52 | it('stores data', async () => {
|
53 | storageService.setData('foo', {
|
54 | test: 'foo'
|
55 | });
|
56 | expect(await storageService.getData('bar', 'bar')).equals('bar');
|
57 | expect((await storageService.getData('foo', {
|
58 | test: 'bar'
|
59 | })).test).equals('foo');
|
60 | });
|
61 |
|
62 | it('removes data', async () => {
|
63 | storageService.setData('foo', {
|
64 | test: 'foo'
|
65 | });
|
66 | expect((await storageService.getData('foo', {
|
67 | test: 'bar'
|
68 | })).test).equals('foo');
|
69 |
|
70 | storageService.setData('foo', undefined);
|
71 | expect((await storageService.getData('foo', {
|
72 | test: 'bar'
|
73 | })).test).equals('bar');
|
74 | });
|
75 |
|
76 | });
|