Updated charts to allow optional pagination

This commit is contained in:
Alejandro Celaya
2019-03-10 08:28:14 +01:00
parent c094a27c97
commit 61480abd2e
10 changed files with 180 additions and 96 deletions

View File

@@ -53,7 +53,7 @@ describe('<ShortUrlsRow />', () => {
});
it('renders long URL in third row', () => {
const col = wrapper.find('td').at(2); // eslint-disable-line no-magic-numbers
const col = wrapper.find('td').at(2);
const link = col.find(ExternalLink);
expect(link.prop('href')).toEqual(shortUrl.longUrl);
@@ -61,7 +61,7 @@ describe('<ShortUrlsRow />', () => {
describe('renders list of tags in fourth row', () => {
it('with tags', () => {
const col = wrapper.find('td').at(3); // eslint-disable-line no-magic-numbers
const col = wrapper.find('td').at(3);
const tags = col.find(Tag);
expect(tags).toHaveLength(shortUrl.tags.length);
@@ -75,20 +75,20 @@ describe('<ShortUrlsRow />', () => {
it('without tags', () => {
wrapper.setProps({ shortUrl: assoc('tags', [], shortUrl) });
const col = wrapper.find('td').at(3); // eslint-disable-line no-magic-numbers
const col = wrapper.find('td').at(3);
expect(col.text()).toContain('No tags');
});
});
it('renders visits count in fifth row', () => {
const col = wrapper.find('td').at(4); // eslint-disable-line no-magic-numbers
const col = wrapper.find('td').at(4);
expect(col.text()).toEqual(toString(shortUrl.visitsCount));
});
it('updates state when copied to clipboard', () => {
const col = wrapper.find('td').at(5); // eslint-disable-line no-magic-numbers
const col = wrapper.find('td').at(5);
const menu = col.find(ShortUrlsRowMenu);
expect(menu).toHaveLength(1);
@@ -98,7 +98,6 @@ describe('<ShortUrlsRow />', () => {
});
it('shows copy hint when state prop is true', () => {
// eslint-disable-next-line no-magic-numbers
const isHidden = () => wrapper.find('td').at(5).find('.short-urls-row__copy-hint').prop('hidden');
expect(isHidden()).toEqual(true);

View File

@@ -8,6 +8,7 @@ import {
determineOrderDir,
fixLeafletIcons,
rangeOf,
roundTen,
} from '../../src/utils/utils';
describe('utils', () => {
@@ -87,4 +88,21 @@ 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);
});
});
});
});

View File

@@ -15,7 +15,7 @@ describe('<SortableBarGraph />', () => {
Foo: 100,
Bar: 50,
};
const createWrapper = (extraHeaderContent = []) => {
const createWrapper = (extraHeaderContent) => {
wrapper = shallow(
<SortableBarGraph title="Foo" stats={stats} sortingItems={sortingItems} extraHeaderContent={extraHeaderContent} />
);
@@ -53,24 +53,19 @@ describe('<SortableBarGraph />', () => {
};
});
// eslint-disable-next-line no-magic-numbers
it('name - ASC', (done) => assert('name', 'ASC', [ 'Bar', 'Foo' ], [ 50, 100 ], done));
// eslint-disable-next-line no-magic-numbers
it('name - DESC', (done) => assert('name', 'DESC', [ 'Foo', 'Bar' ], [ 100, 50 ], done));
// eslint-disable-next-line no-magic-numbers
it('value - ASC', (done) => assert('value', 'ASC', [ 'Bar', 'Foo' ], [ 50, 100 ], done));
// eslint-disable-next-line no-magic-numbers
it('value - DESC', (done) => assert('value', 'DESC', [ 'Foo', 'Bar' ], [ 100, 50 ], done));
});
it('renders extra header functions', () => {
const wrapper = createWrapper([
() => <span className="foo-span">Foo</span>,
() => <span className="bar-span">Bar</span>,
]);
const wrapper = createWrapper((
<React.Fragment>
<span className="foo-span">Foo</span>
<span className="bar-span">Bar</span>
</React.Fragment>
));
expect(wrapper.find('.foo-span')).toHaveLength(1);
expect(wrapper.find('.bar-span')).toHaveLength(1);