mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-10 17:43:51 +00:00
Improved logic to determine default grouping for line chart based on how old the visits are
This commit is contained in:
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { CardHeader, DropdownItem } from 'reactstrap';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
import moment from 'moment';
|
||||
import LineChartCard from '../../../src/visits/helpers/LineChartCard';
|
||||
import Checkbox from '../../../src/utils/Checkbox';
|
||||
|
||||
@@ -22,19 +23,27 @@ describe('<LineChartCard />', () => {
|
||||
expect(header.html()).toContain('Cool title');
|
||||
});
|
||||
|
||||
it('renders group menu and selects active grouping item', () => {
|
||||
const wrapper = createWrapper();
|
||||
it.each([
|
||||
[[], 'monthly' ],
|
||||
[[{ date: moment().subtract(1, 'day').format() }], 'hourly' ],
|
||||
[[{ date: moment().subtract(3, 'day').format() }], 'daily' ],
|
||||
[[{ date: moment().subtract(2, 'month').format() }], 'weekly' ],
|
||||
[[{ date: moment().subtract(6, 'month').format() }], 'weekly' ],
|
||||
[[{ date: moment().subtract(7, 'month').format() }], 'monthly' ],
|
||||
[[{ date: moment().subtract(1, 'year').format() }], 'monthly' ],
|
||||
])('renders group menu and selects proper grouping item based on visits dates', (visits, expectedActiveItem) => {
|
||||
const wrapper = createWrapper(visits);
|
||||
const items = wrapper.find(DropdownItem);
|
||||
|
||||
expect(items).toHaveLength(4);
|
||||
expect(items.at(0).prop('children')).toEqual('Month');
|
||||
expect(items.at(0).prop('active')).toEqual(true);
|
||||
expect(items.at(0).prop('active')).toEqual(expectedActiveItem === 'monthly');
|
||||
expect(items.at(1).prop('children')).toEqual('Week');
|
||||
expect(items.at(1).prop('active')).toEqual(false);
|
||||
expect(items.at(1).prop('active')).toEqual(expectedActiveItem === 'weekly');
|
||||
expect(items.at(2).prop('children')).toEqual('Day');
|
||||
expect(items.at(2).prop('active')).toEqual(false);
|
||||
expect(items.at(2).prop('active')).toEqual(expectedActiveItem === 'daily');
|
||||
expect(items.at(3).prop('children')).toEqual('Hour');
|
||||
expect(items.at(3).prop('active')).toEqual(false);
|
||||
expect(items.at(3).prop('active')).toEqual(expectedActiveItem === 'hourly');
|
||||
});
|
||||
|
||||
it('renders chart with expected options', () => {
|
||||
|
||||
Reference in New Issue
Block a user