From e191c634317a9ea7fa41a5225b326ea0b965e19c Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Fri, 10 May 2024 14:33:50 -0500 Subject: [PATCH 1/2] Allow editing non-primary registrant's profiles --- app/scripts/directives/blocks.js | 4 + test/spec/directives/block.spec.js | 210 ++++++++++------------------- 2 files changed, 74 insertions(+), 140 deletions(-) diff --git a/app/scripts/directives/blocks.js b/app/scripts/directives/blocks.js index ccb3e079..c6f52a72 100644 --- a/app/scripts/directives/blocks.js +++ b/app/scripts/directives/blocks.js @@ -30,6 +30,8 @@ angular.module('confRegistrationWebApp').directive('nameQuestion', function () { !$scope.adminEditRegistrant && user && user.employeeId && + $scope.currentRegistrant === + $scope.currentRegistration.primaryRegistrantId && $scope.block.profileType === 'NAME', ); }, @@ -78,6 +80,8 @@ angular !$scope.adminEditRegistrant && user && user.employeeId && + $scope.currentRegistrant === + $scope.currentRegistration.primaryRegistrantId && $scope.block.profileType === 'EMAIL', ); }, diff --git a/test/spec/directives/block.spec.js b/test/spec/directives/block.spec.js index d1b47844..94259e0c 100644 --- a/test/spec/directives/block.spec.js +++ b/test/spec/directives/block.spec.js @@ -11,6 +11,7 @@ describe('Directive: blocks', () => { $rootScope = _$rootScope_; $scope = $rootScope.$new(); + $scope.currentRegistration = testData.registration; $scope.answer = {}; $templateCache.put('views/blocks/nameQuestion.html', ''); @@ -20,93 +21,57 @@ describe('Directive: blocks', () => { })); describe('lockedStaffProfileBlock', () => { - describe('for staff', () => { - beforeEach(() => { - spyOn($rootScope, 'globalUser').and.returnValue({ - employeeId: '0123456', - }); - }); - - it('is true when the profile type is NAME', () => { - $compile('')($scope); - $scope.$digest(); - - expect($scope.lockedStaffProfileBlock).toBe(true); - }); - - it('is false when the profile type is not NAME', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); - - expect($scope.lockedStaffProfileBlock).toBe(false); + let globalUserSpy; + beforeEach(() => { + globalUserSpy = spyOn($rootScope, 'globalUser').and.returnValue({ + employeeId: '0123456', }); + $scope.adminEditRegistrant = null; + $scope.currentRegistrant = + $scope.currentRegistration.primaryRegistrantId; }); - describe('for non-staff', () => { - beforeEach(() => { - spyOn($rootScope, 'globalUser').and.returnValue({ employeeId: null }); - }); + it('is true when staff are editing a NAME field on the primary registrant', () => { + $compile('')($scope); + $scope.$digest(); - it('is false when the profile type is NAME', () => { - $compile('')($scope); - $scope.$digest(); + expect($scope.lockedStaffProfileBlock).toBe(true); + }); - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + it('is false for non-staff', () => { + globalUserSpy.and.returnValue({ employeeId: null }); - it('is false when the profile type is not NAME', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); + $compile('')($scope); + $scope.$digest(); - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + expect($scope.lockedStaffProfileBlock).toBe(false); }); - describe('with no profile', () => { - beforeEach(() => { - spyOn($rootScope, 'globalUser').and.returnValue(null); - }); - - it('is false when the profile type is NAME', () => { - $compile('')($scope); - $scope.$digest(); + it('is false when an admin is editing', () => { + $scope.adminEditRegistrant = {}; - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + $compile('')($scope); + $scope.$digest(); - it('is false when the profile type is not NAME', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); - - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + expect($scope.lockedStaffProfileBlock).toBe(false); }); - describe('when an admin is editing', () => { - beforeEach(() => { - $scope.adminEditRegistrant = {}; - spyOn($rootScope, 'globalUser').and.returnValue({ - employeeId: '0123456', - }); - }); + it('is false when the profile type is not NAME', () => { + $scope.block.profileType = null; - it('is false when the profile type is NAME', () => { - $compile('')($scope); - $scope.$digest(); + $compile('')($scope); + $scope.$digest(); - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + expect($scope.lockedStaffProfileBlock).toBe(false); + }); - it('is false when the profile type is not NAME', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); + it('is false when editing a secondary registrant', () => { + $scope.currentRegistrant = 'other'; - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + $compile('')($scope); + $scope.$digest(); + + expect($scope.lockedStaffProfileBlock).toBe(false); }); }); }); @@ -118,6 +83,7 @@ describe('Directive: blocks', () => { $rootScope = _$rootScope_; $scope = $rootScope.$new(); + $scope.currentRegistration = testData.registration; $templateCache.put('views/blocks/emailQuestion.html', ''); $scope.block = _.cloneDeep( @@ -126,93 +92,57 @@ describe('Directive: blocks', () => { })); describe('lockedStaffProfileBlock', () => { - describe('for staff', () => { - beforeEach(() => { - spyOn($rootScope, 'globalUser').and.returnValue({ - employeeId: '0123456', - }); - }); - - it('is true when the profile type is EMAIL', () => { - $compile('')($scope); - $scope.$digest(); - - expect($scope.lockedStaffProfileBlock).toBe(true); - }); - - it('is false when the profile type is not EMAIL', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); - - expect($scope.lockedStaffProfileBlock).toBe(false); + let globalUserSpy; + beforeEach(() => { + globalUserSpy = spyOn($rootScope, 'globalUser').and.returnValue({ + employeeId: '0123456', }); + $scope.adminEditRegistrant = null; + $scope.currentRegistrant = + $scope.currentRegistration.primaryRegistrantId; }); - describe('for non-staff', () => { - beforeEach(() => { - spyOn($rootScope, 'globalUser').and.returnValue({ employeeId: null }); - }); + it('is true when staff are editing an EMAIL field on the primary registrant', () => { + $compile('')($scope); + $scope.$digest(); - it('is false when the profile type is EMAIL', () => { - $compile('')($scope); - $scope.$digest(); + expect($scope.lockedStaffProfileBlock).toBe(true); + }); - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + it('is false for non-staff', () => { + globalUserSpy.and.returnValue({ employeeId: null }); - it('is false when the profile type is not EMAIL', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); + $compile('')($scope); + $scope.$digest(); - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + expect($scope.lockedStaffProfileBlock).toBe(false); }); - describe('when an admin is editing', () => { - beforeEach(() => { - $scope.adminEditRegistrant = {}; - spyOn($rootScope, 'globalUser').and.returnValue({ - employeeId: '0123456', - }); - }); - - it('is false when the profile type is EMAIL', () => { - $compile('')($scope); - $scope.$digest(); + it('is false when an admin is editing', () => { + $scope.adminEditRegistrant = {}; - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + $compile('')($scope); + $scope.$digest(); - it('is false when the profile type is not EMAIL', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); - - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + expect($scope.lockedStaffProfileBlock).toBe(false); }); - describe('with no profile', () => { - beforeEach(() => { - spyOn($rootScope, 'globalUser').and.returnValue(null); - }); + it('is false when the profile type is not EMAIL', () => { + $scope.block.profileType = null; - it('is false when the profile type is EMAIL', () => { - $compile('')($scope); - $scope.$digest(); + $compile('')($scope); + $scope.$digest(); - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + expect($scope.lockedStaffProfileBlock).toBe(false); + }); - it('is false when the profile type is not EMAIL', () => { - $scope.block.profileType = null; - $compile('')($scope); - $scope.$digest(); + it('is false when editing a secondary registrant', () => { + $scope.currentRegistrant = 'other'; - expect($scope.lockedStaffProfileBlock).toBe(false); - }); + $compile('')($scope); + $scope.$digest(); + + expect($scope.lockedStaffProfileBlock).toBe(false); }); }); }); From 9e1b455c0ce2353b44509216f61096547ea21179 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Mon, 13 May 2024 07:42:54 -0500 Subject: [PATCH 2/2] Add tests for missing profile --- test/spec/directives/block.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/spec/directives/block.spec.js b/test/spec/directives/block.spec.js index 94259e0c..47e396b9 100644 --- a/test/spec/directives/block.spec.js +++ b/test/spec/directives/block.spec.js @@ -38,6 +38,15 @@ describe('Directive: blocks', () => { expect($scope.lockedStaffProfileBlock).toBe(true); }); + it('is false when profile has not loaded', () => { + globalUserSpy.and.returnValue(null); + + $compile('')($scope); + $scope.$digest(); + + expect($scope.lockedStaffProfileBlock).toBe(false); + }); + it('is false for non-staff', () => { globalUserSpy.and.returnValue({ employeeId: null }); @@ -109,6 +118,15 @@ describe('Directive: blocks', () => { expect($scope.lockedStaffProfileBlock).toBe(true); }); + it('is false when profile has not loaded', () => { + globalUserSpy.and.returnValue(null); + + $compile('')($scope); + $scope.$digest(); + + expect($scope.lockedStaffProfileBlock).toBe(false); + }); + it('is false for non-staff', () => { globalUserSpy.and.returnValue({ employeeId: null });