2020-09-02 21:13:31 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2019-03-10 15:05:20 +03:00
|
|
|
import { Dropdown, DropdownItem, UncontrolledTooltip } from 'reactstrap';
|
2020-09-02 21:13:31 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-28 12:16:59 +03:00
|
|
|
import { OpenMapModalBtn } from '../../../src/visits/helpers/OpenMapModalBtn';
|
|
|
|
import { MapModal } from '../../../src/visits/helpers/MapModal';
|
2020-09-02 21:13:31 +03:00
|
|
|
import { CityStats } from '../../../src/visits/types';
|
2019-01-09 22:11:22 +03:00
|
|
|
|
|
|
|
describe('<OpenMapModalBtn />', () => {
|
2020-09-02 21:13:31 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2019-01-09 22:11:22 +03:00
|
|
|
const title = 'Foo';
|
2019-03-10 15:05:20 +03:00
|
|
|
const locations = [
|
2020-09-02 21:13:31 +03:00
|
|
|
Mock.of<CityStats>({ cityName: 'foo', count: 30 }),
|
|
|
|
Mock.of<CityStats>({ cityName: 'bar', count: 45 }),
|
2019-03-10 15:05:20 +03:00
|
|
|
];
|
2020-09-02 21:13:31 +03:00
|
|
|
const createWrapper = (activeCities: string[] = []) => {
|
|
|
|
wrapper = shallow(<OpenMapModalBtn modalTitle={title} locations={locations} activeCities={activeCities} />);
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2019-03-10 15:05:20 +03:00
|
|
|
return wrapper;
|
|
|
|
};
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2020-09-02 21:13:31 +03:00
|
|
|
afterEach(() => wrapper?.unmount());
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2019-03-10 15:05:20 +03:00
|
|
|
it('renders expected content', () => {
|
|
|
|
const wrapper = createWrapper();
|
2019-01-09 22:11:22 +03:00
|
|
|
const button = wrapper.find('.open-map-modal-btn__btn');
|
|
|
|
const tooltip = wrapper.find(UncontrolledTooltip);
|
2019-03-10 15:05:20 +03:00
|
|
|
const dropdown = wrapper.find(Dropdown);
|
2019-01-09 22:11:22 +03:00
|
|
|
const modal = wrapper.find(MapModal);
|
|
|
|
|
|
|
|
expect(button).toHaveLength(1);
|
|
|
|
expect(tooltip).toHaveLength(1);
|
2019-03-10 15:05:20 +03:00
|
|
|
expect(dropdown).toHaveLength(1);
|
2019-01-09 22:11:22 +03:00
|
|
|
expect(modal).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
it('opens dropdown instead of modal when a list of active cities has been provided', () => {
|
2022-03-26 14:17:42 +03:00
|
|
|
const wrapper = createWrapper(['bar']);
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
wrapper.find('.open-map-modal-btn__btn').simulate('click');
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
expect(wrapper.find(Dropdown).prop('isOpen')).toEqual(true);
|
|
|
|
expect(wrapper.find(MapModal).prop('isOpen')).toEqual(false);
|
2019-03-10 15:05:20 +03:00
|
|
|
});
|
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
it('filters out non-active cities from list of locations', () => {
|
2022-03-26 14:17:42 +03:00
|
|
|
const wrapper = createWrapper(['bar']);
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
wrapper.find('.open-map-modal-btn__btn').simulate('click');
|
|
|
|
wrapper.find(Dropdown).find(DropdownItem).at(1).simulate('click');
|
2019-03-10 15:05:20 +03:00
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
const modal = wrapper.find(MapModal);
|
2019-01-09 22:11:22 +03:00
|
|
|
|
2021-10-31 14:33:17 +03:00
|
|
|
expect(modal.prop('title')).toEqual(title);
|
|
|
|
expect(modal.prop('locations')).toEqual([
|
|
|
|
{
|
|
|
|
cityName: 'bar',
|
|
|
|
count: 45,
|
|
|
|
},
|
|
|
|
]);
|
2019-01-09 22:11:22 +03:00
|
|
|
});
|
|
|
|
});
|