Skip to content

Commit

Permalink
fixed save as with empty name and added tests (#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 authored May 15, 2017
1 parent 735f9a3 commit 650b5c4
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 9 deletions.
126 changes: 124 additions & 2 deletions web/client/actions/__tests__/maps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

var expect = require('expect');
const assign = require('object-assign');
var {
// CREATE_THUMBNAIL, createThumbnail,
MAP_UPDATING, mapUpdating,
Expand All @@ -19,12 +20,123 @@ var {
RESET_CURRENT_MAP, resetCurrentMap,
MAPS_SEARCH_TEXT_CHANGED, mapsSearchTextChanged,
MAPS_LIST_LOAD_ERROR, loadError,
MAP_ERROR, mapError,
MAP_METADATA_UPDATED, mapMetadataUpdated
MAP_ERROR, mapError, updatePermissions,
MAP_METADATA_UPDATED, mapMetadataUpdated,
METADATA_CHANGED, metadataChanged,
updateAttribute, saveAll
} = require('../maps');
let GeoStoreDAO = require('../../api/GeoStoreDAO');
let oldAddBaseUri = GeoStoreDAO.addBaseUrl;

describe('Test correctness of the maps actions', () => {
beforeEach(() => {
GeoStoreDAO.addBaseUrl = (options) => {
return assign(options, {baseURL: 'base/web/client/test-resources/geostore/'});
};
});
afterEach(() => {
GeoStoreDAO.addBaseUrl = oldAddBaseUri;
});
it('updateAttribute with error', (done) => {
const value = "asdSADs";
const name = "thumbnail";
const resourceId = -1;
const type = "STRING";
const retFun = updateAttribute(resourceId, name, value, type, {});
expect(retFun).toExist();
retFun((action) => {
expect(action.type).toBe(THUMBNAIL_ERROR);
done();

});

});
it('updateAttribute', (done) => {
const value = "value.json";
const name = "thumbnail";
const resourceId = 1;
const type = "STRING";
const retFun = updateAttribute(resourceId, name, value, type, {});
expect(retFun).toExist();
let count = 0;
retFun((action) => {
expect(action.type).toBe(ATTRIBUTE_UPDATED);
count++;
if (count === 1) {
done();
}
});
});
it('saveAll - with metadataMap, without thumbnail', (done) => {
const resourceId = 1;
// saveAll(map, metadataMap, nameThumbnail, dataThumbnail, categoryThumbnail, resourceIdMap, options)
const retFun = saveAll({}, {name: "name"}, null, null, null, resourceId, {});
expect(retFun).toExist();
let count = 0;
retFun((action) => {
switch (count) {
case 0: expect(action.type).toBe(MAP_UPDATING); break;
case 1: expect(action.type).toBe("NONE"); break;
default: done();
}
count++;
});
});
it('saveAll - with metadataMap, without thumbnail', (done) => {
const resourceId = 1;
// saveAll(map, metadataMap, nameThumbnail, dataThumbnail, categoryThumbnail, resourceIdMap, options)
const retFun = saveAll({}, null, null, null, null, resourceId, {});
expect(retFun).toExist();
let count = 0;
retFun((action) => {
switch (count) {
case 0: expect(action.type).toBe(MAP_UPDATING); break;
case 1: expect(action.type).toBe("NONE"); break;
case 2: expect(action.type).toBe(RESET_UPDATING); break;
case 3: expect(action.type).toBe(DISPLAY_METADATA_EDIT); break;
default: done();
}
count++;
});
});
it('updatePermissions with securityRules list & without', (done) => {
const securityRules = {
SecurityRuleList: {
RuleCount: 1,
SecurityRule: [{
canRead: true,
canWrite: true,
user: {
id: 1
}
}]
}
};
const resourceId = 1;
const retFun = updatePermissions(resourceId, securityRules);
expect(retFun).toExist();
let count = 0;
retFun((action) => {
switch (count) {
// TODO: this should return PERMISSIONS_UPDATED
case 0: expect(action.type).toBe(PERMISSIONS_UPDATED); break;
default: done();
}
count++;
done();
});
const retFun2 = updatePermissions(-1, securityRules);
expect(retFun).toExist();
let count2 = 0;
retFun2((action) => {
switch (count2) {
case 0: expect(action.type).toBe(THUMBNAIL_ERROR); break;
default: done();
}
count2++;
done();
});
});
it('mapUpdating', () => {
let resourceId = 13;
var retval = mapUpdating(resourceId);
Expand Down Expand Up @@ -121,4 +233,14 @@ describe('Test correctness of the maps actions', () => {
expect(a.result).toBe("result");
expect(a.error).toBe("error");
});
it('mapMetadatachanged', () => {
const prop = "name";
const value = "newName";
const a = metadataChanged(prop, value);
expect(a.type).toBe(METADATA_CHANGED);
expect(a.prop).toExist();
expect(a.value).toExist();
expect(a.prop).toBe(prop);
expect(a.value).toBe(value);
});
});
3 changes: 2 additions & 1 deletion web/client/actions/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,5 +711,6 @@ module.exports = {
resetUpdating,
resetCurrentMap,
mapError,
mapsSearchTextChanged
mapsSearchTextChanged,
updateAttribute
};
2 changes: 2 additions & 0 deletions web/client/components/maps/modals/MetadataModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ const MetadataModal = React.createClass({
},
isMetadataChanged() {
return this.props.map && (
this.props.map.description !== undefined &&
this.props.metadata.description !== this.props.map.description ||
this.props.map.name !== undefined &&
this.props.metadata.name !== this.props.map.name
);
},
Expand Down
14 changes: 8 additions & 6 deletions web/client/plugins/SaveAs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ const SaveAs = React.createClass({
description,
attributes
};
thumbComponent.getThumbnailDataUri( (data) => {
this.props.onMapSave(metadata, JSON.stringify(this.createV2Map()), {
data,
category: "THUMBNAIL",
name: thumbComponent.generateUUID()
if (metadata.name !== "") {
thumbComponent.getThumbnailDataUri( (data) => {
this.props.onMapSave(metadata, JSON.stringify(this.createV2Map()), {
data,
category: "THUMBNAIL",
name: thumbComponent.generateUUID()
});
});
});
}
}
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
2431
}
Empty file.

0 comments on commit 650b5c4

Please sign in to comment.