From: andrzejszukuc Date: Thu, 14 Mar 2019 11:28:39 +0000 (+0100) Subject: Add tests for TopographicMap X-Git-Tag: 1.4.0~5 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fsparky-fe.git;a=commitdiff_plain;h=5b062c1f5005e14b6f18563ee875a06f5c1bc299 Add tests for TopographicMap Change-Id: Ifaac36ba87862dfc09837a6f18b50092ef43ad25 Issue-ID: AAI-2143 Signed-off-by: Andrzej Szukuc --- diff --git a/test/generic-components/map/TopographicMap.test.js b/test/generic-components/map/TopographicMap.test.js new file mode 100644 index 0000000..b393f4e --- /dev/null +++ b/test/generic-components/map/TopographicMap.test.js @@ -0,0 +1,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().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()).toThrow(); + expect(() => mount()).toThrow(); + expect(() => mount()).toThrow(); + }); + + it('Should generate n points on a map', () => { + const sut = mount(); + expect(sut.find(svgTag).find(circleTag).length).toBe(insideUSA.length); + }); + }); + + describe('Equirectangular projection tests', () => { + function createEquirectangularProjection(points) { + return mount(); + } + + 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); + }); + }); +});