mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Created DateRangeSelector test
This commit is contained in:
parent
4e236a80de
commit
3f245a757e
2 changed files with 58 additions and 1 deletions
|
@ -12,7 +12,7 @@ import {
|
||||||
import DateRangeRow from './DateRangeRow';
|
import DateRangeRow from './DateRangeRow';
|
||||||
import './DateRangeSelector.scss';
|
import './DateRangeSelector.scss';
|
||||||
|
|
||||||
interface DateRangeSelectorProps {
|
export interface DateRangeSelectorProps {
|
||||||
initialDateRange?: DateInterval | DateRange;
|
initialDateRange?: DateInterval | DateRange;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onDatesChange: (dateRange: DateRange) => void;
|
onDatesChange: (dateRange: DateRange) => void;
|
||||||
|
|
57
test/utils/dates/DateRangeSelector.test.tsx
Normal file
57
test/utils/dates/DateRangeSelector.test.tsx
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
|
import { DropdownItem } from 'reactstrap';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { DateRangeSelector, DateRangeSelectorProps } from '../../../src/utils/dates/DateRangeSelector';
|
||||||
|
import { DateInterval } from '../../../src/utils/dates/types';
|
||||||
|
|
||||||
|
describe('<DateRangeSelector />', () => {
|
||||||
|
let wrapper: ShallowWrapper;
|
||||||
|
const onDatesChange = jest.fn();
|
||||||
|
const createWrapper = (props: Partial<DateRangeSelectorProps> = {}) => {
|
||||||
|
wrapper = shallow(<DateRangeSelector {...props} onDatesChange={onDatesChange} />);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(jest.clearAllMocks);
|
||||||
|
afterEach(() => wrapper?.unmount());
|
||||||
|
|
||||||
|
test('proper amount of items is rendered', () => {
|
||||||
|
const wrapper = createWrapper();
|
||||||
|
const items = wrapper.find(DropdownItem);
|
||||||
|
|
||||||
|
expect(items).toHaveLength(12);
|
||||||
|
expect(items.filter('[divider]')).toHaveLength(2);
|
||||||
|
expect(items.filter('[header]')).toHaveLength(1);
|
||||||
|
expect(items.filter('[text]')).toHaveLength(1);
|
||||||
|
expect(items.filter('[active]')).toHaveLength(8);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each([
|
||||||
|
[ undefined, 0 ],
|
||||||
|
[ 'today' as DateInterval, 1 ],
|
||||||
|
[ 'yesterday' as DateInterval, 2 ],
|
||||||
|
[ 'last7Days' as DateInterval, 3 ],
|
||||||
|
[ 'last30Days' as DateInterval, 4 ],
|
||||||
|
[ 'last90Days' as DateInterval, 5 ],
|
||||||
|
[ 'last180days' as DateInterval, 6 ],
|
||||||
|
[ 'last365Days' as DateInterval, 7 ],
|
||||||
|
[{ startDate: moment() }, 8 ],
|
||||||
|
])('proper element is active based on provided date range', (initialDateRange, expectedActiveIndex) => {
|
||||||
|
const wrapper = createWrapper({ initialDateRange });
|
||||||
|
const items = wrapper.find(DropdownItem).filter('[active]');
|
||||||
|
|
||||||
|
expect.assertions(8);
|
||||||
|
items.forEach((item, index) => expect(item.prop('active')).toEqual(index === expectedActiveIndex));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('selecting an element triggers onDatesChange callback', () => {
|
||||||
|
const wrapper = createWrapper();
|
||||||
|
const items = wrapper.find(DropdownItem).filter('[active]');
|
||||||
|
|
||||||
|
items.at(2).simulate('click');
|
||||||
|
items.at(4).simulate('click');
|
||||||
|
items.at(1).simulate('click');
|
||||||
|
expect(onDatesChange).toHaveBeenCalledTimes(3);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue