mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
Fixed unit tests
This commit is contained in:
parent
e6034dfb14
commit
2bd70fb9e6
7 changed files with 38 additions and 33 deletions
4
src/utils/helpers/numbers.js
Normal file
4
src/utils/helpers/numbers.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
const TEN_ROUNDING_NUMBER = 10;
|
||||||
|
const { ceil } = Math;
|
||||||
|
|
||||||
|
export const roundTen = (number) => ceil(number / TEN_ROUNDING_NUMBER) * TEN_ROUNDING_NUMBER;
|
|
@ -4,9 +4,7 @@ import marker from 'leaflet/dist/images/marker-icon.png';
|
||||||
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
|
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
|
||||||
import { isEmpty, isNil, range } from 'ramda';
|
import { isEmpty, isNil, range } from 'ramda';
|
||||||
|
|
||||||
const TEN_ROUNDING_NUMBER = 10;
|
|
||||||
const DEFAULT_TIMEOUT_DELAY = 2000;
|
const DEFAULT_TIMEOUT_DELAY = 2000;
|
||||||
const { ceil } = Math;
|
|
||||||
|
|
||||||
export const stateFlagTimeout = (setTimeout) => (
|
export const stateFlagTimeout = (setTimeout) => (
|
||||||
setState,
|
setState,
|
||||||
|
@ -43,6 +41,4 @@ export const fixLeafletIcons = () => {
|
||||||
|
|
||||||
export const rangeOf = (size, mappingFn, startAt = 1) => range(startAt, size + 1).map(mappingFn);
|
export const rangeOf = (size, mappingFn, startAt = 1) => range(startAt, size + 1).map(mappingFn);
|
||||||
|
|
||||||
export const roundTen = (number) => ceil(number / TEN_ROUNDING_NUMBER) * TEN_ROUNDING_NUMBER;
|
|
||||||
|
|
||||||
export const hasValue = (value) => !isNil(value) && !isEmpty(value);
|
export const hasValue = (value) => !isNil(value) && !isEmpty(value);
|
||||||
|
|
|
@ -3,7 +3,8 @@ import PropTypes from 'prop-types';
|
||||||
import { fromPairs, head, keys, pipe, prop, reverse, sortBy, splitEvery, toLower, toPairs, type } from 'ramda';
|
import { fromPairs, head, keys, pipe, prop, reverse, sortBy, splitEvery, toLower, toPairs, type } from 'ramda';
|
||||||
import SortingDropdown from '../utils/SortingDropdown';
|
import SortingDropdown from '../utils/SortingDropdown';
|
||||||
import PaginationDropdown from '../utils/PaginationDropdown';
|
import PaginationDropdown from '../utils/PaginationDropdown';
|
||||||
import { rangeOf, roundTen } from '../utils/utils';
|
import { rangeOf } from '../utils/utils';
|
||||||
|
import { roundTen } from '../utils/helpers/numbers';
|
||||||
import SimplePaginator from '../common/SimplePaginator';
|
import SimplePaginator from '../common/SimplePaginator';
|
||||||
import GraphCard from './GraphCard';
|
import GraphCard from './GraphCard';
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Moment from 'react-moment';
|
import Moment from 'react-moment';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { map } from 'ramda';
|
import { map, min } from 'ramda';
|
||||||
import {
|
import {
|
||||||
faCaretDown as caretDownIcon,
|
faCaretDown as caretDownIcon,
|
||||||
faCaretUp as caretUpIcon,
|
faCaretUp as caretUpIcon,
|
||||||
|
@ -90,24 +90,24 @@ const VisitsTable = ({ visits, onVisitSelected }) => {
|
||||||
<FontAwesomeIcon icon={checkIcon} />
|
<FontAwesomeIcon icon={checkIcon} />
|
||||||
</th>
|
</th>
|
||||||
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('date')}>
|
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('date')}>
|
||||||
{renderOrderIcon('date')}
|
|
||||||
Date
|
Date
|
||||||
|
{renderOrderIcon('date')}
|
||||||
</th>
|
</th>
|
||||||
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('location')}>
|
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('location')}>
|
||||||
{renderOrderIcon('location')}
|
|
||||||
Location
|
Location
|
||||||
|
{renderOrderIcon('location')}
|
||||||
</th>
|
</th>
|
||||||
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('browser')}>
|
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('browser')}>
|
||||||
{renderOrderIcon('browser')}
|
|
||||||
Browser
|
Browser
|
||||||
|
{renderOrderIcon('browser')}
|
||||||
</th>
|
</th>
|
||||||
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('os')}>
|
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('os')}>
|
||||||
{renderOrderIcon('os')}
|
|
||||||
OS
|
OS
|
||||||
|
{renderOrderIcon('os')}
|
||||||
</th>
|
</th>
|
||||||
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('referer')}>
|
<th className="short-urls-list__header-cell--with-action" onClick={orderByColumn('referer')}>
|
||||||
{renderOrderIcon('referer')}
|
|
||||||
Referrer
|
Referrer
|
||||||
|
{renderOrderIcon('referer')}
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -159,7 +159,9 @@ const VisitsTable = ({ visits, onVisitSelected }) => {
|
||||||
</div>
|
</div>
|
||||||
<div className="col-6 d-flex align-items-center flex-row-reverse">
|
<div className="col-6 d-flex align-items-center flex-row-reverse">
|
||||||
<div>
|
<div>
|
||||||
Visits <b>{currentPage.start + 1}</b> to <b>{currentPage.end}</b> of <b>{currentPage.total}</b>
|
Visits <b>{currentPage.start + 1}</b> to{' '}
|
||||||
|
<b>{min(currentPage.end, currentPage.total)}</b> of{' '}
|
||||||
|
<b>{currentPage.total}</b>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
20
test/utils/helpers/numbers.test.js
Normal file
20
test/utils/helpers/numbers.test.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { roundTen } from '../../../src/utils/helpers/numbers';
|
||||||
|
|
||||||
|
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 ],
|
||||||
|
];
|
||||||
|
|
||||||
|
expect.assertions(expectationsPairs.length);
|
||||||
|
expectationsPairs.forEach(([ number, expected ]) => {
|
||||||
|
expect(roundTen(number)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -7,7 +7,6 @@ import {
|
||||||
determineOrderDir,
|
determineOrderDir,
|
||||||
fixLeafletIcons,
|
fixLeafletIcons,
|
||||||
rangeOf,
|
rangeOf,
|
||||||
roundTen,
|
|
||||||
} from '../../src/utils/utils';
|
} from '../../src/utils/utils';
|
||||||
|
|
||||||
describe('utils', () => {
|
describe('utils', () => {
|
||||||
|
@ -86,21 +85,4 @@ describe('utils', () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('roundTen', () => {
|
|
||||||
it('rounds provided number to the next multiple of ten', () => {
|
|
||||||
const expectationsPairs = [
|
|
||||||
[ 10, 10 ],
|
|
||||||
[ 12, 20 ],
|
|
||||||
[ 158, 160 ],
|
|
||||||
[ 5, 10 ],
|
|
||||||
[ -42, -40 ],
|
|
||||||
];
|
|
||||||
|
|
||||||
expect.assertions(expectationsPairs.length);
|
|
||||||
expectationsPairs.forEach(([ number, expected ]) => {
|
|
||||||
expect(roundTen(number)).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,7 +43,7 @@ describe('<ShortUrlVisits />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a preloader when visits are loading', () => {
|
it('renders a preloader when visits are loading', () => {
|
||||||
const wrapper = createComponent({ loading: true });
|
const wrapper = createComponent({ loading: true, visits: [] });
|
||||||
const loadingMessage = wrapper.find(Message);
|
const loadingMessage = wrapper.find(Message);
|
||||||
|
|
||||||
expect(loadingMessage).toHaveLength(1);
|
expect(loadingMessage).toHaveLength(1);
|
||||||
|
@ -51,7 +51,7 @@ describe('<ShortUrlVisits />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a warning when loading large amounts of visits', () => {
|
it('renders a warning when loading large amounts of visits', () => {
|
||||||
const wrapper = createComponent({ loading: true, loadingLarge: true });
|
const wrapper = createComponent({ loading: true, loadingLarge: true, visits: [] });
|
||||||
const loadingMessage = wrapper.find(Message);
|
const loadingMessage = wrapper.find(Message);
|
||||||
|
|
||||||
expect(loadingMessage).toHaveLength(1);
|
expect(loadingMessage).toHaveLength(1);
|
||||||
|
@ -59,7 +59,7 @@ describe('<ShortUrlVisits />', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders an error message when visits could not be loaded', () => {
|
it('renders an error message when visits could not be loaded', () => {
|
||||||
const wrapper = createComponent({ loading: false, error: true });
|
const wrapper = createComponent({ loading: false, error: true, visits: [] });
|
||||||
const errorMessage = wrapper.find(Card);
|
const errorMessage = wrapper.find(Card);
|
||||||
|
|
||||||
expect(errorMessage).toHaveLength(1);
|
expect(errorMessage).toHaveLength(1);
|
||||||
|
|
Loading…
Reference in a new issue