Updated to airbnb coding styles

This commit is contained in:
Alejandro Celaya
2022-03-26 12:17:42 +01:00
parent 4e9b19afd1
commit a2df486280
239 changed files with 2210 additions and 3549 deletions

View File

@@ -16,7 +16,7 @@ describe('<Checkbox />', () => {
afterEach(() => wrapped?.unmount());
it('includes extra class names when provided', () => {
const classNames = [ 'foo', 'bar', 'baz' ];
const classNames = ['foo', 'bar', 'baz'];
expect.assertions(classNames.length);
classNames.forEach((className) => {
@@ -27,7 +27,7 @@ describe('<Checkbox />', () => {
});
it('marks input as checked if defined', () => {
const checkeds = [ true, false ];
const checkeds = [true, false];
expect.assertions(checkeds.length);
checkeds.forEach((checked) => {
@@ -39,7 +39,7 @@ describe('<Checkbox />', () => {
});
it('renders provided children inside the label', () => {
const labels = [ 'foo', 'bar', 'baz' ];
const labels = ['foo', 'bar', 'baz'];
expect.assertions(labels.length);
labels.forEach((children) => {

View File

@@ -6,21 +6,21 @@ import { DropdownBtn, DropdownBtnProps } from '../../src/utils/DropdownBtn';
describe('<DropdownBtn />', () => {
let wrapper: ShallowWrapper;
const createWrapper = (props: PropsWithChildren<DropdownBtnProps>) => {
wrapper = shallow(<DropdownBtn children={'foo'} {...props} />);
wrapper = shallow(<DropdownBtn children="foo" {...props} />);
return wrapper;
};
afterEach(() => wrapper?.unmount());
it.each([[ 'foo' ], [ 'bar' ], [ 'baz' ]])('displays provided text', (text) => {
it.each([['foo'], ['bar'], ['baz']])('displays provided text', (text) => {
const wrapper = createWrapper({ text });
const toggle = wrapper.find(DropdownToggle);
expect(toggle.prop('children')).toContain(text);
});
it.each([[ 'foo' ], [ 'bar' ], [ 'baz' ]])('displays provided children', (children) => {
it.each([['foo'], ['bar'], ['baz']])('displays provided children', (children) => {
const wrapper = createWrapper({ text: '', children });
const menu = wrapper.find(DropdownMenu);
@@ -28,10 +28,10 @@ describe('<DropdownBtn />', () => {
});
it.each([
[ undefined, 'dropdown-btn__toggle btn-block' ],
[ '', 'dropdown-btn__toggle btn-block' ],
[ 'foo', 'dropdown-btn__toggle btn-block foo' ],
[ 'bar', 'dropdown-btn__toggle btn-block bar' ],
[undefined, 'dropdown-btn__toggle btn-block'],
['', 'dropdown-btn__toggle btn-block'],
['foo', 'dropdown-btn__toggle btn-block foo'],
['bar', 'dropdown-btn__toggle btn-block bar'],
])('includes provided classes', (className, expectedClasses) => {
const wrapper = createWrapper({ text: '', className });
const toggle = wrapper.find(DropdownToggle);
@@ -40,9 +40,9 @@ describe('<DropdownBtn />', () => {
});
it.each([
[ 100, { minWidth: '100px' }],
[ 250, { minWidth: '250px' }],
[ undefined, {}],
[100, { minWidth: '100px' }],
[250, { minWidth: '250px' }],
[undefined, {}],
])('renders proper styles when minWidth is provided', (minWidth, expectedStyle) => {
const wrapper = createWrapper({ text: '', minWidth });
const style = wrapper.find(DropdownMenu).prop('style');

View File

@@ -37,9 +37,9 @@ describe('<DropdownBtnMenu />', () => {
});
it.each([
[ undefined, true ],
[ true, true ],
[ false, false ],
[undefined, true],
[true, true],
[false, false],
])('renders menu to right when expected', (right, expectedRight) => {
const wrapper = createWrapper({ right });

View File

@@ -15,8 +15,8 @@ describe('<ExportBtn />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[ true, 'Exporting...' ],
[ false, 'Export (' ],
[true, 'Exporting...'],
[false, 'Export ('],
])('renders a button', (loading, text) => {
const wrapper = createWrapper(undefined, loading);
@@ -27,10 +27,10 @@ describe('<ExportBtn />', () => {
});
it.each([
[ undefined, '0' ],
[ 10, '10' ],
[ 10_000, '10,000' ],
[ 10_000_000, '10,000,000' ],
[undefined, '0'],
[10, '10'],
[10_000, '10,000'],
[10_000_000, '10,000,000'],
])('renders expected amount', (amount, expectedRenderedAmount) => {
const wrapper = createWrapper(amount);

View File

@@ -5,9 +5,9 @@ import { InfoTooltip } from '../../src/utils/InfoTooltip';
describe('<InfoTooltip />', () => {
it.each([
[ undefined ],
[ 'foo' ],
[ 'bar' ],
[undefined],
['foo'],
['bar'],
])('renders expected className on span', (className) => {
const wrapper = shallow(<InfoTooltip placement="right" className={className} />);
const span = wrapper.find('span');
@@ -16,10 +16,10 @@ describe('<InfoTooltip />', () => {
});
it.each([
[ <span key={1} /> ],
[ 'Foo' ],
[ 'Hello' ],
[[ 'One', 'Two', <span key={3} /> ]],
[<span key={1} />],
['Foo'],
['Hello'],
[['One', 'Two', <span key={3} />]],
])('passes children down to the nested tooltip component', (children) => {
const wrapper = shallow(<InfoTooltip placement="right">{children}</InfoTooltip>);
const tooltip = wrapper.find(UncontrolledTooltip);
@@ -28,10 +28,10 @@ describe('<InfoTooltip />', () => {
});
it.each([
[ 'right' as Placement ],
[ 'left' as Placement ],
[ 'top' as Placement ],
[ 'bottom' as Placement ],
['right' as Placement],
['left' as Placement],
['top' as Placement],
['bottom' as Placement],
])('places tooltip where requested', (placement) => {
const wrapper = shallow(<InfoTooltip placement={placement} />);
const tooltip = wrapper.find(UncontrolledTooltip);

View File

@@ -15,9 +15,9 @@ describe('<Message />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[ true, 1, 0 ],
[ false, 0, 1 ],
[ undefined, 0, 1 ],
[true, 1, 0],
[false, 0, 1],
[undefined, 0, 1],
])('renders expected classes based on width', (fullWidth, expectedFull, expectedNonFull) => {
const wrapper = createWrapper({ fullWidth });
@@ -26,27 +26,27 @@ describe('<Message />', () => {
});
it.each([
[ true, 'These are the children contents' ],
[ false, 'These are the children contents' ],
[ true, undefined ],
[ false, undefined ],
[true, 'These are the children contents'],
[false, 'These are the children contents'],
[true, undefined],
[false, undefined],
])('renders expected content', (loading, children) => {
const wrapper = createWrapper({ loading, children });
expect(wrapper.find(FontAwesomeIcon)).toHaveLength(loading ? 1 : 0);
if (loading) {
expect(wrapper.find('span').text()).toContain(children ? children : 'Loading...');
expect(wrapper.find('span').text()).toContain(children || 'Loading...');
} else {
expect(wrapper.find('span')).toHaveLength(0);
expect(wrapper.find('h3').text()).toContain(children ? children : '');
expect(wrapper.find('h3').text()).toContain(children || '');
}
});
it.each([
[ 'error', 'border-danger', 'text-danger' ],
[ 'default', '', 'text-muted' ],
[ undefined, '', 'text-muted' ],
['error', 'border-danger', 'text-danger'],
['default', '', 'text-muted'],
[undefined, '', 'text-muted'],
])('renders proper classes based on message type', (type, expectedCardClass, expectedH3Class) => {
const wrapper = createWrapper({ type: type as 'default' | 'error' | undefined });
const card = wrapper.find(Card);

View File

@@ -4,9 +4,9 @@ import { NavPillItem, NavPills } from '../../src/utils/NavPills';
describe('<NavPills />', () => {
it.each([
[ 'Foo' ],
[ <span key="1">Hi!</span> ],
[[ <NavPillItem key="1" to="" />, <span key="2">Hi!</span> ]],
['Foo'],
[<span key="1">Hi!</span>],
[[<NavPillItem key="1" to="" />, <span key="2">Hi!</span>]],
])('throws error when any of the children is not a NavPillItem', (children) => {
expect.assertions(1);
@@ -18,9 +18,9 @@ describe('<NavPills />', () => {
});
it.each([
[ undefined ],
[ true ],
[ false ],
[undefined],
[true],
[false],
])('renders provided items', (fill) => {
const wrapper = shallow(
<NavPills fill={fill}>

View File

@@ -7,7 +7,7 @@ describe('<PaginationDropdown />', () => {
let wrapper: ShallowWrapper;
beforeEach(() => {
wrapper = shallow(<PaginationDropdown ranges={[ 10, 50, 100, 200 ]} value={50} setValue={setValue} />);
wrapper = shallow(<PaginationDropdown ranges={[10, 50, 100, 200]} value={50} setValue={setValue} />);
});
afterEach(jest.clearAllMocks);
@@ -20,11 +20,11 @@ describe('<PaginationDropdown />', () => {
});
it.each([
[ 0, 10 ],
[ 1, 50 ],
[ 2, 100 ],
[ 3, 200 ],
[ 5, Infinity ],
[0, 10],
[1, 50],
[2, 100],
[3, 200],
[5, Infinity],
])('sets expected value when an item is clicked', (index, expectedValue) => {
const item = wrapper.find(DropdownItem).at(index);

View File

@@ -13,9 +13,9 @@ describe('<Result />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[ 'success' as ResultType, 'bg-main text-white' ],
[ 'error' as ResultType, 'bg-danger text-white' ],
[ 'warning' as ResultType, 'bg-warning' ],
['success' as ResultType, 'bg-main text-white'],
['error' as ResultType, 'bg-danger text-white'],
['warning' as ResultType, 'bg-warning'],
])('renders expected classes based on type', (type, expectedClasses) => {
const wrapper = createWrapper({ type });
const innerCard = wrapper.find(SimpleCard);
@@ -24,9 +24,9 @@ describe('<Result />', () => {
});
it.each([
[ undefined ],
[ 'foo' ],
[ 'bar' ],
[undefined],
['foo'],
['bar'],
])('renders provided classes in root element', (className) => {
const wrapper = createWrapper({ type: 'success', className });

View File

@@ -4,8 +4,8 @@ import { SimpleCard } from '../../src/utils/SimpleCard';
describe('<SimpleCard />', () => {
it.each([
[{}, 0 ],
[{ title: 'Cool title' }, 1 ],
[{}, 0],
[{ title: 'Cool title' }, 1],
])('renders header only if title is provided', (props, expectedAmountOfHeaders) => {
const wrapper = shallow(<SimpleCard {...props} />);

View File

@@ -76,8 +76,8 @@ describe('<SortingDropdown />', () => {
});
it.each([
[{ isButton: false }, <>Order by</> ],
[{ isButton: true }, <>Order by...</> ],
[{ isButton: false }, <>Order by</>],
[{ isButton: true }, <>Order by...</>],
[
{ isButton: true, order: { field: 'foo', dir: 'ASC' as OrderDir } },
'Order by: "Foo" - "ASC"',
@@ -86,11 +86,11 @@ describe('<SortingDropdown />', () => {
{ isButton: true, order: { field: 'baz', dir: 'DESC' as OrderDir } },
'Order by: "Hello World" - "DESC"',
],
[{ isButton: true, order: { field: 'baz' } }, 'Order by: "Hello World" - "DESC"' ],
[{ isButton: true, order: { field: 'baz' } }, 'Order by: "Hello World" - "DESC"'],
])('displays expected text in toggle', (props, expectedText) => {
const wrapper = createWrapper(props);
const toggle = wrapper.find(DropdownToggle);
const [ children ] = (toggle.prop('children') as any[]).filter(Boolean);
const [children] = (toggle.prop('children') as any[]).filter(Boolean);
expect(children).toEqual(expectedText);
});

View File

@@ -13,8 +13,8 @@ describe('<Time />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[{ date: parseDate('2020-05-05', 'yyyy-MM-dd') }, '1588636800000', '2020-05-05 00:00' ],
[{ date: parseDate('2021-03-20', 'yyyy-MM-dd'), format: 'dd/MM/yyyy' }, '1616198400000', '20/03/2021' ],
[{ date: parseDate('2020-05-05', 'yyyy-MM-dd') }, '1588636800000', '2020-05-05 00:00'],
[{ date: parseDate('2021-03-20', 'yyyy-MM-dd'), format: 'dd/MM/yyyy' }, '1616198400000', '20/03/2021'],
])('includes expected dateTime and format', (props, expectedDateTime, expectedFormatted) => {
const wrapper = createWrapper(props);

View File

@@ -15,9 +15,9 @@ describe('<TooltipToggleSwitch />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[ 'foo' ],
[ 'bar' ],
[ 'baz' ],
['foo'],
['bar'],
['baz'],
])('shows children inside tooltip', (children) => {
const wrapper = createWrapper({ children });
const tooltip = wrapper.find(UncontrolledTooltip);

View File

@@ -37,16 +37,16 @@ describe('<DateRangeSelector />', () => {
});
it.each([
[ undefined, 0 ],
[ 'all' as DateInterval, 1 ],
[ 'today' as DateInterval, 1 ],
[ 'yesterday' as DateInterval, 1 ],
[ 'last7Days' as DateInterval, 1 ],
[ 'last30Days' as DateInterval, 1 ],
[ 'last90Days' as DateInterval, 1 ],
[ 'last180Days' as DateInterval, 1 ],
[ 'last365Days' as DateInterval, 1 ],
[{ startDate: new Date() }, 0 ],
[undefined, 0],
['all' as DateInterval, 1],
['today' as DateInterval, 1],
['yesterday' as DateInterval, 1],
['last7Days' as DateInterval, 1],
['last30Days' as DateInterval, 1],
['last90Days' as DateInterval, 1],
['last180Days' as DateInterval, 1],
['last365Days' as DateInterval, 1],
[{ startDate: new Date() }, 0],
])('sets proper element as active based on provided date range', (initialDateRange, expectedActiveIntervalItems) => {
const wrapper = createWrapper({ initialDateRange });
const dateIntervalItems = wrapper.find(DateIntervalDropdownItems).filterWhere(

View File

@@ -15,19 +15,19 @@ describe('date-types', () => {
describe('dateRangeIsEmpty', () => {
it.each([
[ undefined, true ],
[{}, true ],
[{ startDate: null }, true ],
[{ endDate: null }, true ],
[{ startDate: null, endDate: null }, true ],
[{ startDate: undefined }, true ],
[{ endDate: undefined }, true ],
[{ startDate: undefined, endDate: undefined }, true ],
[{ startDate: undefined, endDate: null }, true ],
[{ startDate: null, endDate: undefined }, true ],
[{ startDate: new Date() }, false ],
[{ endDate: new Date() }, false ],
[{ startDate: new Date(), endDate: new Date() }, false ],
[undefined, true],
[{}, true],
[{ startDate: null }, true],
[{ endDate: null }, true],
[{ startDate: null, endDate: null }, true],
[{ startDate: undefined }, true],
[{ endDate: undefined }, true],
[{ startDate: undefined, endDate: undefined }, true],
[{ startDate: undefined, endDate: null }, true],
[{ startDate: null, endDate: undefined }, true],
[{ startDate: new Date() }, false],
[{ endDate: new Date() }, false],
[{ startDate: new Date(), endDate: new Date() }, false],
])('returns proper result', (dateRange, expectedResult) => {
expect(dateRangeIsEmpty(dateRange)).toEqual(expectedResult);
});
@@ -35,10 +35,10 @@ describe('date-types', () => {
describe('rangeIsInterval', () => {
it.each([
[ undefined, false ],
[{}, false ],
[ 'today' as DateInterval, true ],
[ 'yesterday' as DateInterval, true ],
[undefined, false],
[{}, false],
['today' as DateInterval, true],
['yesterday' as DateInterval, true],
])('returns proper result', (range, expectedResult) => {
expect(rangeIsInterval(range)).toEqual(expectedResult);
});
@@ -46,25 +46,25 @@ describe('date-types', () => {
describe('rangeOrIntervalToString', () => {
it.each([
[ undefined, undefined ],
[ 'today' as DateInterval, 'Today' ],
[ 'yesterday' as DateInterval, 'Yesterday' ],
[ 'last7Days' as DateInterval, 'Last 7 days' ],
[ 'last30Days' as DateInterval, 'Last 30 days' ],
[ 'last90Days' as DateInterval, 'Last 90 days' ],
[ 'last180Days' as DateInterval, 'Last 180 days' ],
[ 'last365Days' as DateInterval, 'Last 365 days' ],
[{}, undefined ],
[{ startDate: null }, undefined ],
[{ endDate: null }, undefined ],
[{ startDate: null, endDate: null }, undefined ],
[{ startDate: undefined }, undefined ],
[{ endDate: undefined }, undefined ],
[{ startDate: undefined, endDate: undefined }, undefined ],
[{ startDate: undefined, endDate: null }, undefined ],
[{ startDate: null, endDate: undefined }, undefined ],
[{ startDate: parseDate('2020-01-01', 'yyyy-MM-dd') }, 'Since 2020-01-01' ],
[{ endDate: parseDate('2020-01-01', 'yyyy-MM-dd') }, 'Until 2020-01-01' ],
[undefined, undefined],
['today' as DateInterval, 'Today'],
['yesterday' as DateInterval, 'Yesterday'],
['last7Days' as DateInterval, 'Last 7 days'],
['last30Days' as DateInterval, 'Last 30 days'],
['last90Days' as DateInterval, 'Last 90 days'],
['last180Days' as DateInterval, 'Last 180 days'],
['last365Days' as DateInterval, 'Last 365 days'],
[{}, undefined],
[{ startDate: null }, undefined],
[{ endDate: null }, undefined],
[{ startDate: null, endDate: null }, undefined],
[{ startDate: undefined }, undefined],
[{ endDate: undefined }, undefined],
[{ startDate: undefined, endDate: undefined }, undefined],
[{ startDate: undefined, endDate: null }, undefined],
[{ startDate: null, endDate: undefined }, undefined],
[{ startDate: parseDate('2020-01-01', 'yyyy-MM-dd') }, 'Since 2020-01-01'],
[{ endDate: parseDate('2020-01-01', 'yyyy-MM-dd') }, 'Until 2020-01-01'],
[
{ startDate: parseDate('2020-01-01', 'yyyy-MM-dd'), endDate: parseDate('2021-02-02', 'yyyy-MM-dd') },
'2020-01-01 - 2021-02-02',
@@ -75,17 +75,17 @@ describe('date-types', () => {
});
describe('intervalToDateRange', () => {
const formatted = (date?: Date | null): string | undefined => !date ? undefined : format(date, 'yyyy-MM-dd');
const formatted = (date?: Date | null): string | undefined => (!date ? undefined : format(date, 'yyyy-MM-dd'));
it.each([
[ undefined, undefined, undefined ],
[ 'today' as DateInterval, now(), now() ],
[ 'yesterday' as DateInterval, daysBack(1), daysBack(1) ],
[ 'last7Days' as DateInterval, daysBack(7), now() ],
[ 'last30Days' as DateInterval, daysBack(30), now() ],
[ 'last90Days' as DateInterval, daysBack(90), now() ],
[ 'last180Days' as DateInterval, daysBack(180), now() ],
[ 'last365Days' as DateInterval, daysBack(365), now() ],
[undefined, undefined, undefined],
['today' as DateInterval, now(), now()],
['yesterday' as DateInterval, daysBack(1), daysBack(1)],
['last7Days' as DateInterval, daysBack(7), now()],
['last30Days' as DateInterval, daysBack(30), now()],
['last90Days' as DateInterval, daysBack(90), now()],
['last180Days' as DateInterval, daysBack(180), now()],
['last365Days' as DateInterval, daysBack(365), now()],
])('returns proper result', (interval, expectedStartDate, expectedEndDate) => {
const { startDate, endDate } = intervalToDateRange(interval);
@@ -96,22 +96,22 @@ describe('date-types', () => {
describe('dateToMatchingInterval', () => {
it.each([
[ startOfDay(now()), 'today' ],
[ now(), 'today' ],
[ formatISO(now()), 'today' ],
[ daysBack(1), 'yesterday' ],
[ endOfDay(daysBack(1)), 'yesterday' ],
[ daysBack(2), 'last7Days' ],
[ daysBack(7), 'last7Days' ],
[ startOfDay(daysBack(7)), 'last7Days' ],
[ daysBack(18), 'last30Days' ],
[ daysBack(29), 'last30Days' ],
[ daysBack(58), 'last90Days' ],
[ startOfDay(daysBack(90)), 'last90Days' ],
[ daysBack(120), 'last180Days' ],
[ daysBack(250), 'last365Days' ],
[ daysBack(366), 'all' ],
[ formatISO(daysBack(500)), 'all' ],
[startOfDay(now()), 'today'],
[now(), 'today'],
[formatISO(now()), 'today'],
[daysBack(1), 'yesterday'],
[endOfDay(daysBack(1)), 'yesterday'],
[daysBack(2), 'last7Days'],
[daysBack(7), 'last7Days'],
[startOfDay(daysBack(7)), 'last7Days'],
[daysBack(18), 'last30Days'],
[daysBack(29), 'last30Days'],
[daysBack(58), 'last90Days'],
[startOfDay(daysBack(90)), 'last90Days'],
[daysBack(120), 'last180Days'],
[daysBack(250), 'last365Days'],
[daysBack(366), 'all'],
[formatISO(daysBack(500)), 'all'],
])('returns the first interval which contains provided date', (date, expectedInterval) => {
expect(dateToMatchingInterval(date)).toEqual(expectedInterval);
});

View File

@@ -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);
});

View File

@@ -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);
});
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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' });

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -48,11 +48,11 @@ describe('ColorGenerator', () => {
describe('isColorLightForKey', () => {
it.each([
[ MAIN_COLOR, true ],
[ '#8A661C', false ],
[ '#F7BE05', true ],
[ '#5A02D8', false ],
[ '#202786', false ],
[MAIN_COLOR, true],
['#8A661C', false],
['#F7BE05', true],
['#5A02D8', false],
['#202786', false],
])('returns that the color for a key is light based on the color assigned to that key', (color, isLight) => {
colorGenerator.setColorForKey('foo', color);

View File

@@ -2,7 +2,7 @@ import { Mock } from 'ts-mockery';
import LocalStorage from '../../../src/utils/services/LocalStorage';
describe('LocalStorage', () => {
const getItem = jest.fn((key) => key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null);
const getItem = jest.fn((key) => (key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null));
const setItem = jest.fn();
const localStorageMock = Mock.of<Storage>({ getItem, setItem });
let storage: LocalStorage;

View File

@@ -16,9 +16,9 @@ describe('<TableOrderIcon />', () => {
afterEach(() => wrapper?.unmount());
it.each([
[ 'foo', undefined ],
[ 'bar', 'DESC' as OrderDir ],
[ 'bar', 'ASC' as OrderDir ],
['foo', undefined],
['bar', 'DESC' as OrderDir],
['bar', 'ASC' as OrderDir],
])('renders empty when not all conditions are met', (field, dir) => {
const wrapper = createWrapper(field, dir);
@@ -26,8 +26,8 @@ describe('<TableOrderIcon />', () => {
});
it.each([
[ 'DESC' as OrderDir, caretDownIcon ],
[ 'ASC' as OrderDir, caretUpIcon ],
['DESC' as OrderDir, caretDownIcon],
['ASC' as OrderDir, caretUpIcon],
])('renders an icon when all conditions are met', (dir, expectedIcon) => {
const wrapper = createWrapper('foo', dir);
@@ -36,9 +36,9 @@ describe('<TableOrderIcon />', () => {
});
it.each([
[ undefined, 'ms-1' ],
[ 'foo', 'foo' ],
[ 'bar', 'bar' ],
[undefined, 'ms-1'],
['foo', 'foo'],
['bar', 'bar'],
])('renders expected classname', (className, expectedClassName) => {
const wrapper = createWrapper('foo', 'ASC', className);

View File

@@ -28,11 +28,11 @@ describe('utils', () => {
describe('nonEmptyValueOrNull', () => {
it.each([
[ '', null ],
[ 'Hello', 'Hello' ],
[[], null ],
[[ 1, 2, 3 ], [ 1, 2, 3 ]],
[{}, null ],
['', null],
['Hello', 'Hello'],
[[], null],
[[1, 2, 3], [1, 2, 3]],
[{}, null],
[{ foo: 'bar' }, { foo: 'bar' }],
])('returns expected value based on input', (value, expected) => {
expect(nonEmptyValueOrNull(value)).toEqual(expected);
@@ -41,10 +41,10 @@ describe('utils', () => {
describe('capitalize', () => {
it.each([
[ 'foo', 'Foo' ],
[ 'BAR', 'BAR' ],
[ 'bAZ', 'BAZ' ],
[ 'with spaces', 'With spaces' ],
['foo', 'Foo'],
['BAR', 'BAR'],
['bAZ', 'BAZ'],
['with spaces', 'With spaces'],
])('sets first letter in uppercase', (value, expectedResult) => {
expect(capitalize(value)).toEqual(expectedResult);
});