mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Created Storage service test
This commit is contained in:
parent
12cddac27a
commit
fefbb73568
2 changed files with 56 additions and 0 deletions
6
indocker
6
indocker
|
@ -1,2 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Run docker container if it's not up yet
|
||||
if ! [[ $(docker ps | grep shlink_web_client_node) ]]; then
|
||||
docker-compose up -d
|
||||
fi
|
||||
|
||||
docker exec -it shlink_web_client_node /bin/sh -c "cd /home/shlink/www && $*"
|
||||
|
|
50
test/utils/services/Storage.test.js
Normal file
50
test/utils/services/Storage.test.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
import * as sinon from 'sinon';
|
||||
import Storage from '../../../src/utils/services/Storage';
|
||||
|
||||
describe('Storage', () => {
|
||||
const localStorageMock = {
|
||||
getItem: sinon.fake((key) => key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null),
|
||||
setItem: sinon.spy(),
|
||||
};
|
||||
let storage;
|
||||
|
||||
beforeEach(() => {
|
||||
localStorageMock.getItem.resetHistory();
|
||||
localStorageMock.setItem.resetHistory();
|
||||
|
||||
storage = new Storage(localStorageMock);
|
||||
});
|
||||
|
||||
describe('set', () => {
|
||||
it('writes an stringified representation of provided value in local storage', () => {
|
||||
const value = { bar: 'baz' };
|
||||
|
||||
storage.set('foo', value);
|
||||
|
||||
expect(localStorageMock.setItem.callCount).toEqual(1);
|
||||
expect(localStorageMock.setItem.getCall(0).args).toEqual([
|
||||
'shlink.foo',
|
||||
JSON.stringify(value),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
it('fetches item from local storage', () => {
|
||||
storage.get('foo');
|
||||
expect(localStorageMock.getItem.callCount).toEqual(1);
|
||||
});
|
||||
|
||||
it('returns parsed value when requested value is found in local storage', () => {
|
||||
const value = storage.get('foo');
|
||||
|
||||
expect(value).toEqual({ foo: 'bar' });
|
||||
});
|
||||
|
||||
it('returns undefined when requested value is not found in local storage', () => {
|
||||
const value = storage.get('bar');
|
||||
|
||||
expect(value).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue