UNPKG

3.31 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const inversify_1 = require("inversify");
19const window_service_1 = require("./window/window-service");
20const mock_window_service_1 = require("./window/test/mock-window-service");
21const storage_service_1 = require("./storage-service");
22const chai_1 = require("chai");
23const logger_1 = require("../common/logger");
24const mock_logger_1 = require("../common/test/mock-logger");
25const sinon = require("sinon");
26const common_1 = require("../common/");
27let storageService;
28before(() => {
29 const testContainer = new inversify_1.Container();
30 testContainer.bind(logger_1.ILogger).toDynamicValue(ctx => {
31 const logger = new mock_logger_1.MockLogger();
32 /* Note this is not really needed but here we could just use the
33 MockLogger since it does what we need but this is there as a demo of
34 sinon for other uses-cases. We can remove this once this technique is
35 more generally used. */
36 sinon.stub(logger, 'warn').callsFake(async () => { });
37 return logger;
38 });
39 testContainer.bind(storage_service_1.StorageService).to(storage_service_1.LocalStorageService).inSingletonScope();
40 testContainer.bind(window_service_1.WindowService).to(mock_window_service_1.MockWindowService).inSingletonScope();
41 testContainer.bind(storage_service_1.LocalStorageService).toSelf().inSingletonScope();
42 testContainer.bind(common_1.MessageClient).toSelf().inSingletonScope();
43 testContainer.bind(common_1.MessageService).toSelf().inSingletonScope();
44 storageService = testContainer.get(storage_service_1.StorageService);
45});
46describe('storage-service', () => {
47 it('stores data', async () => {
48 storageService.setData('foo', {
49 test: 'foo'
50 });
51 (0, chai_1.expect)(await storageService.getData('bar', 'bar')).equals('bar');
52 (0, chai_1.expect)((await storageService.getData('foo', {
53 test: 'bar'
54 })).test).equals('foo');
55 });
56 it('removes data', async () => {
57 storageService.setData('foo', {
58 test: 'foo'
59 });
60 (0, chai_1.expect)((await storageService.getData('foo', {
61 test: 'bar'
62 })).test).equals('foo');
63 storageService.setData('foo', undefined);
64 (0, chai_1.expect)((await storageService.getData('foo', {
65 test: 'bar'
66 })).test).equals('bar');
67 });
68});
69//# sourceMappingURL=storage-service.spec.js.map
\No newline at end of file