diff --git a/src/test/js/spec/EnmapifySpec.js b/src/test/js/spec/EnmapifySpec.js index dc8ccaf..5cfa94b 100644 --- a/src/test/js/spec/EnmapifySpec.js +++ b/src/test/js/spec/EnmapifySpec.js @@ -504,9 +504,10 @@ describe("Enmapify Spec", function () { describe("Test ajax call to manual create point", function() { var request, result; - jasmine.Ajax.install(); + beforeEach(function() { + jasmine.Ajax.install(); result = enmapify(options); result.viewModel.transients.editCoordinates(true); options.container["TestLatitude"](0); @@ -520,6 +521,10 @@ describe("Enmapify Spec", function () { expect(request.method).toBe('GET'); }); + afterEach(function() { + jasmine.Ajax.uninstall(); + }); + it("should add point to map and dismiss coordinate fields", function() { request.respondWith({ status: 200, diff --git a/src/test/js/spec/SpeciesViewModelSpec.js b/src/test/js/spec/SpeciesViewModelSpec.js index 802541f..4601757 100644 --- a/src/test/js/spec/SpeciesViewModelSpec.js +++ b/src/test/js/spec/SpeciesViewModelSpec.js @@ -6,15 +6,6 @@ describe("SpeciesViewModel Spec", function () { // request = jasmine.Ajax.requests.mostRecent(); // expect(request.method).toBe('GET'); // }); - - afterEach(function() { - jasmine.Ajax.uninstall(); - }); - - beforeEach(function() { - jasmine.Ajax.install(); - }); - it("Can participate in the DataModelItem calls like checkWarnings", function () { var options = { searchBieUrl: '/species/searchBie' @@ -40,58 +31,72 @@ describe("SpeciesViewModel Spec", function () { }); - it("New outputSpeciesId is passed when the species has changed", function (){ - let oldSpeciesSelectedData = { - outputSpeciesId: '5555555', - scientificName: 'Current scientific Name', - name: 'Current name', - guid: 'Current guid' - } + describe("Test outputSpeciesId", function () { + beforeEach(function() { + jasmine.Ajax.install(); + }); - let newSpeciesSelectedData = { - scientificName: 'New scientific Name', - name: 'New name', - guid: 'New guid' - }; + afterEach(function() { + jasmine.Ajax.uninstall(); + }); + it("New outputSpeciesId is passed when the species has changed", function (){ + let oldSpeciesSelectedData = { + outputSpeciesId: '5555555', + scientificName: 'Current scientific Name', + name: 'Current name', + guid: 'Current guid' + } - let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'} - let responseData = {outputSpeciesId: "666666"}; + let newSpeciesSelectedData = { + scientificName: 'New scientific Name', + name: 'New name', + guid: 'New guid' + }; - // spyOn($, 'ajax').and.callFake(function () { - // var d = $.Deferred(); - // d.resolve(responseData); - // return d.promise(); - // }); + let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'} + let responseData = {outputSpeciesId: "666666"}; + // spyOn($, 'ajax').and.callFake(function () { + // var d = $.Deferred(); + // d.resolve(responseData); + // return d.promise(); + // }); - let speciesViewModel = new SpeciesViewModel(oldSpeciesSelectedData, options, {}); - // spyOn($, 'ajax').and.callFake(function () { - // var d = $.Deferred(); - // d.resolve(responseData); - // return d.promise(); - // }); - speciesViewModel.loadData(newSpeciesSelectedData); - request = jasmine.Ajax.requests.mostRecent(); + let speciesViewModel = new SpeciesViewModel(oldSpeciesSelectedData, options, {}); + // spyOn($, 'ajax').and.callFake(function () { + // var d = $.Deferred(); + // d.resolve(responseData); + // return d.promise(); + // }); - request.respondWith({ - status: 200, - responseJSON: responseData - }); + // request = jasmine.Ajax.requests.mostRecent(); + // request.respondWith({ + // status: 200, + // responseJSON: responseData + // }); + speciesViewModel.loadData(newSpeciesSelectedData); + request = jasmine.Ajax.requests.filter('test/getOutputSpeciesIdUrl')[0]; + request.respondWith({ + status: 200, + responseJSON: responseData + }); - // expect(request.url).toBe('test/getOutputSpeciesIdUrl'); - expect(speciesViewModel.toJS().outputSpeciesId).toEqual(responseData.outputSpeciesId) - expect(speciesViewModel.outputSpeciesId()).not.toEqual(oldSpeciesSelectedData.outputSpeciesId); + // expect(request.url).toBe('test/getOutputSpeciesIdUrl'); + expect(speciesViewModel.toJS().outputSpeciesId).toEqual(responseData.outputSpeciesId) + + expect(speciesViewModel.outputSpeciesId()).not.toEqual(oldSpeciesSelectedData.outputSpeciesId); // expect($.ajax).toHaveBeenCalled(); - // expect(speciesViewModel.toJS().outputSpeciesId).toEqual(responseData.outputSpeciesId); + // expect(speciesViewModel.toJS().outputSpeciesId).toEqual(responseData.outputSpeciesId); - }); + }); + }) }); \ No newline at end of file