diff --git a/src/js/models/metadata/eml211/EMLGeoCoverage.js b/src/js/models/metadata/eml211/EMLGeoCoverage.js index f0b66f84e..c9b93a12e 100644 --- a/src/js/models/metadata/eml211/EMLGeoCoverage.js +++ b/src/js/models/metadata/eml211/EMLGeoCoverage.js @@ -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"); }, /** diff --git a/src/js/views/metadata/EMLGeoCoverageView.js b/src/js/views/metadata/EMLGeoCoverageView.js index ba5245566..6c50c5ba1 100644 --- a/src/js/views/metadata/EMLGeoCoverageView.js +++ b/src/js/views/metadata/EMLGeoCoverageView.js @@ -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(); @@ -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 diff --git a/test/config/tests.json b/test/config/tests.json index a558e0dec..842aa0e71 100644 --- a/test/config/tests.json +++ b/test/config/tests.json @@ -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", diff --git a/test/js/specs/unit/models/metadata/eml211/EMLGeoCoverage.spec.js b/test/js/specs/unit/models/metadata/eml211/EMLGeoCoverage.spec.js new file mode 100644 index 000000000..69cf3e220 --- /dev/null +++ b/test/js/specs/unit/models/metadata/eml211/EMLGeoCoverage.spec.js @@ -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 = ` + Rhine-Main-Observatory + + 9.0005 + 9.0005 + 50.1600 + 50.1600 + + `; + // 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." + // ); + // }); + }); + }); +}); \ No newline at end of file