2021-03-06 18:54:43 +03:00
|
|
|
import { DropdownItem } from 'reactstrap';
|
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { DateIntervalDropdownItems } from '../../../src/utils/dates/DateIntervalDropdownItems';
|
|
|
|
import { DATE_INTERVALS } from '../../../src/utils/dates/types';
|
|
|
|
|
|
|
|
describe('<DateIntervalDropdownItems />', () => {
|
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const onChange = jest.fn();
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(<DateIntervalDropdownItems active="last180days" onChange={onChange} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
afterEach(() => wrapper?.unmount());
|
|
|
|
|
2021-03-06 19:25:09 +03:00
|
|
|
it('renders expected amount of items', () => {
|
2021-03-06 18:54:43 +03:00
|
|
|
const items = wrapper.find(DropdownItem);
|
|
|
|
|
|
|
|
expect(items).toHaveLength(DATE_INTERVALS.length);
|
|
|
|
});
|
|
|
|
|
2021-03-06 19:25:09 +03:00
|
|
|
it('sets expected item as active', () => {
|
2021-03-06 18:54:43 +03:00
|
|
|
const items = wrapper.find(DropdownItem);
|
|
|
|
const EXPECTED_ACTIVE_INDEX = 5;
|
|
|
|
|
|
|
|
expect.assertions(DATE_INTERVALS.length);
|
|
|
|
items.forEach((item, index) => expect(item.prop('active')).toEqual(index === EXPECTED_ACTIVE_INDEX));
|
|
|
|
});
|
|
|
|
|
2021-03-06 19:25:09 +03:00
|
|
|
it('triggers onChange callback when selecting an element', () => {
|
2021-03-06 18:54:43 +03:00
|
|
|
const items = wrapper.find(DropdownItem);
|
|
|
|
|
|
|
|
items.at(2).simulate('click');
|
|
|
|
items.at(4).simulate('click');
|
|
|
|
items.at(1).simulate('click');
|
|
|
|
expect(onChange).toHaveBeenCalledTimes(3);
|
|
|
|
});
|
|
|
|
});
|