From b75fd2e03af71fc47c093789534f6464507de7dd Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 11 Jun 2022 17:38:12 +0200 Subject: [PATCH] Migrated MapModal test to react testing library --- test/visits/helpers/MapModal.test.tsx | 43 +--- .../__snapshots__/MapModal.test.tsx.snap | 183 ++++++++++++++++++ 2 files changed, 188 insertions(+), 38 deletions(-) create mode 100644 test/visits/helpers/__snapshots__/MapModal.test.tsx.snap diff --git a/test/visits/helpers/MapModal.test.tsx b/test/visits/helpers/MapModal.test.tsx index f582a582..2b053896 100644 --- a/test/visits/helpers/MapModal.test.tsx +++ b/test/visits/helpers/MapModal.test.tsx @@ -1,14 +1,9 @@ -import { shallow, ShallowWrapper } from 'enzyme'; -import { Marker, Popup } from 'react-leaflet'; -import { Modal } from 'reactstrap'; +import { render, screen } from '@testing-library/react'; import { MapModal } from '../../../src/visits/helpers/MapModal'; import { CityStats } from '../../../src/visits/types'; describe('', () => { - let wrapper: ShallowWrapper; - const toggle = () => ''; - const isOpen = true; - const title = 'Foobar'; + const toggle = jest.fn(); const zaragozaLat = 41.6563497; const zaragozaLong = -0.876566; const newYorkLat = 40.730610; @@ -26,36 +21,8 @@ describe('', () => { }, ]; - beforeEach(() => { - wrapper = shallow(); - }); - - afterEach(() => wrapper.unmount()); - - it('renders modal with provided props', () => { - const modal = wrapper.find(Modal); - const header = wrapper.find('.map-modal__modal-title'); - - expect(modal.prop('toggle')).toEqual(toggle); - expect(modal.prop('isOpen')).toEqual(isOpen); - expect(header.find('.btn-close').prop('onClick')).toEqual(toggle); - expect(header.text()).toContain(title); - }); - - 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}`); - }); + it('renders expected map', () => { + render(); + expect(screen.getByRole('dialog')).toMatchSnapshot(); }); }); diff --git a/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap b/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap new file mode 100644 index 00000000..efe77267 --- /dev/null +++ b/test/visits/helpers/__snapshots__/MapModal.test.tsx.snap @@ -0,0 +1,183 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` renders expected map 1`] = ` +