From 3c5c5b257054a273420689fad468747c0eff4c5b Mon Sep 17 00:00:00 2001 From: Yung Date: Wed, 6 Sep 2017 13:20:01 -0400 Subject: [PATCH] chore(test): fix unit broken unit tests --- spec/attribRecordSpec.js | 8 +++++- spec/attributeSpec.js | 3 ++- spec/dynamicFCSpec.js | 3 ++- spec/esriMapSpec.js | 55 ++++++++++++++++++++++++++++------------ spec/imageRecordSpec.js | 8 +++++- spec/layerRecordSpec.js | 2 ++ 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/spec/attribRecordSpec.js b/spec/attribRecordSpec.js index 81e2e892..ad6ce79f 100644 --- a/spec/attribRecordSpec.js +++ b/spec/attribRecordSpec.js @@ -8,10 +8,12 @@ class FakeExtent { constructor (height, width) { if (height) { this._height = height; } else { this._height = 2; } if (width) { this._width = width; } else { this._width = 2; } + this._spatialReference = new FakeSpatialReference(); } centerAt (point) { return new FakeExtent(point.x / 2, point.y / 2); } getWidth () { return this._width; } + get spatialReference() { return this._spatialReference; } } // A class that mocks the layer class from Esri @@ -33,7 +35,11 @@ class FakeGeoApiEvents { // A class that mocks the SpatialReference class class FakeSpatialReference { - constructor () {} + constructor () { + this._wkid = 1123; + } + + get wkid() { return this._wkid; } } // A class that mocks the proj module from geoApi diff --git a/spec/attributeSpec.js b/spec/attributeSpec.js index 631d246b..4adb2df9 100644 --- a/spec/attributeSpec.js +++ b/spec/attributeSpec.js @@ -36,7 +36,8 @@ describe('Attribute', () => { const fakeGapi = { symbology: { rendererToLegend: () => { return; }, - enhanceRenderer: () => { return; } + enhanceRenderer: () => { return; }, + cleanRenderer: () => { return; } } }; let attribute; diff --git a/spec/dynamicFCSpec.js b/spec/dynamicFCSpec.js index 39e9b80a..dc603ca6 100644 --- a/spec/dynamicFCSpec.js +++ b/spec/dynamicFCSpec.js @@ -16,7 +16,8 @@ describe('DynamicFC', () => { visibleLayers: [ ], setLayerDrawingOptions: (x) => { parent.testField = x; }, setVisibleLayers: (x) => { parent.visibleLayers = x; }, - setVisibility: () => { return; } + setVisibility: () => { return; }, + refresh: () => { return; } }, synchOpacity: () => { return; }, testField: [ ] diff --git a/spec/esriMapSpec.js b/spec/esriMapSpec.js index ffc9a175..f1b8e694 100644 --- a/spec/esriMapSpec.js +++ b/spec/esriMapSpec.js @@ -5,17 +5,41 @@ global.Element = { prototype: {} }; global.Sizzle = {}; const esriMap = require('../src/map/esriMap.js'); +// A class that mocks the ESRI bundle +class FakeEsri { + constructor() { + this._esriConfig = { defaults: { io: {} } } + } + get esriConfig() { + return this._esriConfig; + } + Extent() { + if (arguments.length === 1 ) { + return { xmin: arguments[0].xmin, ymin: arguments[0].ymin, xmax: arguments[0].xmax, ymax: arguments[0].ymax, + spatialReference: { wkid: arguments[0].wkid } }; + } else { + return { xmin: arguments[0], ymin: arguments[1], xmax: arguments[2], ymax: arguments[3], + spatialReference: { wkid: 3978 } }; + } + } + Map() { return { + setExtent: () => { return Promise.resolve('done'); } }; + } + BasemapGallery() { return { add: () => {}, startup: () => {}, on: () => {} }; } + BasemapLayer() { return {}; } + Basemap() { return {}; } +} + describe('ESRI Map', () => { - const fakeEsri = { - esriConfig: { defaults: { io: {} } }, - Extent: fakeEsriExtent, - Map: function () { return { - setExtent: () => { return Promise.resolve('done'); } }; - }, - BasemapGallery: function () { return { add: () => {}, startup: () => {}, on: () => {} }; }, - BasemapLayer: function () { return {}; }, - Basemap: function () { return {}; } - }; + const fakeEsri = new FakeEsri(); + + const fakeGeoApi = { + proj: { + localProjectExtent: () => { + return jsonExtent; + } + } + } const jsonExtent = { uid: 'gray', @@ -40,7 +64,7 @@ describe('ESRI Map', () => { spatialReference: { wkid: json.wkid } }; } - const Map = esriMap(fakeEsri); + const Map = esriMap(fakeEsri, fakeGeoApi); it('should allow the setting of a proxy', () => { const m = new Map(null, mapConfig); @@ -71,11 +95,10 @@ describe('ESRI Map', () => { expect(result[1]).toBeCloseTo(-2681457); }); - // TODO resolve why this test gives "Map.zoomToExtent is not a function" - // it certainly appears to be a function - xit('should zoom the map to an extent', (done) => { - const result = Map.zoomToExtent(Map.getExtentFromJson(jsonExtent)); - result.then( value => { + it('should zoom the map to an extent', (done) => { + const mapObj = new Map(fakeEsri, mapConfig); + const result = mapObj.zoomToExtent(Map.getExtentFromJson(jsonExtent)); + result.then(value => { expect(value).toBe('done'); done(); }) diff --git a/spec/imageRecordSpec.js b/spec/imageRecordSpec.js index e05b652b..1ade24d8 100644 --- a/spec/imageRecordSpec.js +++ b/spec/imageRecordSpec.js @@ -17,9 +17,11 @@ class FakeExtent { } else { this._width = 1; } + this._spatialReference = new FakeSpatialReference(); } getWidth () { return this._width; } + get spatialReference() { return this._spatialReference; } } // A class that mocks the layer class from Esri @@ -41,7 +43,11 @@ class FakeGeoApiEvents { // A class that mocks the SpatialReference class class FakeSpatialReference { - constructor () {} + constructor () { + this._wkid = 1123; + } + + get wkid() { return this._wkid; } } // A class that mocks the proj module from geoApi diff --git a/spec/layerRecordSpec.js b/spec/layerRecordSpec.js index 8e33c225..be9d3e78 100644 --- a/spec/layerRecordSpec.js +++ b/spec/layerRecordSpec.js @@ -22,12 +22,14 @@ class FakeExtent { constructor (height, width) { if (height) { this._height = height; } else { this._height = 2; } if (width) { this._width = width; } else { this._width = 2; } + this._spatialReference = new FakeSpatialReference(); } centerAt (point) { return new FakeExtent(point.x / 2, point.y / 2); } getWidth () { return this._width; } intersects () { return true; } getCenter (point) { return new FakeExtent(point.x / 2, point.y / 2); } + get spatialReference() { return this._spatialReference; } } // A class that mocks the Map class