-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for MissingValueCode model & collection
Issue #612
- Loading branch information
Showing
5 changed files
with
185 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
test/js/specs/unit/collections/metadata/eml/EMLMissingValueCodes.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
define([ | ||
"../../../../../../../../src/js/collections/metadata/eml/EMLMissingValueCodes", | ||
], function (EMLMissingValueCodes) { | ||
// Configure the Chai assertion library | ||
var should = chai.should(); | ||
var expect = chai.expect; | ||
|
||
describe("EMLMissingValueCodes Test Suite", function () { | ||
/* Set up */ | ||
beforeEach(function () { | ||
this.emlMissingValueCodes = new EMLMissingValueCodes(); | ||
}); | ||
|
||
/* Tear down */ | ||
afterEach(function () { | ||
delete this.emlMissingValueCodes; | ||
}); | ||
|
||
describe("Initialization", function () { | ||
it("should create a EMLMissingValueCodes instance", function () { | ||
new EMLMissingValueCodes().should.be.instanceof(EMLMissingValueCodes); | ||
}); | ||
}); | ||
|
||
describe("Parsing", function () { | ||
it("should parse an EMLMissingValueCodes from XML", function () { | ||
var xmlString = `<missingValueCode> | ||
<code>9999</code> | ||
<codeExplanation>Sensor down</codeExplanation> | ||
</missingValueCode> | ||
<missingValueCode> | ||
<code>9998</code> | ||
<codeExplanation>Technician error</codeExplanation> | ||
</missingValueCode>`; | ||
|
||
this.emlMissingValueCodes.parse(xmlString); | ||
|
||
this.emlMissingValueCodes.length.should.equal(2); | ||
this.emlMissingValueCodes.at(0).get("code").should.equal("9999"); | ||
this.emlMissingValueCodes | ||
.at(0) | ||
.get("codeExplanation") | ||
.should.equal("Sensor down"); | ||
this.emlMissingValueCodes.at(1).get("code").should.equal("9998"); | ||
this.emlMissingValueCodes | ||
.at(1) | ||
.get("codeExplanation") | ||
.should.equal("Technician error"); | ||
|
||
}); | ||
}); | ||
|
||
describe("Validation", function () { | ||
it("should validate valid EMLMissingValueCodes", function () { | ||
this.emlMissingValueCodes.add({ | ||
code: "9999", | ||
codeExplanation: "Sensor down", | ||
}) | ||
var errors = this.emlMissingValueCodes.validate(); | ||
|
||
expect(errors).to.be.null; | ||
}); | ||
|
||
it("should validate invalid EMLMissingValueCodes", function () { | ||
|
||
this.emlMissingValueCodes.add({ | ||
code: "", | ||
codeExplanation: "Sensor down", | ||
}) | ||
|
||
var errors = this.emlMissingValueCodes.validate(); | ||
|
||
errors.should.be.an("object"); | ||
errors.should.have.property("missingValueCode"); | ||
errors.missingValueCode.should.be.a("string"); | ||
|
||
}); | ||
}); | ||
|
||
}); | ||
}); |
78 changes: 78 additions & 0 deletions
78
test/js/specs/unit/models/metadata/eml211/EMLMissingValueCode.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
define([ | ||
"../../../../../../../../src/js/models/metadata/eml211/EMLMissingValueCode", | ||
], function (EMLMissingValueCode) { | ||
// Configure the Chai assertion library | ||
var should = chai.should(); | ||
var expect = chai.expect; | ||
|
||
describe("EMLMissingValueCode Test Suite", function () { | ||
/* Set up */ | ||
beforeEach(function () { | ||
this.emlMissingValueCode = new EMLMissingValueCode(); | ||
}); | ||
|
||
/* Tear down */ | ||
afterEach(function () { | ||
delete this.emlMissingValueCode; | ||
}); | ||
|
||
describe("Initialization", function () { | ||
it("should create a EMLMissingValueCode instance", function () { | ||
new EMLMissingValueCode().should.be.instanceof(EMLMissingValueCode); | ||
}); | ||
}); | ||
|
||
describe("Parsing", function () { | ||
it("should parse an EMLMissingValueCode from XML", function () { | ||
var xmlString = | ||
"<missingValueCode><code>9999</code><codeExplanation>Missing value</codeExplanation></missingValueCode>"; | ||
|
||
var emlMissingValueCode = new EMLMissingValueCode( | ||
{ | ||
objectDOM: xmlString, | ||
}, | ||
{ parse: true } | ||
); | ||
emlMissingValueCode.get("code").should.equal("9999"); | ||
emlMissingValueCode | ||
.get("codeExplanation") | ||
.should.equal("Missing value"); | ||
}); | ||
}); | ||
|
||
describe("Serializing", function () { | ||
it("should serialize the EMLMissingValueCode to XML", function () { | ||
var emlMissingValueCode = new EMLMissingValueCode({ | ||
code: "9999", | ||
codeExplanation: "Missing value", | ||
}); | ||
var xmlString = emlMissingValueCode.serialize(); | ||
xmlString.should.be.a("string"); | ||
xmlString.should.equal( | ||
"<missingValueCode><code>9999</code><codeExplanation>Missing value</codeExplanation></missingValueCode>" | ||
); | ||
}); | ||
}); | ||
|
||
describe("Validation", function () { | ||
it("should validate a valid EMLMissingValueCode", function () { | ||
var emlMissingValueCode = new EMLMissingValueCode({ | ||
code: "9999", | ||
codeExplanation: "Missing value", | ||
}); | ||
var errors = emlMissingValueCode.validate(); | ||
expect(errors).to.be.undefined; | ||
}); | ||
|
||
it("should not validate an invalid EMLMissingValueCode", function () { | ||
var emlMissingValueCode = new EMLMissingValueCode({ | ||
code: "-999", | ||
codeExplanation: "", | ||
}); | ||
var errors = emlMissingValueCode.validate(); | ||
expect(errors).to.be.an("object"); | ||
expect(errors.missingValueCode).to.be.a("string"); | ||
}); | ||
}); | ||
}); | ||
}); |