From 80b2459be66368a407a14cdb785ab9fd3d883981 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Tue, 24 Mar 2020 10:47:54 +0545 Subject: [PATCH 1/3] 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 3c6fe59e9affb7eef15718a1afb749e46ca76ef8 Mon Sep 17 00:00:00 2001 From: Romina Date: Fri, 10 Apr 2020 05:01:57 -0300 Subject: [PATCH 2/3] 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 3/3] 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')));