Skip to content

Commit

Permalink
Merge pull request #262 from AtlasOfLivingAustralia/feature/issue1638
Browse files Browse the repository at this point in the history
commit fix on occurrenceId changing every form submit #1638
  • Loading branch information
temi authored Oct 14, 2024
2 parents 4ce5a04 + 72ceb91 commit 99e8e08
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
6 changes: 4 additions & 2 deletions grails-app/assets/javascripts/speciesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ var SpeciesViewModel = function(data, options, context) {
name:self.name(),
scientificName:self.scientificName(),
commonName:self.commonName(),
listId:self.listId
listId:self.listId,
outputSpeciesId:self.outputSpeciesId()
}
};

Expand All @@ -298,9 +299,10 @@ var SpeciesViewModel = function(data, options, context) {
if (!data) data = {};

self.guid(orBlank(data.guid || data.lsid));
self.name(orBlank(data.name));
self.outputSpeciesId(orBlank(data.outputSpeciesId));
self.listId(orBlank(data.listId));
self.scientificName(orBlank(data.scientificName));
self.name(orBlank(data.name));

if (!data.commonName) {
if (data.kvpValues) {
Expand Down
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
67 changes: 65 additions & 2 deletions src/test/js/spec/SpeciesViewModelSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,70 @@
describe("SpeciesViewModel Spec", function () {
var request, result;
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);

expect(data.outputSpeciesId).toEqual(speciesViewModel.toJS().outputSpeciesId);

});

describe("Test ajax call to supply new outSpeciesId", function () {
beforeEach(function() {
jasmine.Ajax.install();
});

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 newSpeciesSelectedData = {
scientificName: 'New scientific Name',
name: 'New name',
guid: 'New guid'
};

let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'}
let responseData = {outputSpeciesId: "666666"};

let speciesViewModel = new SpeciesViewModel(oldSpeciesSelectedData, options, {});

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);

});
})

});

0 comments on commit 99e8e08

Please sign in to comment.