Skip to content

Commit

Permalink
test(proj): add tests and docs for proj module
Browse files Browse the repository at this point in the history
  • Loading branch information
alyec committed Nov 24, 2015
1 parent cf159b5 commit 3ee2ac3
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions spec/projSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,50 @@
const projBuilder = require('../src/proj.js');
const proj4 = require('proj4');

// describe declares a test suite
// takes a suite name and a function, all tests within the suite are declared within the function
// besides grouping tests together suites can also do a setup / teardown for each test or for the whole suite
describe('Local projection', () => {

// make up some data for testing
let fakeEsri = { EsriExtent: {} };
const sampleExtent = {
"xmin":-122.68,"ymin":45.53,"xmax":-122.45,"ymax":45.6,
"spatialReference":{"wkid":4326}
};
const sampleData = {x0:-95,y0:49,x1:-94.5,y1:49.5,sr:4326};
const sampleExtent = makeFakeEsriExtent(sampleData);
let proj;

function makeFakeEsriExtent(o) {
return {
"xmin":o.x0,"ymin":o.y0,"xmax":o.x1,"ymax":o.y1,
"spatialReference":{"wkid":o.sr}
};
}

proj4.defs("EPSG:3978", "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
proj4.defs("EPSG:3979", "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
proj4.defs("EPSG:102100", proj4.defs('EPSG:3857'));
proj4.defs("EPSG:54004", "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs");

it('should reproject extents', () => {
const proj = projBuilder(fakeEsri);
// setup function running before each test
beforeEach(() => {
proj = projBuilder(fakeEsri);
});

// each test is also a name and a function
// tests use expect to generate testing assertions
// see the jasmine page for a full list of built in tests
it('should use the target WKID when reprojecting', () => {
let res = proj.localProjectExtent(sampleExtent, 3978);
expect(res.sr).toEqual(3978);
});

it('should reproject from A -> B -> A without deviation within the same projection type', () => {
let res = proj.localProjectExtent(sampleExtent, 54004);
res = proj.localProjectExtent(makeFakeEsriExtent(res),4326);
'x0 x1 y0 y1'.split(' ').forEach(x => expect(res[x]).toBeCloseTo(sampleData[x],5));
});

it('should not fail silently if a projection is not set', () => {
expect(() => proj.localProjectExtent(sampleExtent, 111111)).toThrow();
});

});

0 comments on commit 3ee2ac3

Please sign in to comment.