diff --git a/ang/civiawards/award-creation/directives/award.directive.js b/ang/civiawards/award-creation/directives/award.directive.js index e24111b0..bc24bb62 100644 --- a/ang/civiawards/award-creation/directives/award.directive.js +++ b/ang/civiawards/award-creation/directives/award.directive.js @@ -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; @@ -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(); } /** diff --git a/ang/civiawards/award-creation/directives/review-fields/review-field-selection.html b/ang/civiawards/award-creation/directives/review-fields/review-field-selection.html index e2ee13b5..ec18933f 100644 --- a/ang/civiawards/award-creation/directives/review-fields/review-field-selection.html +++ b/ang/civiawards/award-creation/directives/review-fields/review-field-selection.html @@ -26,11 +26,14 @@ {{reviewField.label}} {{reviewField.data_type}} diff --git a/ang/civiawards/award-creation/directives/review-fields/review-fields-table.directive.html b/ang/civiawards/award-creation/directives/review-fields/review-fields-table.directive.html index c50be364..58ab826e 100644 --- a/ang/civiawards/award-creation/directives/review-fields/review-fields-table.directive.html +++ b/ang/civiawards/award-creation/directives/review-fields/review-fields-table.directive.html @@ -25,8 +25,10 @@ - {{getReviewFieldData(reviewField.id, 'label')}} + ng-if="additionalDetails.selectedReviewFields.length > 0 && isTruthy(getReviewFieldData(reviewField.id, 'is_active'))"> + + {{getReviewFieldData(reviewField.id, 'label')}} + { beforeEach(() => { createController({ ifNewAward: false }); + $scope.reviewFields = ReviewFieldsMockData; $scope.awardStages = CaseStatus.getAll(); $scope.basicDetails.selectedAwardStages = { 1: true }; @@ -398,6 +399,30 @@ }); }); }); + + 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', () => { @@ -405,6 +430,7 @@ beforeEach(() => { createController({ ifNewAward: true, redirectTo: 'dashboard' }); setAwardDetails(); + $scope.reviewFields = ReviewFieldsMockData; $scope.saveNewAward(); $scope.$digest(); @@ -423,6 +449,7 @@ beforeEach(() => { createController({ ifNewAward: true, redirectTo: 'workflow' }); setAwardDetails(); + $scope.reviewFields = ReviewFieldsMockData; $scope.saveNewAward(); $scope.$digest(); @@ -443,6 +470,7 @@ beforeEach(() => { createController({ ifNewAward: true, redirectTo: 'dashboard' }); setAwardDetails(); + $scope.reviewFields = ReviewFieldsMockData; $scope.saveAndNavigateToPreviousPage(); $scope.$digest(); @@ -468,6 +496,7 @@ beforeEach(() => { createController({ ifNewAward: true, redirectTo: 'workflow' }); setAwardDetails(); + $scope.reviewFields = ReviewFieldsMockData; $scope.saveAndNavigateToPreviousPage(); $scope.$digest(); diff --git a/ang/test/civiawards/award-creation/directives/review-fields/review-fields-table.directive.spec.js b/ang/test/civiawards/award-creation/directives/review-fields/review-fields-table.directive.spec.js index f2527d86..ec04ca3e 100644 --- a/ang/test/civiawards/award-creation/directives/review-fields/review-fields-table.directive.spec.js +++ b/ang/test/civiawards/award-creation/directives/review-fields/review-fields-table.directive.spec.js @@ -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', () => {