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