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(() => {
|
2021-12-22 22:08:28 +03:00
|
|
|
wrapper = shallow(<DateIntervalDropdownItems allText="All" active="last180Days" onChange={onChange} />);
|
2021-03-06 18:54:43 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2021-10-03 22:07:07 +03:00
|
|
|
const dividerItems = items.findWhere((item) => !!item.prop('divider'));
|
2021-03-06 18:54:43 +03:00
|
|
|
|
2021-10-03 22:07:07 +03:00
|
|
|
expect(items).toHaveLength(DATE_INTERVALS.length + 2);
|
|
|
|
expect(dividerItems).toHaveLength(1);
|
2021-03-06 18:54:43 +03:00
|
|
|
});
|
|
|
|
|
2021-03-06 19:25:09 +03:00
|
|
|
it('sets expected item as active', () => {
|
2021-10-03 22:07:07 +03:00
|
|
|
const items = wrapper.find(DropdownItem).findWhere((item) => item.prop('active') !== undefined);
|
|
|
|
const EXPECTED_ACTIVE_INDEX = 6;
|
2021-03-06 18:54:43 +03:00
|
|
|
|
2021-10-03 22:07:07 +03:00
|
|
|
expect.assertions(DATE_INTERVALS.length + 1);
|
2021-03-06 18:54:43 +03:00
|
|
|
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(4).simulate('click');
|
2021-10-03 22:07:07 +03:00
|
|
|
items.at(6).simulate('click');
|
|
|
|
items.at(3).simulate('click');
|
2021-03-06 18:54:43 +03:00
|
|
|
expect(onChange).toHaveBeenCalledTimes(3);
|
|
|
|
});
|
|
|
|
});
|