1 import TopographicMap from 'generic-components/map/TopographicMap'
2 import {PROJECTION_TYPES} from "generic-components/map/MapConstants.js"
3 import React from 'react';
4 import {shallow, mount} from 'enzyme'
6 describe('Utility methods tests', () => {
7 const sut = shallow(<TopographicMap/>).instance();
9 describe('areArraysEqual tests', () => {
10 it('Empty arrays should be equal', () => {
11 expect(sut.areArraysEqual([], [])).toBe(true);
14 it('Nested empty arrays should be equal', () => {
15 expect(sut.areArraysEqual([[]], [[]])).toBe(true);
16 expect(sut.areArraysEqual([[],[]], [[],[]])).toBe(true);
19 it('A nested empty array should not be equal to an empty array', () => {
20 expect(sut.areArraysEqual([[]], [])).toBe(false);
23 it('Should not coerce elements', () => {
24 expect(sut.areArraysEqual([undefined], [null])).toBe(false);
25 expect(sut.areArraysEqual([['x']],['x'])).toBe(true);
26 expect(sut.areArraysEqual([['xx']],['xx'])).toBe(false);
27 expect(sut.areArraysEqual([true], ["true"])).toBe(false);
28 expect(sut.areArraysEqual([1], ["1"])).toBe(false);
32 describe('extractNestedObjectInJson tests', () => {
33 it('Should return an empty object from an empty object', () => {
34 expect(sut.extractNestedObjectInJson({},['a'])).toBeUndefined();
35 expect(sut.extractNestedObjectInJson({},['a', 'b'])).toBeUndefined();
38 it('Should extract a nested element', () => {
40 expect(sut.extractNestedObjectInJson({a:{b: value}},['a', 'b'])).toBe(value);
45 describe('TopographicMap integration tests', () => {
47 const circleTag = 'circle';
50 {longtitude: 28.70, latitude: -127.50},
51 {longtitude: 48.85, latitude: -55.90}];
53 const outsideUSA = [{longitude: 19.145136, latitude: 51.919438}];
55 {longitude:-122.4196396, latitude:37.7771187},
56 {longitude:-122.4196396, latitude:37.6771187},
57 {longitude:-122.4196396, latitude:37.5771187},
58 {longitude:-122.4196396, latitude:37.4771187}];
60 describe('AlbertsUSA projection tests', () => {
61 it('Points outside USA should not be supported', () => {
62 expect(() => mount(<TopographicMap pointArray={outsideUSA} />)).toThrow();
63 expect(() => mount(<TopographicMap pointArray={outsideUSA.concat(insideUSA)} />)).toThrow();
64 expect(() => mount(<TopographicMap pointArray={insideUSA.concat(outsideUSA)} />)).toThrow();
67 it('Should generate n points on a map', () => {
68 const sut = mount(<TopographicMap pointArray={insideUSA} />);
69 expect(sut.find(svgTag).find(circleTag).length).toBe(insideUSA.length);
73 describe('Equirectangular projection tests', () => {
74 function createEquirectangularProjection(points) {
75 return mount(<TopographicMap currentProjection={PROJECTION_TYPES.EQUIRECTANGULAR} pointArray={points} />);
78 it('Should display points', () => {
79 const sutInsideUSA = createEquirectangularProjection(insideUSA);
80 const sutOutsideUSA = createEquirectangularProjection(outsideUSA);
81 const sutMixed = createEquirectangularProjection(insideUSA.concat(outsideUSA));
83 expect(sutInsideUSA.find(svgTag).find(circleTag).length).toBe(insideUSA.length);
84 expect(sutOutsideUSA.find(svgTag).find(circleTag).length).toBe(outsideUSA.length);
85 expect(sutMixed.find(svgTag).find(circleTag).length).toBe(insideUSA.length + outsideUSA.length);