mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 01:53:51 +00:00
Migrated first visits helper components to TS
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { Modal } from 'reactstrap';
|
||||
import { Marker, Popup } from 'react-leaflet';
|
||||
import MapModal from '../../../src/visits/helpers/MapModal';
|
||||
import { CityStats } from '../../../src/visits/types';
|
||||
|
||||
describe('<MapModal />', () => {
|
||||
let wrapper;
|
||||
let wrapper: ShallowWrapper;
|
||||
const toggle = () => '';
|
||||
const isOpen = true;
|
||||
const title = 'Foobar';
|
||||
@@ -13,7 +14,7 @@ describe('<MapModal />', () => {
|
||||
const zaragozaLong = -0.876566;
|
||||
const newYorkLat = 40.730610;
|
||||
const newYorkLong = -73.935242;
|
||||
const locations = [
|
||||
const locations: CityStats[] = [
|
||||
{
|
||||
cityName: 'Zaragoza',
|
||||
count: 54,
|
||||
@@ -34,12 +35,12 @@ describe('<MapModal />', () => {
|
||||
|
||||
it('renders modal with provided props', () => {
|
||||
const modal = wrapper.find(Modal);
|
||||
const headerheader = wrapper.find('.map-modal__modal-title');
|
||||
const header = wrapper.find('.map-modal__modal-title');
|
||||
|
||||
expect(modal.prop('toggle')).toEqual(toggle);
|
||||
expect(modal.prop('isOpen')).toEqual(isOpen);
|
||||
expect(headerheader.find('.close').prop('onClick')).toEqual(toggle);
|
||||
expect(headerheader.text()).toContain(title);
|
||||
expect(header.find('.close').prop('onClick')).toEqual(toggle);
|
||||
expect(header.text()).toContain(title);
|
||||
});
|
||||
|
||||
it('renders open street map tile', () => {
|
||||
@@ -1,30 +1,25 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { Dropdown, DropdownItem, UncontrolledTooltip } from 'reactstrap';
|
||||
import createOpenMapModalBtn from '../../../src/visits/helpers/OpenMapModalBtn';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import OpenMapModalBtn from '../../../src/visits/helpers/OpenMapModalBtn';
|
||||
import MapModal from '../../../src/visits/helpers/MapModal';
|
||||
import { CityStats } from '../../../src/visits/types';
|
||||
|
||||
describe('<OpenMapModalBtn />', () => {
|
||||
let wrapper;
|
||||
let wrapper: ShallowWrapper;
|
||||
const title = 'Foo';
|
||||
const locations = [
|
||||
{
|
||||
cityName: 'foo',
|
||||
count: 30,
|
||||
},
|
||||
{
|
||||
cityName: 'bar',
|
||||
count: 45,
|
||||
},
|
||||
Mock.of<CityStats>({ cityName: 'foo', count: 30 }),
|
||||
Mock.of<CityStats>({ cityName: 'bar', count: 45 }),
|
||||
];
|
||||
const MapModal = () => '';
|
||||
const OpenMapModalBtn = createOpenMapModalBtn(MapModal);
|
||||
const createWrapper = (activeCities) => {
|
||||
wrapper = mount(<OpenMapModalBtn modalTitle={title} locations={locations} activeCities={activeCities} />);
|
||||
const createWrapper = (activeCities: string[] = []) => {
|
||||
wrapper = shallow(<OpenMapModalBtn modalTitle={title} locations={locations} activeCities={activeCities} />);
|
||||
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
afterEach(() => wrapper && wrapper.unmount());
|
||||
afterEach(() => wrapper?.unmount());
|
||||
|
||||
it('renders expected content', () => {
|
||||
const wrapper = createWrapper();
|
||||
@@ -39,21 +34,6 @@ describe('<OpenMapModalBtn />', () => {
|
||||
expect(modal).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('sets provided props to the map', (done) => {
|
||||
const wrapper = createWrapper();
|
||||
const button = wrapper.find('.open-map-modal-btn__btn');
|
||||
|
||||
button.simulate('click');
|
||||
setImmediate(() => {
|
||||
const modal = wrapper.find(MapModal);
|
||||
|
||||
expect(modal.prop('title')).toEqual(title);
|
||||
expect(modal.prop('locations')).toEqual(locations);
|
||||
expect(modal.prop('isOpen')).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('opens dropdown instead of modal when a list of active cities has been provided', (done) => {
|
||||
const wrapper = createWrapper([ 'bar' ]);
|
||||
const button = wrapper.find('.open-map-modal-btn__btn');
|
||||
Reference in New Issue
Block a user