2019-01-09 22:11:22 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2019-01-09 22:30:59 +03:00
|
|
|
import { Modal } from 'reactstrap';
|
2019-01-09 22:11:22 +03:00
|
|
|
import { Marker, Popup } from 'react-leaflet';
|
|
|
|
import MapModal from '../../../src/visits/helpers/MapModal';
|
|
|
|
|
|
|
|
describe('<MapModal />', () => {
|
|
|
|
let wrapper;
|
|
|
|
const toggle = () => '';
|
|
|
|
const isOpen = true;
|
|
|
|
const title = 'Foobar';
|
|
|
|
const zaragozaLat = 41.6563497;
|
|
|
|
const zaragozaLong = -0.876566;
|
|
|
|
const newYorkLat = 40.730610;
|
|
|
|
const newYorkLong = -73.935242;
|
|
|
|
const locations = [
|
|
|
|
{
|
|
|
|
cityName: 'Zaragoza',
|
|
|
|
count: 54,
|
|
|
|
latLong: [ zaragozaLat, zaragozaLong ],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cityName: 'New York',
|
|
|
|
count: 7,
|
|
|
|
latLong: [ newYorkLat, newYorkLong ],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(<MapModal toggle={toggle} isOpen={isOpen} title={title} locations={locations} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('renders modal with provided props', () => {
|
|
|
|
const modal = wrapper.find(Modal);
|
2019-01-09 22:30:59 +03:00
|
|
|
const headerheader = wrapper.find('.map-modal__modal-title');
|
2019-01-09 22:11:22 +03:00
|
|
|
|
|
|
|
expect(modal.prop('toggle')).toEqual(toggle);
|
|
|
|
expect(modal.prop('isOpen')).toEqual(isOpen);
|
2019-01-09 22:30:59 +03:00
|
|
|
expect(headerheader.find('.close').prop('onClick')).toEqual(toggle);
|
|
|
|
expect(headerheader.text()).toContain(title);
|
2019-01-09 22:11:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders open street map tile', () => {
|
|
|
|
expect(wrapper.find('OpenStreetMapTile')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders proper amount of markers', () => {
|
|
|
|
const markers = wrapper.find(Marker);
|
|
|
|
|
|
|
|
expect(markers).toHaveLength(locations.length);
|
|
|
|
locations.forEach(({ latLong, count, cityName }, index) => {
|
|
|
|
const marker = markers.at(index);
|
|
|
|
const popup = marker.find(Popup);
|
|
|
|
|
|
|
|
expect(marker.prop('position')).toEqual(latLong);
|
|
|
|
expect(popup.text()).toEqual(`${count} visits from ${cityName}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|