Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit fix on occurrenceId changing every form submit #1638 #262

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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: "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assign a value

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, {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass species data here and change species selection by filling transients(.name, .scientificName, .commonName & .guid) such that it will trigger ajax call when name changes. Happy to chat if it is not clear.

speciesViewModel.loadData(data);

expect($.ajax).toHaveBeenCalled();
expect(data.outputSpeciesId).toEqual(speciesViewModel.outputSpeciesId());

});

function ajax_response(response) {
var deferred = $.Deferred().resolve(response);
return deferred.promise();
}
});
Loading