Skip to content

Commit

Permalink
Merge pull request #1498 from ushahidi/develop
Browse files Browse the repository at this point in the history
Prepare release select-all fix
  • Loading branch information
AmTryingMyBest authored Apr 16, 2020
2 parents 5ba8fa4 + 331bb0e commit 458025d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
21 changes: 19 additions & 2 deletions app/main/posts/views/filters/filter-form.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/main/posts/views/filters/filter-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

<div class="form-field checkbox" ng-show="forms.length > 5">
<label>
<input type="checkbox" name="selectedForms" ng-model="all"><em><span translate="category.select_all"></span></em>
<input type="checkbox" name="selectedForms" ng-checked="checkAll" ng-click="toggleAll()"><em><span translate="category.select_all"></span></em>
</label>
</div>
<div class="form-field checkbox" ng-repeat="(index, form) in forms">
<label>
<input checklist-value="form.id" checklist-model="selectedForms" type="checkbox" name="selectedForms" ng-checked="all"> <bdi>{{ ::form.name }}</bdi>
<input checklist-value="form.id" checklist-model="selectedForms" type="checkbox" name="selectedForms"> <bdi>{{ ::form.name }}</bdi>
</label>
</div>
<div class="form-field checkbox">
<label>
<input checklist-value="'none'" checklist-model="selectedForms" type="checkbox" name="selectedForms" ng-checked="all" > <span translate="nav.unknown">Unknown</span>
<input checklist-value="'none'" checklist-model="selectedForms" type="checkbox" name="selectedForms"> <span translate="nav.unknown">Unknown</span>
</label>
</div>
</fieldset>
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ describe('user profile directive', 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 = '[email protected]';
});

describe('after calling saveUser', function () {
Expand All @@ -60,19 +64,54 @@ 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': '[email protected]',
'realname': 'Changed name'
}
)
);
expect(isolateScope.user.realname).toBe('Changed name');
expect(isolateScope.user.email).toBe('[email protected]');
expect(Notify.notify).toHaveBeenCalledWith('user_profile.update_success');
expect(Notify.apiErrors).toHaveBeenCalledTimes(0)
expect(Session.setSessionDataEntries).toHaveBeenCalledWith(
{'email': '[email protected]', 'realname': 'Changed name'}
);
});

it('should set user to the new data', function () {
expect(isolateScope.user.someField).toBe('addedByServer');
});
});
});

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: {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/mock/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module.exports = [function () {
successCallback({
realname: 'Changed name',
id: 1,
someField: 'addedByServer'
someField: 'addedByServer',
email: '[email protected]'
});
} else {
failCallback({
Expand Down

0 comments on commit 458025d

Please sign in to comment.