Skip to content

Commit

Permalink
commit test #1638
Browse files Browse the repository at this point in the history
  • Loading branch information
salomon-j committed Oct 12, 2024
1 parent e7354a1 commit 52a6935
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/test/js/spec/SpeciesViewModelSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
describe("SpeciesViewModel Spec", function () {
it("Can participate in the DataModelItem calls like checkWarnings", function () {

let speciesViewModel = new SpeciesViewModel({}, {searchBieUrl:'/species/searchBie'}, {});
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();
}
});

0 comments on commit 52a6935

Please sign in to comment.