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

});
})

});
Loading