Skip to content

Commit

Permalink
Fix geo tests & minor bugs found while testing
Browse files Browse the repository at this point in the history
- Set up new geo tests

Issues #2180 and #2189
  • Loading branch information
robyngit committed Oct 17, 2023
1 parent 7f4103b commit b245cca
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 62 deletions.
23 changes: 21 additions & 2 deletions src/js/models/filters/SpatialFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,25 @@ define([
}
},

/**
* Remove the listeners.
* @since x.x.x
*/
removeListeners: function () {
const extentEvents =
"change:height change:north change:south change:east change:west";
this.stopListening(this, extentEvents);
},

/**
* Set a listener that updates the filter when the coordinates & height
* change
* @since 2.25.0
*/
setListeners: function () {
this.removeListeners();
const extentEvents =
"change:height change:north change:south change:east change:west";
this.stopListening(this, extentEvents);
this.listenTo(this, extentEvents, this.updateFilterFromExtent);
},

Expand Down Expand Up @@ -318,7 +328,13 @@ define([
* @inheritdoc
*/
resetValue: function () {
const df = this.defaults();
// Need to stop listeners because otherwise changing the coords will
// update the filter values. This sometimes updates the values *after*
// the values are reset, preventing the reset from working.
this.removeListeners();

let df = this.defaults();

this.set({
values: df.values,
east: df.east,
Expand All @@ -327,6 +343,9 @@ define([
south: df.south,
height: df.height,
});

// Reset the listeners
this.setListeners();
},
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/js/models/maps/Geohash.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ define([
},
properties: properties,
};
if (label) {
if (label && (properties[label] || properties[label] === 0)) {
(feature["label"] = {
text: properties[label].toString(),
text: properties[label]?.toString(),
show: true,
fillColor: {
rgba: [255, 255, 255, 255],
Expand Down
2 changes: 1 addition & 1 deletion src/js/models/maps/assets/CesiumGeohash.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ define([
const limit = this.get("maxGeoHashes");
const geohashes = this.get("geohashes")
const area = this.getViewExtent().getArea();
return this.get("geohashes").getMaxPrecision(area, limit);
return geohashes.getMaxPrecision(area, limit);
},

/**
Expand Down
6 changes: 6 additions & 0 deletions test/config/tests.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"unit": [
"./js/specs/unit/collections/maps/GeoPoints.spec.js",
"./js/specs/unit/models/connectors/GeoPoints-Cesium.spec.js",
"./js/specs/unit/models/connectors/GeoPoints-CesiumPoints.spec.js",
"./js/specs/unit/models/connectors/GeoPoints-CesiumPolygon.spec.js",
"./js/specs/unit/models/maps/GeoBoundingBox.spec.js",
"./js/specs/unit/models/maps/GeoUtilities.spec.js",
"./js/specs/unit/collections/SolrResults.spec.js",
"./js/specs/unit/models/Search.spec.js",
"./js/specs/unit/models/filters/Filter.spec.js",
Expand Down
21 changes: 21 additions & 0 deletions test/js/specs/unit/collections/maps/GeoPoints.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"../../../../../../../../src/js/collections/maps/GeoPoints",
], function (GeoPoints) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("GeoPoints Test Suite", function () {
/* Set up */
beforeEach(function () {});

/* Tear down */
afterEach(function () {});

describe("Initialization", function () {
it("should create a GeoPoints instance", function () {
new GeoPoints().should.be.instanceof(GeoPoints);
});
});
});
});
47 changes: 0 additions & 47 deletions test/js/specs/unit/collections/maps/Geohashes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,9 @@ define(["../../../../../../../../src/js/collections/maps/Geohashes"], function (
.validatePrecision([1, 2, 3])
.should.deep.equal([1, 2, 3]);
});

it("should validate a valid bounding box", function () {
const bounds = { north: 80, south: -80, east: 170, west: 160 };
this.geohashes.boundsAreValid(bounds).should.be.true;
});

it("should invalidate a bounding box with invalid bounds", function () {
const bounds = { north: 80, south: -80, east: 170, west: 190 };
this.geohashes.boundsAreValid(bounds).should.be.false;
});

it("should invalidate a bounding box with missing bounds", function () {
const bounds = { north: 80, south: -80, east: 170 };
this.geohashes.boundsAreValid(bounds).should.be.false;
});

it("should invalidate a bounding box with non-number bounds", function () {
const bounds = { north: 80, south: -80, east: 170, west: "west" };
this.geohashes.boundsAreValid(bounds).should.be.false;
});
});

describe("Bounds", function () {
it("should split a bounding box that crosses the prime meridian", function () {
const bounds = { north: 80, south: -80, east: -170, west: 170 };
const expected = [
{ north: 80, south: -80, east: 180, west: 170 },
{ north: 80, south: -80, east: -170, west: -180 },
];
this.geohashes.splitBoundingBox(bounds).should.deep.equal(expected);
});

it("should not split a bounding box that does not cross the prime meridian", function () {
const bounds = { north: 80, south: -80, east: 170, west: 160 };
const expected = [{ north: 80, south: -80, east: 170, west: 160 }];
this.geohashes.splitBoundingBox(bounds).should.deep.equal(expected);
});

it("should get the area of a geohash tile", function () {
const precision = 5;
const expected = 0.0019311904907226562;
Expand All @@ -117,18 +82,6 @@ define(["../../../../../../../../src/js/collections/maps/Geohashes"], function (
.getGeohashAreas(minPrecision, maxPrecision)
.should.deep.equal(expected);
});

it("should get the area of the world", function () {
const bounds = { north: 90, south: -90, east: 180, west: -180 };
const expected = 360 * 180;
this.geohashes.getBoundingBoxArea(bounds).should.equal(expected);
});

it("should get the area of a small bounding box", function () {
const bounds = { north: 45, south: 44, east: 45, west: 44 };
const expected = 1;
this.geohashes.getBoundingBoxArea(bounds).should.equal(expected);
});
});

describe("Precision", function () {
Expand Down
4 changes: 2 additions & 2 deletions test/js/specs/unit/models/connectors/Filters-Map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ define([
const map = this.filtersMap.get("map");
const spatialFilters = this.filtersMap.get("spatialFilters");
const extent = { north: 1, south: 2, east: 3, west: 4 };
map.set("currentViewExtent", extent);
map.get("interactions").setViewExtent(extent);
this.filtersMap.updateSpatialFilters();
spatialFilters[0].get("north").should.equal(1);
spatialFilters[0].get("south").should.equal(2);
Expand Down Expand Up @@ -80,6 +80,6 @@ define([
const spatialFilters = this.filtersMap.get("spatialFilters");
spatialFilters[0].get("values").should.deep.equal([]);
});
});
});
});
});
21 changes: 21 additions & 0 deletions test/js/specs/unit/models/connectors/GeoPoints-Cesium.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"../../../../../../../../src/js/models/connectors/GeoPoints-Cesium",
], function (GeoPointsCesium) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("GeoPointsCesium Test Suite", function () {
/* Set up */
beforeEach(function () {});

/* Tear down */
afterEach(function () {});

describe("Initialization", function () {
it("should create a GeoPointsCesium instance", function () {
new GeoPointsCesium().should.be.instanceof(GeoPointsCesium);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"../../../../../../../../src/js/models/connectors/GeoPoints-CesiumPoints",
], function (GeoPointsCesiumPoints) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("GeoPointsCesiumPoints Test Suite", function () {
/* Set up */
beforeEach(function () {});

/* Tear down */
afterEach(function () {});

describe("Initialization", function () {
it("should create a GeoPointsCesiumPoints instance", function () {
new GeoPointsCesiumPoints().should.be.instanceof(GeoPointsCesiumPoints);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"../../../../../../../../src/js/models/connectors/GeoPoints-CesiumPolygon",
], function (GeoPointsCesiumPolygon) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("GeoPointsCesiumPolygon Test Suite", function () {
/* Set up */
beforeEach(function () {});

/* Tear down */
afterEach(function () {});

describe("Initialization", function () {
it("should create a GeoPointsCesiumPolygon instance", function () {
new GeoPointsCesiumPolygon().should.be.instanceof(GeoPointsCesiumPolygon);
});
});
});
});
21 changes: 21 additions & 0 deletions test/js/specs/unit/models/maps/GeoBoundingBox.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"../../../../../../../../src/js/models/maps/GeoBoundingBox",
], function (GeoBoundingBox) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("GeoBoundingBox Test Suite", function () {
/* Set up */
beforeEach(function () {});

/* Tear down */
afterEach(function () {});

describe("Initialization", function () {
it("should create a GeoBoundingBox instance", function () {
new GeoBoundingBox().should.be.instanceof(GeoBoundingBox);
});
});
});
});
21 changes: 21 additions & 0 deletions test/js/specs/unit/models/maps/GeoUtilities.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define([
"../../../../../../../../src/js/models/maps/GeoUtilities",
], function (GeoUtilities) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("GeoUtilities Test Suite", function () {
/* Set up */
beforeEach(function () {});

/* Tear down */
afterEach(function () {});

describe("Initialization", function () {
it("should create a GeoUtilities instance", function () {
new GeoUtilities().should.be.instanceof(GeoUtilities);
});
});
});
});
9 changes: 5 additions & 4 deletions test/js/specs/unit/models/maps/assets/CesiumGeohash.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
define([
"../../../../../../../../src/js/models/maps/assets/CesiumGeohash",
"../../../../../../../../src/js/collections/maps/Geohashes",
"../../../../../../../../src/js/models/maps/Map",
], function (CesiumGeohash, Geohashes) {
], function (CesiumGeohash, MapModel) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("CesiumGeohash Test Suite", function () {
/* Set up */
beforeEach(function () {
this.map = new Map();
this.map = new MapModel();
this.model = new CesiumGeohash();
this.model.set("mapModel", this.map);
});
Expand Down Expand Up @@ -83,7 +82,9 @@ define([
it("should get the precision", function () {
this.model.replaceGeohashes();
this.model.set("maxGeoHashes", 32);
this.map.set("currentViewExtent", {
console.log(this.map.attributes);
console.log(this.map.get("interactions"));
this.map.get("interactions").setViewExtent({
north: 90,
south: -90,
east: 180,
Expand Down
6 changes: 2 additions & 4 deletions test/js/specs/unit/models/maps/assets/CesiumImagery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ define([
describe("Creating the Cesium Model", function () {

it("should convert list of degrees to a Cesium rectangle", function (done) {
const expectedRect = Cesium.Rectangle.fromDegrees(...boundingBox)
imagery.whenReady().then(function (model) {
const rect = model.get("cesiumOptions").rectangle
const rectsEqual = Cesium.Rectangle.equals(rect, expectedRect)
rectsEqual.should.be.true
const rect = model.get("cesiumModel").rectangle
expect(rect.constructor.name).to.equal("Rectangle")
done()
}, function (error) {
done(error)
Expand Down

0 comments on commit b245cca

Please sign in to comment.