Skip to content

Commit 52a6935

Browse files
committed
commit test #1638
1 parent e7354a1 commit 52a6935

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed
+52-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
11
describe("SpeciesViewModel Spec", function () {
22
it("Can participate in the DataModelItem calls like checkWarnings", function () {
3-
4-
let speciesViewModel = new SpeciesViewModel({}, {searchBieUrl:'/species/searchBie'}, {});
3+
var options = {
4+
searchBieUrl: '/species/searchBie'
5+
}
6+
let speciesViewModel = new SpeciesViewModel({}, options, {});
57
expect(speciesViewModel.checkWarnings()).toBeUndefined();
68
});
9+
10+
it("Same outputSpeciesId is passed when the species has not changed", function (){
11+
var data = {
12+
outputSpeciesId: "5555555",
13+
scientificName: "Test Scientific Name",
14+
name:"Test name",
15+
guid:"Test guid"
16+
};
17+
18+
let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'}
19+
20+
let speciesViewModel = new SpeciesViewModel({}, options, {});
21+
speciesViewModel.loadData(data);
22+
23+
console.log("speciesViewModel.toJS()" + speciesViewModel.toJS().outputSpeciesId);
24+
expect(data.outputSpeciesId).toEqual(speciesViewModel.toJS().outputSpeciesId);
25+
26+
});
27+
28+
it("New outputSpeciesId is passed when the species has changed", function (){
29+
let data = {
30+
outputSpeciesId: "",
31+
scientificName: "Test Scientific Name",
32+
name:"Test name",
33+
guid:"Test guid"
34+
};
35+
36+
let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'}
37+
let responseData = {outputSpeciesId: "55555"};
38+
39+
spyOn($, 'ajax').and.callFake(function () {
40+
var d = $.Deferred();
41+
d.resolve(responseData);
42+
return d.promise();
43+
});
44+
45+
let speciesViewModel = new SpeciesViewModel({}, options, {});
46+
speciesViewModel.loadData(data);
47+
48+
expect($.ajax).toHaveBeenCalled();
49+
expect(data.outputSpeciesId).toEqual(speciesViewModel.outputSpeciesId());
50+
51+
});
52+
53+
function ajax_response(response) {
54+
var deferred = $.Deferred().resolve(response);
55+
return deferred.promise();
56+
}
757
});

0 commit comments

Comments
 (0)