summaryrefslogtreecommitdiffstats
path: root/test/generic-components/map/TopographicMap.test.js
blob: b393f4e0a2d0a631024aa02133d3ef57f3d27911 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import TopographicMap from 'generic-components/map/TopographicMap'
import {PROJECTION_TYPES} from "generic-components/map/MapConstants.js"
import React from 'react';
import {shallow, mount} from 'enzyme'

describe('Utility methods tests', () => {
    const sut = shallow(<TopographicMap/>).instance();

    describe('areArraysEqual tests', () => {
        it('Empty arrays should be equal', () => {
             expect(sut.areArraysEqual([], [])).toBe(true);
        });

        it('Nested empty arrays should be equal', () => {
            expect(sut.areArraysEqual([[]], [[]])).toBe(true);
            expect(sut.areArraysEqual([[],[]], [[],[]])).toBe(true);
        });

        it('A nested empty array should not be equal to an empty array', () => {
            expect(sut.areArraysEqual([[]], [])).toBe(false);
        });

        it('Should not coerce elements', () => {
            expect(sut.areArraysEqual([undefined], [null])).toBe(false);
            expect(sut.areArraysEqual([['x']],['x'])).toBe(true);
            expect(sut.areArraysEqual([['xx']],['xx'])).toBe(false);
            expect(sut.areArraysEqual([true], ["true"])).toBe(false);
            expect(sut.areArraysEqual([1], ["1"])).toBe(false);
        });
    });

    describe('extractNestedObjectInJson tests', () => {
        it('Should return an empty object from an empty object', () => {
            expect(sut.extractNestedObjectInJson({},['a'])).toBeUndefined();
            expect(sut.extractNestedObjectInJson({},['a', 'b'])).toBeUndefined();
        });

        it('Should extract a nested element', () => {
            const value = "Foo";
            expect(sut.extractNestedObjectInJson({a:{b: value}},['a', 'b'])).toBe(value);
        });
    });
});

describe('TopographicMap integration tests', () => {
    const svgTag = 'svg';
    const circleTag = 'circle';

    const worldBounds = [
        {longtitude: 28.70, latitude: -127.50},
        {longtitude: 48.85, latitude: -55.90}];

    const outsideUSA = [{longitude: 19.145136, latitude: 51.919438}];
    const insideUSA = [
        {longitude:-122.4196396, latitude:37.7771187},
        {longitude:-122.4196396, latitude:37.6771187},
        {longitude:-122.4196396, latitude:37.5771187},
        {longitude:-122.4196396, latitude:37.4771187}];

    describe('AlbertsUSA projection tests', () => {
        it('Points outside USA should not be supported', () => {
            expect(() => mount(<TopographicMap pointArray={outsideUSA} />)).toThrow();
            expect(() => mount(<TopographicMap pointArray={outsideUSA.concat(insideUSA)} />)).toThrow();
            expect(() => mount(<TopographicMap pointArray={insideUSA.concat(outsideUSA)} />)).toThrow();
        });

        it('Should generate n points on a map', () => {
            const sut = mount(<TopographicMap pointArray={insideUSA} />);
            expect(sut.find(svgTag).find(circleTag).length).toBe(insideUSA.length);
        });
    });

    describe('Equirectangular projection tests', () => {
        function createEquirectangularProjection(points) {
            return mount(<TopographicMap currentProjection={PROJECTION_TYPES.EQUIRECTANGULAR} pointArray={points} />);
        }

        it('Should display points', () => {
            const sutInsideUSA = createEquirectangularProjection(insideUSA);
            const sutOutsideUSA = createEquirectangularProjection(outsideUSA);
            const sutMixed = createEquirectangularProjection(insideUSA.concat(outsideUSA));

            expect(sutInsideUSA.find(svgTag).find(circleTag).length).toBe(insideUSA.length);
            expect(sutOutsideUSA.find(svgTag).find(circleTag).length).toBe(outsideUSA.length);
            expect(sutMixed.find(svgTag).find(circleTag).length).toBe(insideUSA.length + outsideUSA.length);
        });
    });
});