Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
temi committed Oct 14, 2024
1 parent cddd219 commit 5c03282
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 46 deletions.
7 changes: 6 additions & 1 deletion src/test/js/spec/EnmapifySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
95 changes: 50 additions & 45 deletions src/test/js/spec/SpeciesViewModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);

});
});
})

});

0 comments on commit 5c03282

Please sign in to comment.