mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 09:33:51 +00:00
Updated to airbnb coding styles
This commit is contained in:
@@ -6,13 +6,13 @@ describe('date', () => {
|
||||
|
||||
describe('formatDate', () => {
|
||||
it.each([
|
||||
[ parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'), 'dd/MM/yyyy', '05/03/2020' ],
|
||||
[ parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'), 'yyyy-MM', '2020-03' ],
|
||||
[ parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'), undefined, '2020-03-05' ],
|
||||
[ '2020-03-05 10:00:10', 'dd-MM-yyyy', '2020-03-05 10:00:10' ],
|
||||
[ '2020-03-05 10:00:10', undefined, '2020-03-05 10:00:10' ],
|
||||
[ undefined, undefined, undefined ],
|
||||
[ null, undefined, null ],
|
||||
[parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'), 'dd/MM/yyyy', '05/03/2020'],
|
||||
[parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'), 'yyyy-MM', '2020-03'],
|
||||
[parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'), undefined, '2020-03-05'],
|
||||
['2020-03-05 10:00:10', 'dd-MM-yyyy', '2020-03-05 10:00:10'],
|
||||
['2020-03-05 10:00:10', undefined, '2020-03-05 10:00:10'],
|
||||
[undefined, undefined, undefined],
|
||||
[null, undefined, null],
|
||||
])('formats date as expected', (date, format, expected) => {
|
||||
expect(formatDate(format)(date)).toEqual(expected);
|
||||
});
|
||||
@@ -24,10 +24,10 @@ describe('date', () => {
|
||||
parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss'),
|
||||
formatISO(parseDate('2020-03-05 10:00:10', 'yyyy-MM-dd HH:mm:ss')),
|
||||
],
|
||||
[ '2020-03-05 10:00:10', '2020-03-05 10:00:10' ],
|
||||
[ 'foo', 'foo' ],
|
||||
[ undefined, undefined ],
|
||||
[ null, null ],
|
||||
['2020-03-05 10:00:10', '2020-03-05 10:00:10'],
|
||||
['foo', 'foo'],
|
||||
[undefined, undefined],
|
||||
[null, null],
|
||||
])('formats date as expected', (date, expected) => {
|
||||
expect(formatIsoDate(date)).toEqual(expected);
|
||||
});
|
||||
@@ -35,17 +35,17 @@ describe('date', () => {
|
||||
|
||||
describe('isBetween', () => {
|
||||
it.each([
|
||||
[ now, undefined, undefined, true ],
|
||||
[ now, subDays(now, 1), undefined, true ],
|
||||
[ now, now, undefined, true ],
|
||||
[ now, undefined, addDays(now, 1), true ],
|
||||
[ now, undefined, now, true ],
|
||||
[ now, subDays(now, 1), addDays(now, 1), true ],
|
||||
[ now, now, now, true ],
|
||||
[ now, addDays(now, 1), undefined, false ],
|
||||
[ now, undefined, subDays(now, 1), false ],
|
||||
[ now, subDays(now, 3), subDays(now, 1), false ],
|
||||
[ now, addDays(now, 1), addDays(now, 3), false ],
|
||||
[now, undefined, undefined, true],
|
||||
[now, subDays(now, 1), undefined, true],
|
||||
[now, now, undefined, true],
|
||||
[now, undefined, addDays(now, 1), true],
|
||||
[now, undefined, now, true],
|
||||
[now, subDays(now, 1), addDays(now, 1), true],
|
||||
[now, now, now, true],
|
||||
[now, addDays(now, 1), undefined, false],
|
||||
[now, undefined, subDays(now, 1), false],
|
||||
[now, subDays(now, 3), subDays(now, 1), false],
|
||||
[now, addDays(now, 1), addDays(now, 3), false],
|
||||
])('returns true when a date is between provided range', (date, start, end, expectedResult) => {
|
||||
expect(isBetween(date, start, end)).toEqual(expectedResult);
|
||||
});
|
||||
@@ -53,9 +53,9 @@ describe('date', () => {
|
||||
|
||||
describe('isBeforeOrEqual', () => {
|
||||
it.each([
|
||||
[ now, now, true ],
|
||||
[ now, addDays(now, 1), true ],
|
||||
[ now, subDays(now, 1), false ],
|
||||
[now, now, true],
|
||||
[now, addDays(now, 1), true],
|
||||
[now, subDays(now, 1), false],
|
||||
])('returns true when the date before or equal to provided one', (date, dateToCompare, expectedResult) => {
|
||||
expect(isBeforeOrEqual(date, dateToCompare)).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
@@ -4,15 +4,15 @@ describe('numbers', () => {
|
||||
describe('roundTen', () => {
|
||||
it('rounds provided number to the next multiple of ten', () => {
|
||||
const expectationsPairs = [
|
||||
[ 10, 10 ],
|
||||
[ 12, 20 ],
|
||||
[ 158, 160 ],
|
||||
[ 5, 10 ],
|
||||
[ -42, -40 ],
|
||||
[10, 10],
|
||||
[12, 20],
|
||||
[158, 160],
|
||||
[5, 10],
|
||||
[-42, -40],
|
||||
];
|
||||
|
||||
expect.assertions(expectationsPairs.length);
|
||||
expectationsPairs.forEach(([ number, expected ]) => {
|
||||
expectationsPairs.forEach(([number, expected]) => {
|
||||
expect(roundTen(number)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,10 +25,10 @@ describe('ordering', () => {
|
||||
|
||||
describe('orderToString', () => {
|
||||
it.each([
|
||||
[{}, undefined ],
|
||||
[{ field: 'foo' }, undefined ],
|
||||
[{ field: 'foo', dir: 'ASC' as OrderDir }, 'foo-ASC' ],
|
||||
[{ field: 'bar', dir: 'DESC' as OrderDir }, 'bar-DESC' ],
|
||||
[{}, undefined],
|
||||
[{ field: 'foo' }, undefined],
|
||||
[{ field: 'foo', dir: 'ASC' as OrderDir }, 'foo-ASC'],
|
||||
[{ field: 'bar', dir: 'DESC' as OrderDir }, 'bar-DESC'],
|
||||
])('casts the order to string', (order, expectedResult) => {
|
||||
expect(orderToString(order)).toEqual(expectedResult);
|
||||
});
|
||||
@@ -36,8 +36,8 @@ describe('ordering', () => {
|
||||
|
||||
describe('stringToOrder', () => {
|
||||
it.each([
|
||||
[ 'foo-ASC', { field: 'foo', dir: 'ASC' }],
|
||||
[ 'bar-DESC', { field: 'bar', dir: 'DESC' }],
|
||||
['foo-ASC', { field: 'foo', dir: 'ASC' }],
|
||||
['bar-DESC', { field: 'bar', dir: 'DESC' }],
|
||||
])('casts a string to an order objects', (order, expectedResult) => {
|
||||
expect(stringToOrder(order)).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
@@ -3,10 +3,10 @@ import { parseQuery, stringifyQuery } from '../../../src/utils/helpers/query';
|
||||
describe('query', () => {
|
||||
describe('parseQuery', () => {
|
||||
it.each([
|
||||
[ '', {}],
|
||||
[ 'foo=bar', { foo: 'bar' }],
|
||||
[ '?foo=bar', { foo: 'bar' }],
|
||||
[ '?foo=bar&baz=123', { foo: 'bar', baz: '123' }],
|
||||
['', {}],
|
||||
['foo=bar', { foo: 'bar' }],
|
||||
['?foo=bar', { foo: 'bar' }],
|
||||
['?foo=bar&baz=123', { foo: 'bar', baz: '123' }],
|
||||
])('parses query string as expected', (queryString, expectedResult) => {
|
||||
expect(parseQuery(queryString)).toEqual(expectedResult);
|
||||
});
|
||||
@@ -14,10 +14,10 @@ describe('query', () => {
|
||||
|
||||
describe('stringifyQuery', () => {
|
||||
it.each([
|
||||
[{}, '' ],
|
||||
[{ foo: 'bar' }, 'foo=bar' ],
|
||||
[{ foo: 'bar', baz: '123' }, 'foo=bar&baz=123' ],
|
||||
[{ bar: 'foo', list: [ 'one', 'two' ] }, encodeURI('bar=foo&list[]=one&list[]=two') ],
|
||||
[{}, ''],
|
||||
[{ foo: 'bar' }, 'foo=bar'],
|
||||
[{ foo: 'bar', baz: '123' }, 'foo=bar&baz=123'],
|
||||
[{ bar: 'foo', list: ['one', 'two'] }, encodeURI('bar=foo&list[]=one&list[]=two')],
|
||||
])('stringifies query as expected', (queryObj, expectedResult) => {
|
||||
expect(stringifyQuery(queryObj)).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
@@ -6,9 +6,9 @@ describe('redux', () => {
|
||||
|
||||
describe('buildActionCreator', () => {
|
||||
it.each([
|
||||
[ 'foo', { type: 'foo' }],
|
||||
[ 'bar', { type: 'bar' }],
|
||||
[ 'something', { type: 'something' }],
|
||||
['foo', { type: 'foo' }],
|
||||
['bar', { type: 'bar' }],
|
||||
['something', { type: 'something' }],
|
||||
])('returns an action creator', (type, expected) => {
|
||||
const actionCreator = buildActionCreator(type);
|
||||
|
||||
@@ -37,8 +37,8 @@ describe('redux', () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ 'foo', 'foo result', fooActionHandler, barActionHandler ],
|
||||
[ 'bar', 'bar result', barActionHandler, fooActionHandler ],
|
||||
['foo', 'foo result', fooActionHandler, barActionHandler],
|
||||
['bar', 'bar result', barActionHandler, fooActionHandler],
|
||||
])(
|
||||
'returns a reducer which calls corresponding action handler',
|
||||
(type, expected, invokedActionHandler, notInvokedActionHandler) => {
|
||||
@@ -49,9 +49,9 @@ describe('redux', () => {
|
||||
);
|
||||
|
||||
it.each([
|
||||
[ undefined, initialState ],
|
||||
[ 'foo', 'foo' ],
|
||||
[ 'something', 'something' ],
|
||||
[undefined, initialState],
|
||||
['foo', 'foo'],
|
||||
['something', 'something'],
|
||||
])('returns a reducer which calls action handler with provided state or initial', (state, expected) => {
|
||||
reducer(state, { type: 'foo' });
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ import { replaceAuthorityFromUri } from '../../../src/utils/helpers/uri';
|
||||
describe('uri-helper', () => {
|
||||
describe('replaceAuthorityFromUri', () => {
|
||||
it.each([
|
||||
[ 'http://something.com/foo/bar', 'www.new.to', 'http://www.new.to/foo/bar' ],
|
||||
[ 'https://www.authori.ty:8000/', 'doma.in', 'https://doma.in/' ],
|
||||
[ 'http://localhost:8080/this/is-a-long/path', 'somewhere:8888', 'http://somewhere:8888/this/is-a-long/path' ],
|
||||
['http://something.com/foo/bar', 'www.new.to', 'http://www.new.to/foo/bar'],
|
||||
['https://www.authori.ty:8000/', 'doma.in', 'https://doma.in/'],
|
||||
['http://localhost:8080/this/is-a-long/path', 'somewhere:8888', 'http://somewhere:8888/this/is-a-long/path'],
|
||||
])('replaces authority as expected', (uri, newAuthority, expectedResult) => {
|
||||
expect(replaceAuthorityFromUri(uri, newAuthority)).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
@@ -5,19 +5,19 @@ import { Empty } from '../../../src/utils/utils';
|
||||
describe('version', () => {
|
||||
describe('versionMatch', () => {
|
||||
it.each([
|
||||
[ undefined, Mock.all<Versions>(), false ],
|
||||
[ null, Mock.all<Versions>(), false ],
|
||||
[ '' as Empty, Mock.all<Versions>(), false ],
|
||||
[[], Mock.all<Versions>(), false ],
|
||||
[ '2.8.3' as SemVer, Mock.all<Versions>(), true ],
|
||||
[ '2.8.3' as SemVer, Mock.of<Versions>({ minVersion: '2.0.0' }), true ],
|
||||
[ '2.0.0' as SemVer, Mock.of<Versions>({ minVersion: '2.0.0' }), true ],
|
||||
[ '1.8.0' as SemVer, Mock.of<Versions>({ maxVersion: '1.8.0' }), true ],
|
||||
[ '1.7.1' as SemVer, Mock.of<Versions>({ maxVersion: '1.8.0' }), true ],
|
||||
[ '1.7.3' as SemVer, Mock.of<Versions>({ minVersion: '1.7.0', maxVersion: '1.8.0' }), true ],
|
||||
[ '1.8.3' as SemVer, Mock.of<Versions>({ minVersion: '2.0.0' }), false ],
|
||||
[ '1.8.3' as SemVer, Mock.of<Versions>({ maxVersion: '1.8.0' }), false ],
|
||||
[ '1.8.3' as SemVer, Mock.of<Versions>({ minVersion: '1.7.0', maxVersion: '1.8.0' }), false ],
|
||||
[undefined, Mock.all<Versions>(), false],
|
||||
[null, Mock.all<Versions>(), false],
|
||||
['' as Empty, Mock.all<Versions>(), false],
|
||||
[[], Mock.all<Versions>(), false],
|
||||
['2.8.3' as SemVer, Mock.all<Versions>(), true],
|
||||
['2.8.3' as SemVer, Mock.of<Versions>({ minVersion: '2.0.0' }), true],
|
||||
['2.0.0' as SemVer, Mock.of<Versions>({ minVersion: '2.0.0' }), true],
|
||||
['1.8.0' as SemVer, Mock.of<Versions>({ maxVersion: '1.8.0' }), true],
|
||||
['1.7.1' as SemVer, Mock.of<Versions>({ maxVersion: '1.8.0' }), true],
|
||||
['1.7.3' as SemVer, Mock.of<Versions>({ minVersion: '1.7.0', maxVersion: '1.8.0' }), true],
|
||||
['1.8.3' as SemVer, Mock.of<Versions>({ minVersion: '2.0.0' }), false],
|
||||
['1.8.3' as SemVer, Mock.of<Versions>({ maxVersion: '1.8.0' }), false],
|
||||
['1.8.3' as SemVer, Mock.of<Versions>({ minVersion: '1.7.0', maxVersion: '1.8.0' }), false],
|
||||
])('properly matches versions based on what is provided', (version, versionConstraints, expected) => {
|
||||
expect(versionMatch(version, versionConstraints)).toEqual(expected);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user