mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-05-04 10:43:01 +03:00
Created utils test
This commit is contained in:
parent
8b8be2d7ca
commit
bb6fb6b9ea
2 changed files with 72 additions and 5 deletions
test/utils
60
test/utils/utils.test.js
Normal file
60
test/utils/utils.test.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
import * as sinon from 'sinon';
|
||||
import L from 'leaflet';
|
||||
import marker2x from 'leaflet/dist/images/marker-icon-2x.png';
|
||||
import marker from 'leaflet/dist/images/marker-icon.png';
|
||||
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
|
||||
import { stateFlagTimeout as stateFlagTimeoutFactory, determineOrderDir, fixLeafletIcons } from '../../src/utils/utils';
|
||||
|
||||
describe('utils', () => {
|
||||
describe('stateFlagTimeout', () => {
|
||||
it('sets state and initializes timeout with provided delay', () => {
|
||||
const setTimeout = sinon.fake((callback) => callback());
|
||||
const setState = sinon.spy();
|
||||
const stateFlagTimeout = stateFlagTimeoutFactory(setTimeout);
|
||||
const delay = 5000;
|
||||
const expectedSetStateCalls = 2;
|
||||
|
||||
stateFlagTimeout(setState, 'foo', false, delay);
|
||||
|
||||
expect(setState.callCount).toEqual(expectedSetStateCalls);
|
||||
expect(setState.getCall(0).args).toEqual([{ foo: false }]);
|
||||
expect(setState.getCall(1).args).toEqual([{ foo: true }]);
|
||||
expect(setTimeout.callCount).toEqual(1);
|
||||
expect(setTimeout.getCall(0).args[1]).toEqual(delay);
|
||||
});
|
||||
});
|
||||
|
||||
describe('determineOrderDir', () => {
|
||||
it('returns ASC when current order field and selected field are different', () => {
|
||||
expect(determineOrderDir('foo', 'bar')).toEqual('ASC');
|
||||
expect(determineOrderDir('bar', 'foo')).toEqual('ASC');
|
||||
});
|
||||
|
||||
it('returns ASC when no current order dir is provided', () => {
|
||||
expect(determineOrderDir('foo', 'foo')).toEqual('ASC');
|
||||
expect(determineOrderDir('bar', 'bar')).toEqual('ASC');
|
||||
});
|
||||
|
||||
it('returns DESC when current order field and selected field are equal and current order dir is ASC', () => {
|
||||
expect(determineOrderDir('foo', 'foo', 'ASC')).toEqual('DESC');
|
||||
expect(determineOrderDir('bar', 'bar', 'ASC')).toEqual('DESC');
|
||||
});
|
||||
|
||||
it('returns undefined when current order field and selected field are equal and current order dir is DESC', () => {
|
||||
expect(determineOrderDir('foo', 'foo', 'DESC')).toBeUndefined();
|
||||
expect(determineOrderDir('bar', 'bar', 'DESC')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('fixLeafletIcons', () => {
|
||||
it('updates icons used by leaflet', () => {
|
||||
fixLeafletIcons();
|
||||
|
||||
const { iconRetinaUrl, iconUrl, shadowUrl } = L.Icon.Default.prototype.options;
|
||||
|
||||
expect(iconRetinaUrl).toEqual(marker2x);
|
||||
expect(iconUrl).toEqual(marker);
|
||||
expect(shadowUrl).toEqual(markerShadow);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue