-
-
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 unit tests for EMLDistribution model
Issue #1380
- Loading branch information
Showing
3 changed files
with
194 additions
and
1 deletion.
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
189 changes: 189 additions & 0 deletions
189
test/js/specs/unit/models/metadata/eml211/EMLDistribution.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,189 @@ | ||
define([ | ||
"../../../../../../../../src/js/models/metadata/eml211/EMLDistribution", | ||
], function (EMLDistribution) { | ||
// Configure the Chai assertion library | ||
var should = chai.should(); | ||
var expect = chai.expect; | ||
|
||
describe("EMLDistribution Test Suite", function () { | ||
/* Set up */ | ||
beforeEach(function () { | ||
this.emlDistribution = new EMLDistribution(); | ||
}); | ||
|
||
/* Tear down */ | ||
afterEach(function () { | ||
delete this.emlDistribution; | ||
}); | ||
|
||
describe("Initialization", function () { | ||
it("should create a EMLDistribution instance", function () { | ||
new EMLDistribution().should.be.instanceof(EMLDistribution); | ||
}); | ||
}); | ||
|
||
describe("Parse", function () { | ||
it("should parse online URL from EMLDistribution model", function () { | ||
var objectDOM = new DOMParser().parseFromString( | ||
"<distribution>" + | ||
" <online>" + | ||
" <url>http://www.dataone.org</url>" + | ||
" </online>" + | ||
"</distribution>", | ||
"text/xml" | ||
).documentElement; | ||
|
||
var emlDistribution = new EMLDistribution( | ||
{ | ||
objectDOM: objectDOM, | ||
}, | ||
{ parse: true } | ||
); | ||
|
||
emlDistribution.get("url").should.equal("http://www.dataone.org"); | ||
}); | ||
|
||
it("should parse offline elements from EMLDistribution model", function () { | ||
var objectDOM = new DOMParser().parseFromString( | ||
"<distribution>" + | ||
" <offline>" + | ||
" <mediumName>CD-ROM</mediumName>" + | ||
" <mediumVolume>1</mediumVolume>" + | ||
" <mediumFormat>ISO9660</mediumFormat>" + | ||
" <mediumNote>Some notes</mediumNote>" + | ||
" </offline>" + | ||
"</distribution>", | ||
"text/xml" | ||
).documentElement; | ||
|
||
var emlDistribution = new EMLDistribution( | ||
{ | ||
objectDOM: objectDOM, | ||
}, | ||
{ parse: true } | ||
); | ||
|
||
emlDistribution.get("mediumName").should.equal("CD-ROM"); | ||
emlDistribution.get("mediumVolume").should.equal("1"); | ||
emlDistribution.get("mediumFormat").should.equal("ISO9660"); | ||
emlDistribution.get("mediumNote").should.equal("Some notes"); | ||
}); | ||
}); | ||
|
||
describe("Update DOM", function () { | ||
it("should update the DOM with the new values", function () { | ||
var objectDOM = new DOMParser().parseFromString( | ||
"<distribution>" + | ||
" <online>" + | ||
" <url>http://www.dataone.org</url>" + | ||
" </online>" + | ||
"</distribution>", | ||
"text/xml" | ||
).documentElement; | ||
|
||
var emlDistribution = new EMLDistribution( | ||
{ | ||
objectDOM: objectDOM, | ||
}, | ||
{ parse: true } | ||
); | ||
|
||
emlDistribution.set("url", "http://www.dataone.org/updated"); | ||
|
||
var updatedDOM = emlDistribution.updateDOM(); | ||
|
||
updatedDOM | ||
.querySelector("url") | ||
.textContent.should.equal("http://www.dataone.org/updated"); | ||
}); | ||
|
||
it("should create a new node if one does not exist", function () { | ||
var objectDOM = new DOMParser().parseFromString( | ||
"<distribution>" + | ||
" <offline>" + | ||
" <mediumName>CD-ROM</mediumName>" + | ||
" </offline>" + | ||
"</distribution>", | ||
"text/xml" | ||
).documentElement; | ||
|
||
var emlDistribution = new EMLDistribution( | ||
{ | ||
objectDOM: objectDOM, | ||
}, | ||
{ parse: true } | ||
); | ||
|
||
emlDistribution.set("mediumName", "CD-ROM"); | ||
|
||
var updatedDOM = emlDistribution.updateDOM(); | ||
|
||
updatedDOM | ||
.querySelector("mediumName") | ||
.textContent.should.equal("CD-ROM"); | ||
}); | ||
|
||
it("should create a DOM if one doesn't exist", function () { | ||
var emlDistribution = new EMLDistribution({ | ||
mediumName: "CD-ROM", | ||
}); | ||
|
||
var updatedDOM = emlDistribution.updateDOM(); | ||
|
||
updatedDOM | ||
.querySelector("mediumName") | ||
.textContent.should.equal("CD-ROM"); | ||
// check that mediumName is within the offline node | ||
updatedDOM.querySelector("offline > mediumName").should.not.equal(null); | ||
}); | ||
|
||
it("should remove nodes if the value is empty", function () { | ||
var objectDOM = new DOMParser().parseFromString( | ||
"<distribution>" + | ||
" <online>" + | ||
" <url>http://www.dataone.org</url>" + | ||
" </online>" + | ||
"</distribution>", | ||
"text/xml" | ||
).documentElement; | ||
|
||
var emlDistribution = new EMLDistribution( | ||
{ | ||
objectDOM: objectDOM, | ||
}, | ||
{ parse: true } | ||
); | ||
|
||
emlDistribution.set("url", ""); | ||
|
||
var updatedDOM = emlDistribution.updateDOM(); | ||
expect(updatedDOM.querySelector("url")).to.equal(null); | ||
}); | ||
|
||
it("should not remove id, system, nor scope attributes from the distribution node", function () { | ||
var objectDOM = new DOMParser().parseFromString( | ||
"<distribution id='123' system='eml' scope='system'>" + | ||
" <online>" + | ||
" <url>http://www.dataone.org</url>" + | ||
" </online>" + | ||
"</distribution>", | ||
"text/xml" | ||
).documentElement; | ||
|
||
var emlDistribution = new EMLDistribution( | ||
{ | ||
objectDOM: objectDOM, | ||
}, | ||
{ parse: true } | ||
); | ||
|
||
emlDistribution.set("url", ""); | ||
|
||
var updatedDOM = emlDistribution.updateDOM(); | ||
expect(updatedDOM.getAttribute("id")).to.equal("123"); | ||
expect(updatedDOM.getAttribute("system")).to.equal("eml"); | ||
expect(updatedDOM.getAttribute("scope")).to.equal("system"); | ||
}); | ||
}); | ||
}); | ||
}); |