From 38ddfacb58383f792da694e4390919c9dfabbbc9 Mon Sep 17 00:00:00 2001 From: DemeritCowboy Date: Sun, 6 Oct 2019 23:35:01 -0400 Subject: [PATCH] minor a_b/b_a mixup --- ang/crmCaseType.js | 4 +- tests/karma/unit/crmCaseTypeSpec.js | 108 ++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/ang/crmCaseType.js b/ang/crmCaseType.js index daee538ae4..af7958e344 100644 --- a/ang/crmCaseType.js +++ b/ang/crmCaseType.js @@ -488,9 +488,9 @@ $scope.addRoleOnTheFly = function(roles, newType) { roles.push({name: newType.label_b_a, displaylabel: newType.label_a_b}); // Assume that the case role should be A-B but add both directions as options. - $scope.relationshipTypeOptions.push({id: newType.label_a_b, text: newType.label_a_b}); + $scope.relationshipTypeOptions.push({id: newType.label_a_b, text: newType.label_b_a}); if (newType.label_a_b != newType.label_b_a) { - $scope.relationshipTypeOptions.push({id: newType.label_b_a, text: newType.label_b_a}); + $scope.relationshipTypeOptions.push({id: newType.label_b_a, text: newType.label_a_b}); } }; diff --git a/tests/karma/unit/crmCaseTypeSpec.js b/tests/karma/unit/crmCaseTypeSpec.js index 3b21d3e4c1..258488ed76 100644 --- a/tests/karma/unit/crmCaseTypeSpec.js +++ b/tests/karma/unit/crmCaseTypeSpec.js @@ -547,6 +547,114 @@ describe('crmCaseType', function() { ); }); }); + + describe('when adding a role on-the-fly', function() { + beforeEach(inject(function ($controller) { + ctrl = $controller('CaseTypeCtrl', {$scope: scope, apiCalls: apiCalls}); + })); + + it('updates the case roles for unidirectional', function() { + // first simulate the ajax popup to create a new relationship type + var newType = { + "id": "33", + "name_a_b": "Some New Type is", + "label_a_b": "Some New Type is", + "name_b_a": "Some New Type for", + "label_b_a": "Some New Type for", + "description": "Some New Type", + "contact_type_a": "Individual", + "contact_type_b": "Individual", + "is_reserved": "0", + "is_active": "1" + }; + apiCalls.relTypes.values.push(newType); + + // now let the real code do what it does with the new type + scope.addRoleOnTheFly(scope.caseType.definition.caseRoles, newType); + + expect(scope.caseType.definition.caseRoles).toEqual( + [ + { + name: 'Homeless Services Coordinator', + creator: '1', + manager: '1', + displaylabel: 'Homeless Services Coordinator is' + }, + { + name: 'Some New Type for', + displaylabel: 'Some New Type is' + } + ] + ); + + expect(scope.relationshipTypeOptions.slice(-2)).toEqual( + [ + { + id: 'Some New Type is', + text: 'Some New Type for' + }, + { + id: 'Some New Type for', + text: 'Some New Type is' + } + ] + ); + }); + + it('updates the case roles for bidirectional', function() { + // first simulate the ajax popup to create a new relationship type + var newType = { + "id": "34", + "name_a_b": "Friend of", + "label_a_b": "Friend of", + "name_b_a": "Friend of", + "label_b_a": "Friend of", + "description": "Friend", + "contact_type_a": "Individual", + "contact_type_b": "Individual", + "is_reserved": "0", + "is_active": "1" + }; + apiCalls.relTypes.values.push(newType); + + // now let the real code do what it does with the new type + scope.addRoleOnTheFly(scope.caseType.definition.caseRoles, newType); + + expect(scope.caseType.definition.caseRoles).toEqual( + [ + { + name: 'Homeless Services Coordinator', + creator: '1', + manager: '1', + displaylabel: 'Homeless Services Coordinator is' + }, + { + name: 'Friend of', + displaylabel: 'Friend of' + } + ] + ); + + expect(scope.relationshipTypeOptions.slice(-1)).toEqual( + [ + { + id: 'Friend of', + text: 'Friend of' + } + ] + ); + + // Check that it did NOT add two entries for this bidirectional type + expect(scope.relationshipTypeOptions.slice(-2,-1)).not.toEqual( + [ + { + id: 'Friend of', + text: 'Friend of' + } + ] + ); + }); + }); }); describe('crmAddName', function () { -- 2.25.1