Skip to content

Commit

Permalink
RSESPRT-57: Handle disabled review fields
Browse files Browse the repository at this point in the history
  • Loading branch information
deb1990 committed Jul 8, 2021
1 parent 1296226 commit 4ac9e6e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 10 deletions.
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 @@ -405,6 +406,7 @@
beforeEach(() => {
createController({ ifNewAward: true, redirectTo: 'dashboard' });
setAwardDetails();
$scope.reviewFields = ReviewFieldsMockData;

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

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

$scope.saveAndNavigateToPreviousPage();
$scope.$digest();
Expand All @@ -468,6 +472,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

0 comments on commit 4ac9e6e

Please sign in to comment.