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 bba80ae
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
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 @@ -26,7 +26,9 @@
<tr
ng-repeat="reviewField in additionalDetails.selectedReviewFields | orderBy: 'weight'"
ng-if="additionalDetails.selectedReviewFields.length > 0">
<td>{{getReviewFieldData(reviewField.id, 'label')}}</td>
<td ng-class="{ disabled: !isTruthy(getReviewFieldData(reviewField.id, 'is_active')) }">
{{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 @@ -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 bba80ae

Please sign in to comment.