From 52a693567c2a752a345bd0509a829ab59c9afe81 Mon Sep 17 00:00:00 2001 From: sal153 Date: Sun, 13 Oct 2024 10:44:02 +1100 Subject: [PATCH] commit test #1638 --- src/test/js/spec/SpeciesViewModelSpec.js | 54 +++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/test/js/spec/SpeciesViewModelSpec.js b/src/test/js/spec/SpeciesViewModelSpec.js index b5176a41..92639a19 100644 --- a/src/test/js/spec/SpeciesViewModelSpec.js +++ b/src/test/js/spec/SpeciesViewModelSpec.js @@ -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(); + } }); \ No newline at end of file