Skip to content

Commit

Permalink
chore(test): fix unit broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barryytm committed Sep 6, 2017
1 parent 11494ac commit 3c5c5b2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 20 deletions.
8 changes: 7 additions & 1 deletion spec/attribRecordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/attributeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ describe('Attribute', () => {
const fakeGapi = {
symbology: {
rendererToLegend: () => { return; },
enhanceRenderer: () => { return; }
enhanceRenderer: () => { return; },
cleanRenderer: () => { return; }
}
};
let attribute;
Expand Down
3 changes: 2 additions & 1 deletion spec/dynamicFCSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [ ]
Expand Down
55 changes: 39 additions & 16 deletions spec/esriMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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();
})
Expand Down
8 changes: 7 additions & 1 deletion spec/imageRecordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/layerRecordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c5c5b2

Please sign in to comment.