diff --git a/web/client/actions/__tests__/maps-test.js b/web/client/actions/__tests__/maps-test.js index 284ee44cf2..7b0a091ef8 100644 --- a/web/client/actions/__tests__/maps-test.js +++ b/web/client/actions/__tests__/maps-test.js @@ -7,6 +7,7 @@ */ var expect = require('expect'); +const assign = require('object-assign'); var { // CREATE_THUMBNAIL, createThumbnail, MAP_UPDATING, mapUpdating, @@ -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); @@ -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); + }); }); diff --git a/web/client/actions/__tests__/maptype-test.jsx b/web/client/actions/__tests__/maptype-test.js similarity index 100% rename from web/client/actions/__tests__/maptype-test.jsx rename to web/client/actions/__tests__/maptype-test.js diff --git a/web/client/actions/maps.js b/web/client/actions/maps.js index 45b161bd35..95eefcff00 100644 --- a/web/client/actions/maps.js +++ b/web/client/actions/maps.js @@ -711,5 +711,6 @@ module.exports = { resetUpdating, resetCurrentMap, mapError, - mapsSearchTextChanged + mapsSearchTextChanged, + updateAttribute }; diff --git a/web/client/components/maps/modals/MetadataModal.jsx b/web/client/components/maps/modals/MetadataModal.jsx index 4fbf1d50b1..d16cb0f1f6 100644 --- a/web/client/components/maps/modals/MetadataModal.jsx +++ b/web/client/components/maps/modals/MetadataModal.jsx @@ -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 ); }, diff --git a/web/client/plugins/SaveAs.jsx b/web/client/plugins/SaveAs.jsx index bd22dcb028..d2b7038f42 100644 --- a/web/client/plugins/SaveAs.jsx +++ b/web/client/plugins/SaveAs.jsx @@ -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() + }); }); - }); + } } }); diff --git a/web/client/reducers/__tests__/maps-test.jsx b/web/client/reducers/__tests__/maps-test.js similarity index 100% rename from web/client/reducers/__tests__/maps-test.jsx rename to web/client/reducers/__tests__/maps-test.js diff --git a/web/client/test-resources/geostore/resources/resource/1/attributes/thumbnail/value.json b/web/client/test-resources/geostore/resources/resource/1/attributes/thumbnail/value.json new file mode 100644 index 0000000000..984e798aa0 --- /dev/null +++ b/web/client/test-resources/geostore/resources/resource/1/attributes/thumbnail/value.json @@ -0,0 +1,3 @@ +{ + 2431 +} diff --git a/web/client/test-resources/geostore/resources/resource/1/permissions b/web/client/test-resources/geostore/resources/resource/1/permissions new file mode 100644 index 0000000000..e69de29bb2