Skip to content

Commit

Permalink
Add tests for EMLGeoCoverage
Browse files Browse the repository at this point in the history
Issue #2159
  • Loading branch information
robyngit committed Nov 1, 2023
1 parent e546dda commit 728c3da
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/js/models/metadata/eml211/EMLGeoCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,10 @@ define(["jquery", "underscore", "backbone", "models/DataONEObject"], function (
* Apply the change event on the parent EML model
*/
trickleUpChange: function () {
this.get("parentModel").trigger("change");
this.get("parentModel").trigger("change:geoCoverage");
const parentModel = this.get("parentModel");
if (!parentModel) return;
parentModel.trigger("change");
parentModel.trigger("change:geoCoverage");
},

/**
Expand Down
5 changes: 2 additions & 3 deletions src/js/views/metadata/EMLGeoCoverageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ define([
* @param {Event} e - The event that triggered this function
*/
updateModel: function (e) {
console.log("updateModel", e);
if (!e) return false;

e.preventDefault();
Expand Down Expand Up @@ -255,8 +254,8 @@ define([
* performs validation across the row and displays any errors. This id
* called when the user clicks out of an edit box on to the page.
*
* @param e The event
* @param options
* @param {Event} e - The event that triggered this function
* @param {Object} options - Validation options
*/
validate: function (e, options) {
//Query for the EMlGeoCoverageView element that the user is actively
Expand Down
1 change: 1 addition & 0 deletions test/config/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"./js/specs/unit/collections/metadata/eml/EMLMissingValueCodes.spec.js",
"./js/specs/unit/models/metadata/eml211/EMLMissingValueCode.spec.js",
"./js/specs/unit/models/metadata/eml211/EMLDistribution.spec.js",
"./js/specs/unit/models/metadata/eml211/EMLGeoCoverage.spec.js",
"./js/specs/unit/models/maps/assets/CesiumImagery.spec.js",
"./js/specs/unit/collections/maps/Geohashes.spec.js",
"./js/specs/unit/models/connectors/Filters-Map.spec.js",
Expand Down
133 changes: 133 additions & 0 deletions test/js/specs/unit/models/metadata/eml211/EMLGeoCoverage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
define([
"../../../../../../../../src/js/models/metadata/eml211/EMLGeoCoverage",
], function (EMLGeoCoverage) {
// Configure the Chai assertion library
var should = chai.should();
var expect = chai.expect;

describe("EMLGeoCoverage Test Suite", function () {
/* Set up */
beforeEach(function () {
let testEML = `<geographicCoverage>
<geographicDescription>Rhine-Main-Observatory</geographicDescription>
<boundingCoordinates>
<westBoundingCoordinate>9.0005</westBoundingCoordinate>
<eastBoundingCoordinate>9.0005</eastBoundingCoordinate>
<northBoundingCoordinate>50.1600</northBoundingCoordinate>
<southBoundingCoordinate>50.1600</southBoundingCoordinate>
</boundingCoordinates>
</geographicCoverage>`;
// remove ALL whitespace
testEML = testEML.replace(/\s/g, "");
this.testEML = testEML;
});

/* Tear down */
afterEach(function () {
delete this.testEML;
});

describe("Initialization", function () {
it("should create a EMLGeoCoverage instance", function () {
new EMLGeoCoverage().should.be.instanceof(EMLGeoCoverage);
});
});

describe("parse()", function () {
it("should parse EML", function () {

var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);

emlGeoCoverage
.get("description")
.should.equal("Rhine-Main-Observatory");
emlGeoCoverage.get("east").should.equal("9.0005");
emlGeoCoverage.get("north").should.equal("50.1600");
emlGeoCoverage.get("south").should.equal("50.1600");
emlGeoCoverage.get("west").should.equal("9.0005");
});
});

describe("serialize()", function () {

it("should serialize to XML", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
var xmlString = emlGeoCoverage.serialize();
xmlString.should.equal(this.testEML);
});
});

describe("validation", function () {
it("should get the status of the coordinates", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
var status = emlGeoCoverage.getCoordinateStatus();
status.north.isSet.should.equal(true);
status.north.isValid.should.equal(true);
status.east.isSet.should.equal(true);
status.east.isValid.should.equal(true);
status.south.isSet.should.equal(true);
status.south.isValid.should.equal(true);
status.west.isSet.should.equal(true);
status.west.isValid.should.equal(true);
});

it("should validate the coordinates", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
var status = emlGeoCoverage.getCoordinateStatus();
var errors = emlGeoCoverage.generateStatusErrors(status);
expect(errors).to.be.empty;
});

it("should give an error if the coordinates are invalid", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
emlGeoCoverage.set("north", "100");
var errors = emlGeoCoverage.validate();
errors.north.should.equal(
"The Northwest latitude must be between -90 and 90."
);
});

it("should give an error if the coordinates are missing", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
emlGeoCoverage.set("north", "");
var errors = emlGeoCoverage.validate();
console.log(errors);
errors.north.should.equal("Each coordinate must include a latitude AND longitude.");
});

// it("should give an error if the north and south coordinates are reversed", function () {
// var emlGeoCoverage = new EMLGeoCoverage(
// { objectDOM: this.testEML },
// { parse: true }
// );
// emlGeoCoverage.set("north", "40");
// emlGeoCoverage.set("south", "50");
// var errors = emlGeoCoverage.validate();
// errors.north.should.equal(
// "The Northwest latitude must be between -90 and 90."
// );
// errors.south.should.equal(
// "The Southeast latitude must be between -90 and 90."
// );
// });
});
});
});

0 comments on commit 728c3da

Please sign in to comment.