Splitting tests between api and internal.

This commit is contained in:
Tim Schaub
2012-06-20 11:56:20 +02:00
parent a7a86bb169
commit 14b1a34f98
7 changed files with 38 additions and 37 deletions

View File

@@ -0,0 +1,31 @@
describe("ol.bounds", function() {
it("allows flexible construction", function() {
var bounds, proj;
// array with min/max
bounds = ol.bounds([1, 2, 3, 4]);
expect(bounds.minX()).toBe(1);
expect(bounds.minY()).toBe(2);
expect(bounds.maxX()).toBe(3);
expect(bounds.maxY()).toBe(4);
// object config
bounds = ol.bounds({
minX: 9, maxX: 10, minY: 11, maxY: 12,
projection: ol.projection("bar")
});
expect(bounds.minX()).toBe(9);
expect(bounds.maxX()).toBe(10);
expect(bounds.minY()).toBe(11);
expect(bounds.maxY()).toBe(12);
proj = bounds.projection();
expect(proj).toBeA(ol.Projection);
expect(proj.code()).toBe("bar");
});
});

View File

@@ -0,0 +1,49 @@
describe("ol.geom.geometry", function() {
var g;
beforeEach(function() {
g = ol.geom.geometry();
});
afterEach(function() {
g = null;
});
it("constructs instances", function() {
expect(g).toEqual(jasmine.any(ol.geom.Geometry));
});
it("can set bounds", function() {
var oldBounds = g.bounds();
expect(oldBounds).toBeUndefined();
var b = ol.bounds([0,1,2,3]);
g.bounds(b);
var gotBounds = g.bounds();
expect(gotBounds).not.toBeUndefined();
});
it("can get bounds", function() {
var b = ol.bounds([0,1,2,3]);
g.bounds(b);
var gotBounds = g.bounds();
expect(gotBounds).toEqual(jasmine.any(ol.Bounds));
});
it("sets and gets the correct bounds", function() {
var b = ol.bounds([0,1,2,3]);
g.bounds(b);
var gotBounds = g.bounds();
expect(gotBounds.getMinX()).toEqual(0);
expect(gotBounds.getMinY()).toEqual(1);
expect(gotBounds.getMaxX()).toEqual(2);
expect(gotBounds.getMaxY()).toEqual(3);
});
//
});

126
test/spec/api/loc.test.js Normal file
View File

@@ -0,0 +1,126 @@
describe("ol.loc", function() {
it("allows empty construction", function() {
var loc;
// nowhere
loc = ol.loc();
expect(loc).toBeA(ol.Loc);
});
it("allows construction from an obj config", function() {
var loc;
// obj config
loc = ol.loc({x: 10, y: 20});
expect(loc.x()).toBe(10);
expect(loc.y()).toBe(20);
});
it("allows construction from an array config", function() {
var loc;
// array config
loc = ol.loc([30, 40]);
expect(loc.x()).toBe(30);
expect(loc.y()).toBe(40);
});
it("accounts for the third dimension", function() {
var loc;
// obj config
loc = ol.loc({x: 10, y: 20, z: 30});
expect(loc.z()).toBe(30);
// array config
loc = ol.loc([40, 50, 60]);
expect(loc.z()).toBe(60);
});
it("is mutable", function() {
var loc = ol.loc({x: 10, y: 20, z: 15});
loc.z(30);
expect(loc.x()).toBe(10);
expect(loc.y()).toBe(20);
expect(loc.z()).toBe(30);
});
it("has no default projection", function() {
var loc = ol.loc({x: 1, y: 2});
expect(loc.projection()).toBeUndefined();
});
it("allows projection to be set", function() {
var proj;
// at construction
var loc = ol.loc({x: 1, y: 2, projection: "EPSG:4326"});
proj = loc.projection();
expect(proj).toBeA(ol.Projection);
expect(proj.code()).toBe("EPSG:4326");
// after construction
loc.projection("EPSG:3857");
expect(loc.projection().code()).toBe("EPSG:3857");
// setting projection does not transform coordinates
expect(loc.x()).toBe(1);
expect(loc.y()).toBe(2);
});
it("can be transformed (to mercator)", function() {
var loc = ol.loc({x: 10, y: 20, projection: "EPSG:4326"});
var trans = loc.transform("EPSG:3857");
expect(trans).toBeA(ol.Loc);
expect(trans.projection().code()).toBe("EPSG:3857");
expect(trans.x().toFixed(3)).toBe("1113194.908");
expect(trans.y().toFixed(3)).toBe("2273030.927");
expect(loc.x().toFixed(3)).toBe("10.000");
expect(loc.y().toFixed(3)).toBe("20.000");
});
it("can be transformed (to geographic)", function() {
var loc = ol.loc({x: 1113195, y: 2273031, projection: "EPSG:3857"});
var trans = loc.transform("EPSG:4326");
expect(trans).toBeA(ol.Loc);
expect(trans.projection().code()).toBe("EPSG:4326");
expect(trans.x().toFixed(3)).toBe("10.000");
expect(trans.y().toFixed(3)).toBe("20.000");
});
it("should not be transformable if it has no projection", function() {
var loc = ol.loc([1, 2]);
expect(function() {
loc.transform("EPSG:4326");
}).toThrow();
});
it("is destroyable", function() {
var loc = ol.loc([1, 2]);
loc.destroy();
});
});

291
test/spec/api/map.test.js Normal file
View File

@@ -0,0 +1,291 @@
describe("ol.map", function() {
it("should be easy to make a map", function() {
var map = ol.map();
expect(map).toBeA(ol.Map);
});
it("should be easy to set the map center", function() {
var map, center;
// with array
map = ol.map();
map.center([-110, 45]);
center = map.center();
expect(center.x().toFixed(3)).toBe("-110.000");
expect(center.y().toFixed(3)).toBe("45.000");
expect(center).toBeA(ol.Loc);
// with object literal
map.center({x: -111, y: 46});
center = map.center();
expect(center.x().toFixed(3)).toBe("-111.000");
expect(center.y().toFixed(3)).toBe("46.000");
expect(center).toBeA(ol.Loc);
// more verbose
map = ol.map({
center: ol.loc({x: -112, y: 47})
});
center = map.center();
expect(center.x().toFixed(3)).toBe("-112.000");
expect(center.y().toFixed(3)).toBe("47.000");
expect(center).toBeA(ol.Loc);
});
it("allows flexible setting of center and zoom", function() {
var map, center, zoom;
// chained
map = ol.map().center([1, 2]).zoom(3);
center = map.center();
zoom = map.zoom();
expect(center.x().toFixed(3)).toBe("1.000");
expect(center.y().toFixed(3)).toBe("2.000");
expect(zoom).toBe(3);
// all at once
map = ol.map({
center: [4, 5],
zoom: 6
});
center = map.center();
zoom = map.zoom();
expect(center.x().toFixed(3)).toBe("4.000");
expect(center.y().toFixed(3)).toBe("5.000");
expect(zoom).toBe(6);
});
it("has a default projection", function() {
var map = ol.map();
var proj = map.projection();
expect(proj).toBeA(ol.Projection);
expect(proj.code()).toBe("EPSG:3857");
});
it("allows projection to be set", function() {
var proj;
// at construction
var map = ol.map({
projection: ol.projection("EPSG:4326")
});
proj = map.projection();
expect(proj).toBeA(ol.Projection);
expect(proj.code()).toBe("EPSG:4326");
// after construction
map.projection("EPSG:3857");
proj = map.projection();
expect(proj).toBeA(ol.Projection);
expect(proj.code()).toBe("EPSG:3857");
});
it("has a default user projection in 4326", function() {
var map = ol.map();
var userproj = map.userProjection();
expect(userproj).toBeA(ol.Projection);
expect(userproj.code()).toBe("EPSG:4326");
});
it("allows number of zoom levels to be set", function() {
var map = ol.map();
var nzoom = map.numZoomLevels();
expect(nzoom).toBe(22);
map.numZoomLevels(15);
nzoom = map.numZoomLevels();
expect(nzoom).toBe(15);
});
it("allows a user projection to be set", function() {
var proj;
var map = ol.map();
proj = map.userProjection();
expect(proj).toBeA(ol.Projection);
expect(proj.code()).toBe("EPSG:4326");
map.center([10, 20]);
map.userProjection("EPSG:3857");
var center = map.center();
expect(center.x().toFixed(3)).toBe("1113194.908");
expect(center.y().toFixed(3)).toBe("2273030.927");
});
it("provides feedback when you mess up", function() {
var map;
if (ol.DEBUG) {
// misspelling
expect(function() {
map = ol.map({
centre: [1, 2]
});
}).toThrow(new Error("Unsupported config property: centre"));
} else {
expect(function() {
map = ol.map({
centre: [1, 2]
});
}).not.toThrow();
}
});
it("is destroyable", function() {
var map = ol.map();
map.center([1, 2]);
map.destroy();
expect(goog.isDef(map.layers)).toBe(false);
});
it("allows setting the resolutions array", function() {
var map = ol.map();
map.resolutions([1,2,3]);
var resolutions = map.resolutions();
expect(resolutions.length).toBe(3);
expect(resolutions[0]).toBe(1);
expect(resolutions[1]).toBe(2);
expect(resolutions[2]).toBe(3);
});
it("resolutions array is mutable", function() {
var map = ol.map();
map.resolutions([1,2,3]);
var resolutions = map.resolutions();
expect(resolutions[0]).toBe(1);
map.resolutions([10,9,8,7,6,5]);
resolutions = map.resolutions();
expect(resolutions.length).toBe(6);
expect(resolutions[0]).toBe(10);
expect(resolutions[2]).toBe(8);
expect(resolutions[4]).toBe(6);
});
it("returns correct maxExtent for default map", function() {
var map = ol.map();
var extent = map.maxExtent();
expect(extent).toBeA(ol.Bounds);
expect(extent.minX()).toBe(-20037508.34);
expect(extent.maxX()).toBe(-20037508.34);
expect(extent.minY()).toBe(20037508.34);
expect(extent.maxY()).toBe(20037508.34);
});
it("returns correct maxExtent for custom map extent", function() {
var map = ol.map();
map.maxExtent([-5,-4,7,9]);
var extent = map.maxExtent();
expect(extent).toBeA(ol.Bounds);
expect(extent.minX()).toBe(-5);
expect(extent.maxX()).toBe(-4);
expect(extent.minY()).toBe(7);
expect(extent.maxY()).toBe(9);
});
it("returns correct maxExtent for custom projection extent", function() {
var map = ol.map();
map.projection("CRS:84");
var extent = map.maxExtent();
expect(extent).toBeA(ol.Bounds);
expect(extent.minX()).toBe(-180);
expect(extent.maxX()).toBe(-90);
expect(extent.minY()).toBe(180);
expect(extent.maxY()).toBe(90);
});
it("throws an error whith no maxExtent available", function() {
expect(function(){
map({projection: ol.projection("bar")});
extent = map.maxExtent();
}).toThrow();
});
it("getMaxRes returns correct defaults", function() {
var map = ol.map();
var res = map.maxRes();
expect(res.toFixed(5)).toBe(1.40625);
});
it("allows setting of maxRes", function() {
var map = ol.map({
maxRes: 67
});
var res = map.maxRes();
expect(res).toBe(67);
});
it("getMaxRes returns correct for custom maxExtent", function() {
var map = ol.map({
projection: ol.projection({
maxExtent: [0,0,90,90]
})
});
var res = map.maxRes();
expect(res.toFixed(7)).toBe(0.3515625);
});
it("getResForZoom returns correct defaults", function() {
var map = ol.map();
res = map.getResForZoom(0);
expect(res.toFixed(5)).toBe(1.40625);
res = map.getResForZoom(5);
expect(res.toFixed(10)).toBe(0.0439453125);
});
it("has no layers by default", function() {
var map = ol.map();
var layers = map.layers();
expect(layers).toBe(null);
});
});

View File

@@ -0,0 +1,28 @@
describe("ol.projection", function() {
it("constructs instances", function() {
var p;
p = ol.projection("foo");
expect(p.code()).toBe("foo");
p = ol.projection({
code: "bar",
units: "m"
});
expect(p.code()).toBe("bar");
});
it("allows units to be set", function() {
var p;
p = ol.projection("foo");
expect(p.units()).toBeUndefined();
p = ol.projection({code: "foo", units: "m"});
expect(p.units()).toBe("m");
});
});