Skip to content

Commit 99e8e08

Browse files
authored
Merge pull request #262 from AtlasOfLivingAustralia/feature/issue1638
commit fix on occurrenceId changing every form submit #1638
2 parents 4ce5a04 + 72ceb91 commit 99e8e08

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

grails-app/assets/javascripts/speciesModel.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ var SpeciesViewModel = function(data, options, context) {
286286
name:self.name(),
287287
scientificName:self.scientificName(),
288288
commonName:self.commonName(),
289-
listId:self.listId
289+
listId:self.listId,
290+
outputSpeciesId:self.outputSpeciesId()
290291
}
291292
};
292293

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

300301
self.guid(orBlank(data.guid || data.lsid));
301-
self.name(orBlank(data.name));
302+
self.outputSpeciesId(orBlank(data.outputSpeciesId));
302303
self.listId(orBlank(data.listId));
303304
self.scientificName(orBlank(data.scientificName));
305+
self.name(orBlank(data.name));
304306

305307
if (!data.commonName) {
306308
if (data.kvpValues) {

src/test/js/spec/EnmapifySpec.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,10 @@ describe("Enmapify Spec", function () {
504504

505505
describe("Test ajax call to manual create point", function() {
506506
var request, result;
507-
jasmine.Ajax.install();
507+
508508

509509
beforeEach(function() {
510+
jasmine.Ajax.install();
510511
result = enmapify(options);
511512
result.viewModel.transients.editCoordinates(true);
512513
options.container["TestLatitude"](0);
@@ -520,6 +521,10 @@ describe("Enmapify Spec", function () {
520521
expect(request.method).toBe('GET');
521522
});
522523

524+
afterEach(function() {
525+
jasmine.Ajax.uninstall();
526+
});
527+
523528
it("should add point to map and dismiss coordinate fields", function() {
524529
request.respondWith({
525530
status: 200,
+65-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,70 @@
11
describe("SpeciesViewModel Spec", function () {
2+
var request, result;
23
it("Can participate in the DataModelItem calls like checkWarnings", function () {
3-
4-
let speciesViewModel = new SpeciesViewModel({}, {searchBieUrl:'/species/searchBie'}, {});
4+
var options = {
5+
searchBieUrl: '/species/searchBie'
6+
}
7+
let speciesViewModel = new SpeciesViewModel({}, options, {});
58
expect(speciesViewModel.checkWarnings()).toBeUndefined();
69
});
10+
11+
it("Same outputSpeciesId is passed when the species has not changed", function (){
12+
var data = {
13+
outputSpeciesId: "5555555",
14+
scientificName: "Test Scientific Name",
15+
name:"Test name",
16+
guid:"Test guid"
17+
};
18+
19+
let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'}
20+
21+
let speciesViewModel = new SpeciesViewModel({}, options, {});
22+
speciesViewModel.loadData(data);
23+
24+
expect(data.outputSpeciesId).toEqual(speciesViewModel.toJS().outputSpeciesId);
25+
26+
});
27+
28+
describe("Test ajax call to supply new outSpeciesId", function () {
29+
beforeEach(function() {
30+
jasmine.Ajax.install();
31+
});
32+
33+
afterEach(function() {
34+
jasmine.Ajax.uninstall();
35+
});
36+
37+
it("New outputSpeciesId is passed when the species has changed", function (){
38+
let oldSpeciesSelectedData = {
39+
outputSpeciesId: '5555555',
40+
scientificName: 'Current scientific Name',
41+
name: 'Current name',
42+
guid: 'Current guid'
43+
}
44+
45+
let newSpeciesSelectedData = {
46+
scientificName: 'New scientific Name',
47+
name: 'New name',
48+
guid: 'New guid'
49+
};
50+
51+
let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'}
52+
let responseData = {outputSpeciesId: "666666"};
53+
54+
let speciesViewModel = new SpeciesViewModel(oldSpeciesSelectedData, options, {});
55+
56+
speciesViewModel.loadData(newSpeciesSelectedData);
57+
request = jasmine.Ajax.requests.filter('test/getOutputSpeciesIdUrl')[0];
58+
request.respondWith({
59+
status: 200,
60+
responseJSON: responseData
61+
});
62+
63+
expect(request.url).toBe('test/getOutputSpeciesIdUrl');
64+
expect(speciesViewModel.toJS().outputSpeciesId).toEqual(responseData.outputSpeciesId)
65+
expect(speciesViewModel.outputSpeciesId()).not.toEqual(oldSpeciesSelectedData.outputSpeciesId);
66+
67+
});
68+
})
69+
770
});

0 commit comments

Comments
 (0)