Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSESPRT-57: Handle disabled review fields while Creating/Editing awards #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions ang/civiawards/award-creation/directives/award.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
});

module.controller('CiviAwardCreateEditAwardController', function (
$location, $q, $scope, $window, CaseStatus,
$location, $q, $scope, $window, CaseStatus, isTruthy,
civicaseCrmApi, crmStatus, Select2Utils, ts) {
var existingCaseTypeDefintion = null;

Expand Down Expand Up @@ -326,13 +326,22 @@
* @returns {object[]} list of selected review field ids
*/
function prepareReviewFields () {
return _.map($scope.additionalDetails.selectedReviewFields, function (reviewField) {
return {
id: reviewField.id,
required: reviewField.required ? '1' : '0',
weight: reviewField.weight
};
});
return _.chain($scope.additionalDetails.selectedReviewFields)
.filter(function (reviewField) {
reviewField = _.find($scope.reviewFields, function (field) {
return field.id === reviewField.id;
});

return isTruthy(reviewField.is_active);
})
.map(function (reviewField) {
return {
id: reviewField.id,
required: reviewField.required ? '1' : '0',
weight: reviewField.weight
};
})
.value();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
<tbody>
<tr
ng-repeat="reviewField in model.reviewFields | filter: model.searchText"
ng-attr-title="{{reviewField.is_active === '0' ? 'This field is disabled.' : ''}}"
ng-class="{ disabled: !model.isTruthy(reviewField.is_active) }"
ng-click="model.toggleReviewField(reviewField)">
<td>{{reviewField.label}}</td>
<td align="center">
<input
ng-checked="!!model.findReviewFieldByID(reviewField.id)"
ng-disabled="!model.isTruthy(reviewField.is_active)"
type="checkbox"/>
</td>
<td>{{reviewField.data_type}}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
<tbody>
<tr
ng-repeat="reviewField in additionalDetails.selectedReviewFields | orderBy: 'weight'"
ng-if="additionalDetails.selectedReviewFields.length > 0">
<td>{{getReviewFieldData(reviewField.id, 'label')}}</td>
ng-if="additionalDetails.selectedReviewFields.length > 0 && isTruthy(getReviewFieldData(reviewField.id, 'is_active'))">
<td>
{{getReviewFieldData(reviewField.id, 'label')}}
</td>
<td>
<a
class="crm-weight-arrow" ng-if="$index > 0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$scope.openReviewFieldSelectionPopup = openReviewFieldSelectionPopup;
$scope.removeReviewFieldFromSelection = removeReviewFieldFromSelection;
$scope.findReviewFieldByID = findReviewFieldByID;
$scope.isTruthy = isTruthy;
$scope.toggleRequiredState = toggleRequiredState;
$scope.moveUp = moveUp;
$scope.moveDown = moveDown;
Expand Down Expand Up @@ -217,6 +218,10 @@
* @param {object} reviewField review field object to be toggled
*/
function toggleReviewField (reviewField) {
if (!isTruthy(reviewField.is_active)) {
return;
}

var field = findReviewFieldByID(reviewField.id);

if (field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
describe('when editing an award', () => {
beforeEach(() => {
createController({ ifNewAward: false });
$scope.reviewFields = ReviewFieldsMockData;
$scope.awardStages = CaseStatus.getAll();
$scope.basicDetails.selectedAwardStages = { 1: true };

Expand Down Expand Up @@ -398,13 +399,38 @@
});
});
});

describe('when editing an award with a disabled review field', () => {
beforeEach(() => {
createController({ ifNewAward: false });
$scope.reviewFields = ReviewFieldsMockData;
$scope.awardStages = CaseStatus.getAll();
$scope.basicDetails.selectedAwardStages = { 1: true };

setAwardDetails();
ReviewFieldsMockData[0].is_active = '0';
$scope.saveAwardInBG();
$scope.$digest();
});

afterEach(() => {
ReviewFieldsMockData[0].is_active = '1';
});

it('removes the disabled field while saving the additional award details', () => {
expect(civicaseCrmApi).toHaveBeenCalledWith('AwardDetail', 'create', jasmine.objectContaining({
review_fields: []
}));
});
});
});

describe('when saving a new award', () => {
describe('from dashboard', () => {
beforeEach(() => {
createController({ ifNewAward: true, redirectTo: 'dashboard' });
setAwardDetails();
$scope.reviewFields = ReviewFieldsMockData;

$scope.saveNewAward();
$scope.$digest();
Expand All @@ -423,6 +449,7 @@
beforeEach(() => {
createController({ ifNewAward: true, redirectTo: 'workflow' });
setAwardDetails();
$scope.reviewFields = ReviewFieldsMockData;

$scope.saveNewAward();
$scope.$digest();
Expand All @@ -443,6 +470,7 @@
beforeEach(() => {
createController({ ifNewAward: true, redirectTo: 'dashboard' });
setAwardDetails();
$scope.reviewFields = ReviewFieldsMockData;

$scope.saveAndNavigateToPreviousPage();
$scope.$digest();
Expand All @@ -468,6 +496,7 @@
beforeEach(() => {
createController({ ifNewAward: true, redirectTo: 'workflow' });
setAwardDetails();
$scope.reviewFields = ReviewFieldsMockData;

$scope.saveAndNavigateToPreviousPage();
$scope.$digest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,50 @@
expect($scope.additionalDetails.selectedReviewFields).toEqual([]);
});
});

describe('and the review field is disabled', () => {
beforeEach(() => {
ReviewFieldsMockData[0].is_active = '0';
});

afterEach(() => {
ReviewFieldsMockData[0].is_active = '1';
});

describe('and the review was not selected before', () => {
beforeEach(() => {
$scope.additionalDetails = { selectedReviewFields: [] };

$scope.toggleReviewField(ReviewFieldsMockData[0]);
});

it('does not addd the clicked review field as selected', () => {
expect($scope.additionalDetails.selectedReviewFields).toEqual([]);
});
});

describe('and the review was selected before', () => {
beforeEach(() => {
$scope.additionalDetails = {
selectedReviewFields: [{
id: ReviewFieldsMockData[0].id,
required: false,
weight: 1
}]
};

$scope.toggleReviewField(ReviewFieldsMockData[0]);
});

it('does not remove the clicked review field from selected', () => {
expect($scope.additionalDetails.selectedReviewFields[0]).toEqual({
id: ReviewFieldsMockData[0].id,
required: false,
weight: 1
});
});
});
});
});

describe('when the REMOVE button is clicked from the review field list', () => {
Expand Down