Fixed VisitsStats test

This commit is contained in:
Alejandro Celaya 2022-02-07 22:55:32 +01:00
parent c4e928ff09
commit eab072831d
2 changed files with 19 additions and 7 deletions

View file

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed ### Changed
* [#567](https://github.com/shlinkio/shlink-web-client/pull/567) Improved Shlink 3.0.0 compatibility by checking the `INVALID_SHORT_URL_DELETION` error code when deleting short URLs. * [#567](https://github.com/shlinkio/shlink-web-client/pull/567) Improved Shlink 3.0.0 compatibility by checking the `INVALID_SHORT_URL_DELETION` error code when deleting short URLs.
* [#524](https://github.com/shlinkio/shlink-web-client/pull/524) Updated to react-router v6.
### Deprecated ### Deprecated
* *Nothing* * *Nothing*

View file

@ -1,6 +1,8 @@
import { shallow, ShallowWrapper } from 'enzyme'; import { shallow, ShallowWrapper } from 'enzyme';
import { Button, Progress } from 'reactstrap'; import { Button, Progress } from 'reactstrap';
import { sum } from 'ramda';
import { Mock } from 'ts-mockery'; import { Mock } from 'ts-mockery';
import { Route } from 'react-router-dom';
import VisitStats from '../../src/visits/VisitsStats'; import VisitStats from '../../src/visits/VisitsStats';
import Message from '../../src/utils/Message'; import Message from '../../src/utils/Message';
import { Visit, VisitsInfo } from '../../src/visits/types'; import { Visit, VisitsInfo } from '../../src/visits/types';
@ -75,18 +77,27 @@ describe('<VisitsStats />', () => {
it('renders expected amount of charts', () => { it('renders expected amount of charts', () => {
const wrapper = createComponent({ loading: false, error: false, visits }); const wrapper = createComponent({ loading: false, error: false, visits });
const charts = wrapper.find(DoughnutChartCard); const total = sum(wrapper.find(Route).map((element) => {
const sortableCharts = wrapper.find(SortableBarChartCard); const ElementComponents = () => element.prop('element');
const lineChart = wrapper.find(LineChartCard); // @ts-expect-error Wrapped element
const table = wrapper.find(VisitsTable); const wrappedElement = shallow(<ElementComponents />);
expect(charts.length + sortableCharts.length + lineChart.length).toEqual(6); const charts = wrappedElement.find(DoughnutChartCard);
expect(table).toHaveLength(1); const sortableCharts = wrappedElement.find(SortableBarChartCard);
const lineChart = wrappedElement.find(LineChartCard);
const table = wrappedElement.find(VisitsTable);
return charts.length + sortableCharts.length + lineChart.length + table.length;
}));
expect(total).toEqual(7);
}); });
it('holds the map button content generator on cities chart extraHeaderContent', () => { it('holds the map button content generator on cities chart extraHeaderContent', () => {
const wrapper = createComponent({ loading: false, error: false, visits }); const wrapper = createComponent({ loading: false, error: false, visits });
const citiesChart = wrapper.find(SortableBarChartCard).find('[title="Cities"]'); const ElementComponent = () => wrapper.find(Route).findWhere((element) => element.prop('path') === 'by-location')
.prop('element');
const citiesChart = shallow(<ElementComponent />).find(SortableBarChartCard).find('[title="Cities"]');
const extraHeaderContent = citiesChart.prop('extraHeaderContent'); const extraHeaderContent = citiesChart.prop('extraHeaderContent');
expect(extraHeaderContent).toHaveLength(1); expect(extraHeaderContent).toHaveLength(1);