From 80b2459be66368a407a14cdb785ab9fd3d883981 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Tue, 24 Mar 2020 10:47:54 +0545 Subject: [PATCH 1/6] test: user profile & session update --- .../directives/user-profile-directive-spec.js | 45 +++++++++++++++++-- test/unit/mock/services/user.js | 3 +- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/test/unit/common/user-profile/directives/user-profile-directive-spec.js b/test/unit/common/user-profile/directives/user-profile-directive-spec.js index 31797073b5..e80d4640d3 100644 --- a/test/unit/common/user-profile/directives/user-profile-directive-spec.js +++ b/test/unit/common/user-profile/directives/user-profile-directive-spec.js @@ -44,14 +44,18 @@ describe('user profile directive', function () { }); describe('saveUser', function () { - describe('with a successfull backend call', function () { + describe('with a successful backend call', function () { beforeEach(function () { spyOn(UserEndpoint, 'update').and.callThrough(); + spyOn(Session, 'setSessionDataEntries').and.callThrough(); + spyOn(Notify, 'apiErrors') + spyOn(Notify, 'notify').and.callThrough(); }); describe('after changed values of user', function () { beforeEach(function () { isolateScope.user.realname = 'Changed name'; + isolateScope.user.email = 'changed@ushahidi.com'; }); describe('after calling saveUser', function () { @@ -60,8 +64,21 @@ describe('user profile directive', function () { }); it('should call "update" on the UserEndpoint with id=me and the changed user profile values', function () { - expect(UserEndpoint.update).toHaveBeenCalled(); + expect(UserEndpoint.update).toHaveBeenCalledWith( + {id: 'me'}, + jasmine.objectContaining({ + 'email': 'changed@ushahidi.com', + 'realname': 'Changed name' + } + ) + ); expect(isolateScope.user.realname).toBe('Changed name'); + expect(isolateScope.user.email).toBe('changed@ushahidi.com'); + expect(Notify.notify).toHaveBeenCalledWith('user_profile.update_success'); + expect(Notify.apiErrors).toHaveBeenCalledTimes(0) + expect(Session.setSessionDataEntries).toHaveBeenCalledWith( + {'email': 'changed@ushahidi.com', 'realname': 'Changed name'} + ); }); it('should set user to the new data', function () { @@ -69,10 +86,32 @@ describe('user profile directive', function () { }); }); }); + + describe('after changed the password of the user', function () { + beforeEach(function () { + isolateScope.user.password = 'changed'; + }); + + describe('after calling saveUser', function () { + beforeEach(function () { + isolateScope.saveUser(isolateScope.user); + }); + + it('should call "update" on the UserEndpoint with the changed password', function () { + expect(UserEndpoint.update).toHaveBeenCalledWith( + {id: 'me'}, + jasmine.objectContaining({ + 'password': 'changed' + } + ) + ); + expect(Notify.apiErrors).toHaveBeenCalledTimes(0) + }); + }); + }); }); describe('with an error on the backend call', function () { - var errorResponse = { status: 400, data: { diff --git a/test/unit/mock/services/user.js b/test/unit/mock/services/user.js index 043594270d..e865439c76 100644 --- a/test/unit/mock/services/user.js +++ b/test/unit/mock/services/user.js @@ -47,7 +47,8 @@ module.exports = [function () { successCallback({ realname: 'Changed name', id: 1, - someField: 'addedByServer' + someField: 'addedByServer', + email: 'changed@ushahidi.com' }); } else { failCallback({ From a9ccbb90d4d2e58bf837b903baf2310f744a1321 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 26 Mar 2020 09:59:59 +0100 Subject: [PATCH 2/6] Adding a new confirm delete-notification w extra check --- app/common/locales/en.json | 8 ++-- app/common/notifications/notify.service.js | 49 +++++++++++++++++++++- app/settings/surveys/surveys.controller.js | 2 +- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index c0012a864e..b7ccf03520 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -319,7 +319,7 @@ "delete" : { "desc" : "If you delete this survey, all of its posts will also be deleted. Proceed with caution.", "delete" : "Delete survey", - "delete_this" : "Delete this survey", + "delete_this" : "Delete this surve", "delete_this_field" : "Delete this field", "delete_field" : "Delete field", "desc_field" : "If you delete this field, all of the data that was collected within it will also be deleted. Proceed with caution." @@ -1523,8 +1523,10 @@ "save_attribute_success" : "Field {{name}} added", "edit_form_success" : "Survey {{name}} updated", "edit_stage_success" : "Survey task {{name}} updated", - "delete_form_confirm" : "Are you sure you want to delete this survey?", - "delete_form_confirm_desc" : "This action cannot be undone. Deleting this survey will remove all of its data, including posts.", + "delete_form_confirm" : "Are you sure you want to delete this survey and all its posts?", + "delete_form_confirm_desc" : "This action cannot be undone. Deleting this survey will remove all of its data, including posts. Write the name of the survey:

{{check_name}}

in the box below to confirm deletion.", + "delete_form_error": "The text you entered does not match the survey-name, please try again", + "delete_form_button": "Delete this survey", "destroy_form_success" : "Survey {{name}} deleted", "delete_stage_confirm" : "Are you sure you want to delete this task?", "delete_stage_confirm_desc" : "This action cannot be undone. Deleting this task will remove all of its fields, and any data in them.", diff --git a/app/common/notifications/notify.service.js b/app/common/notifications/notify.service.js index 7002d62258..a86655cf66 100644 --- a/app/common/notifications/notify.service.js +++ b/app/common/notifications/notify.service.js @@ -22,7 +22,8 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo infoModal: infoModal, confirmLeave: confirmLeave, demo: demo, - notifyPermanent: notifyPermanent + notifyPermanent: notifyPermanent, + deleteWithInput: deleteWithInput }; function notify(message, translateValues) { @@ -217,7 +218,52 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo return deferred.promise; } + function deleteWithInput (type, checkName) { + var scope = getScope(); + var deferred = $q.defer(); + scope.noequal = false; + + const modalText = { + survey: { + title: 'notify.form.delete_form_confirm', + modalBody: 'notify.form.delete_form_confirm_desc', + errorLabel: 'notify.form.delete_form_error', + button: 'notify.form.delete_form_button' + } + }; + + var texts = modalText[type]; + $translate(texts.modalBody, {check_name: checkName}).then(show, show); + + function show(body) { + + scope.confirm = function (name) { + if (name === checkName) { + scope.noequal = false; + deferred.resolve(); + ModalService.close(); + } else { + scope.noequal = true; + } + }; + + scope.cancel = function () { + deferred.reject(); + ModalService.close(); + }; + + ModalService.openTemplate( + `
+

${body}

+

${texts.errorLabel}

+ + + +
`, texts.title, false, scope, false, false); + } + return deferred.promise; + } function confirmDelete(confirmText, confirmWarningText, translateValues) { var deferred = $q.defer(); @@ -227,7 +273,6 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo translateValues = confirmWarningText; confirmWarningText = false; } - $translate(confirmText, translateValues).then(show, show); function show(confirmText) { diff --git a/app/settings/surveys/surveys.controller.js b/app/settings/surveys/surveys.controller.js index 63ab14e9ba..fdbbcccb78 100644 --- a/app/settings/surveys/surveys.controller.js +++ b/app/settings/surveys/surveys.controller.js @@ -49,7 +49,7 @@ function ( }; $scope.deleteSurvey = function (survey) { - Notify.confirmDelete('notify.form.delete_form_confirm', 'notify.form.delete_form_confirm_desc').then(function () { + Notify.deleteWithInput('survey', survey.name).then(function () { // If we haven't saved the survey // just go back to the surveys views if (!survey.id) { From 6f718669725cd6f3a301fec98e0a6d71466c0572 Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 26 Mar 2020 10:00:30 +0100 Subject: [PATCH 3/6] adding test --- .../common/notifications/notify.service.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/unit/common/notifications/notify.service.spec.js b/test/unit/common/notifications/notify.service.spec.js index 79d657364d..ce1777a257 100644 --- a/test/unit/common/notifications/notify.service.spec.js +++ b/test/unit/common/notifications/notify.service.spec.js @@ -203,6 +203,21 @@ describe('Notify', function () { }); }); + describe('deleteWithInput', function () { + beforeEach(function () { + spyOn(mockModalService, 'openTemplate').and.callThrough(); + spyOn(mockSliderService, 'openTemplate').and.callThrough(); + }); + + it('Calls ModalService.openTemplate with error message', function () { + mockModalService.state = false; + Notify.deleteWithInput('survey', 'this is the name of the survey'); + $rootScope.$digest(); + expect(mockModalService.openTemplate).toHaveBeenCalled(); + }); + }); + + describe('limit', function () { beforeEach(function () { spyOn(mockSliderService, 'openTemplate').and.callThrough(); From 6ad82b4d5b97c7ced57bb0e5ed3000b7112ef6a2 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 27 Mar 2020 11:31:42 +0100 Subject: [PATCH 4/6] tweaks to confirmation-notification --- app/common/locales/en.json | 4 ++-- app/common/notifications/notify.service.js | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index b7ccf03520..92c7bc8e61 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -319,7 +319,7 @@ "delete" : { "desc" : "If you delete this survey, all of its posts will also be deleted. Proceed with caution.", "delete" : "Delete survey", - "delete_this" : "Delete this surve", + "delete_this" : "Delete this survey", "delete_this_field" : "Delete this field", "delete_field" : "Delete field", "desc_field" : "If you delete this field, all of the data that was collected within it will also be deleted. Proceed with caution." @@ -1523,7 +1523,7 @@ "save_attribute_success" : "Field {{name}} added", "edit_form_success" : "Survey {{name}} updated", "edit_stage_success" : "Survey task {{name}} updated", - "delete_form_confirm" : "Are you sure you want to delete this survey and all its posts?", + "delete_form_confirm" : "Are you sure you want to delete this survey and all of its data?", "delete_form_confirm_desc" : "This action cannot be undone. Deleting this survey will remove all of its data, including posts. Write the name of the survey:

{{check_name}}

in the box below to confirm deletion.", "delete_form_error": "The text you entered does not match the survey-name, please try again", "delete_form_button": "Delete this survey", diff --git a/app/common/notifications/notify.service.js b/app/common/notifications/notify.service.js index a86655cf66..56b0f6aff3 100644 --- a/app/common/notifications/notify.service.js +++ b/app/common/notifications/notify.service.js @@ -221,7 +221,7 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo function deleteWithInput (type, checkName) { var scope = getScope(); var deferred = $q.defer(); - scope.noequal = false; + scope.isEqual = true; const modalText = { survey: { @@ -237,14 +237,11 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo $translate(texts.modalBody, {check_name: checkName}).then(show, show); function show(body) { - scope.confirm = function (name) { - if (name === checkName) { - scope.noequal = false; + scope.isEqual = name === checkName; + if (scope.isEqual) { deferred.resolve(); ModalService.close(); - } else { - scope.noequal = true; } }; @@ -256,7 +253,7 @@ function Notify(_, $q, $rootScope, $translate, SliderService, ModalService, Demo ModalService.openTemplate( `

${body}

-

${texts.errorLabel}

+

${texts.errorLabel}

From 3c6fe59e9affb7eef15718a1afb749e46ca76ef8 Mon Sep 17 00:00:00 2001 From: Romina Date: Fri, 10 Apr 2020 05:01:57 -0300 Subject: [PATCH 5/6] Fix(SelectAll for surveys): update the model correctly on check/uncheck all --- .../views/filters/filter-form.directive.js | 21 +++++++++++++++++-- app/main/posts/views/filters/filter-form.html | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/main/posts/views/filters/filter-form.directive.js b/app/main/posts/views/filters/filter-form.directive.js index 816766b558..2c7e5d8302 100644 --- a/app/main/posts/views/filters/filter-form.directive.js +++ b/app/main/posts/views/filters/filter-form.directive.js @@ -12,15 +12,24 @@ function FormSelectDirective(FormEndpoint) { }; function FormSelectLink(scope, element, attrs, ngModel) { + scope.checkAll = true; if (!ngModel) { return; } scope.forms = []; scope.selectedForms = []; - + scope.toggleAll = toggleAll; activate(); - + function toggleAll() { + if (!scope.checkAll) { + scope.checkAll = true; + Array.prototype.splice.apply(scope.selectedForms, [0, scope.selectedForms.length].concat(scope.forms.map(f => f.id).concat('none'))); + } else { + scope.checkAll = false; + Array.prototype.splice.apply(scope.selectedForms, [0, scope.selectedForms.length]); + } + } function activate() { // Load forms scope.forms = FormEndpoint.query(); @@ -35,6 +44,14 @@ function FormSelectDirective(FormEndpoint) { } function saveValueToView(selectedForms) { + // the length +1 check is because we add 'none' through ng-models for unknown survey type (messages with no post) + // this "fixes" the usecase where the user manually selected/unselected all checkboxes + const sameValues = selectedForms.length === scope.forms.length + 1; + if (!sameValues && scope.checkAll === true) { + scope.checkAll = false; + } else if (sameValues && scope.checkAll === false) { + scope.checkAll = true; + } ngModel.$setViewValue(angular.copy(selectedForms)); } } diff --git a/app/main/posts/views/filters/filter-form.html b/app/main/posts/views/filters/filter-form.html index 2a25257bc7..2280dd906f 100644 --- a/app/main/posts/views/filters/filter-form.html +++ b/app/main/posts/views/filters/filter-form.html @@ -3,17 +3,17 @@
From d6c395536971458377f91ba17f8a3840fd641d94 Mon Sep 17 00:00:00 2001 From: Romina Suarez Date: Mon, 13 Apr 2020 08:39:48 -0300 Subject: [PATCH 6/6] Update filter-form.directive.js Remove trailing spaces --- app/main/posts/views/filters/filter-form.directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main/posts/views/filters/filter-form.directive.js b/app/main/posts/views/filters/filter-form.directive.js index 2c7e5d8302..2b3c1dd9aa 100644 --- a/app/main/posts/views/filters/filter-form.directive.js +++ b/app/main/posts/views/filters/filter-form.directive.js @@ -21,7 +21,7 @@ function FormSelectDirective(FormEndpoint) { scope.selectedForms = []; scope.toggleAll = toggleAll; activate(); - function toggleAll() { + function toggleAll() { if (!scope.checkAll) { scope.checkAll = true; Array.prototype.splice.apply(scope.selectedForms, [0, scope.selectedForms.length].concat(scope.forms.map(f => f.id).concat('none')));