diff --git a/src/components/__tests__/MapCluster.test.js b/src/components/__tests__/MapCluster.test.js new file mode 100644 index 0000000..6577833 --- /dev/null +++ b/src/components/__tests__/MapCluster.test.js @@ -0,0 +1,101 @@ +import React from 'react'; +import { render, screen, waitFor } from '@testing-library/react'; +import MapCluster from '../MapCluster'; + +describe('MapCluster chart', () => { + test('renders MapCluster correctly', async () => { + const props = { + tile: { + url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', + maxZoom: 19, + attribution: '© OpenStreetMap' + }, + data: [ + { + point: [39.61, -105.02], + name: 'Basic', + label: 'This is Littleton, CO.', + color: 'blue' + }, + { + point: [39.73, -104.8], + name: 'Limited', + label: 'This is Aurora, CO.', + color: 'yellow' + } + ], + config: { + center: [39.73, -104.99], + zoom: 10, + height: '100vh', + width: '100%' + } + }; + let instance = null; + render( + { + instance = el; + }} + /> + ); + + await waitFor(() => { + const mapContainer = screen.getByTestId('map-view'); + expect(mapContainer).toBeInTheDocument(); + + expect(instance.getMap().getPixelOrigin()).toEqual({ + x: 54621, + y: 99498 + }); + expect(instance.getMap().getMaxZoom()).toEqual(19); + }); + }); + + test('matches MapCluster snapshot', async () => { + const props = { + tile: { + url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', + maxZoom: 19, + attribution: '© OpenStreetMap' + }, + layer: { + source: 'window.topoData' + }, + data: [ + { + point: [39.61, -105.02], + name: 'Basic', + label: 'This is Littleton, CO.', + color: 'blue' + }, + { + point: [39.73, -104.8], + name: 'Limited', + label: 'This is Aurora, CO.', + color: 'yellow' + } + ], + config: { + center: [39.73, -104.99], + zoom: 10, + height: '100vh', + width: '100%' + } + }; + + let instance = null; + const { container } = render( + { + instance = el; + }} + /> + ); + await waitFor(() => { + expect(container).toMatchSnapshot(); + }); + }); +}); diff --git a/src/components/__tests__/__snapshots__/MapCluster.test.js.snap b/src/components/__tests__/__snapshots__/MapCluster.test.js.snap new file mode 100644 index 0000000..c85b7ae --- /dev/null +++ b/src/components/__tests__/__snapshots__/MapCluster.test.js.snap @@ -0,0 +1,136 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MapCluster chart matches MapCluster snapshot 1`] = ` +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + Leaflet + + + + © OpenStreetMap +
+
+
+
+
+`;