Skip to content

Commit

Permalink
Merge pull request #856 from CruGlobal/845-allow-editing-dependent-pr…
Browse files Browse the repository at this point in the history
…ofile

[EVENT-845] Allow editing non-primary registrant's profiles
  • Loading branch information
canac authored May 13, 2024
2 parents 680e601 + 9e1b455 commit cdd5825
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 136 deletions.
4 changes: 4 additions & 0 deletions app/scripts/directives/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ angular.module('confRegistrationWebApp').directive('nameQuestion', function () {
!$scope.adminEditRegistrant &&
user &&
user.employeeId &&
$scope.currentRegistrant ===
$scope.currentRegistration.primaryRegistrantId &&
$scope.block.profileType === 'NAME',
);
},
Expand Down Expand Up @@ -78,6 +80,8 @@ angular
!$scope.adminEditRegistrant &&
user &&
user.employeeId &&
$scope.currentRegistrant ===
$scope.currentRegistration.primaryRegistrantId &&
$scope.block.profileType === 'EMAIL',
);
},
Expand Down
220 changes: 84 additions & 136 deletions test/spec/directives/block.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Directive: blocks', () => {
$rootScope = _$rootScope_;

$scope = $rootScope.$new();
$scope.currentRegistration = testData.registration;
$scope.answer = {};
$templateCache.put('views/blocks/nameQuestion.html', '');

Expand All @@ -20,93 +21,66 @@ 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('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(true);
});

it('is false when the profile type is not NAME', () => {
$scope.block.profileType = null;
$compile('<name-question></name-question>')($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('<name-question></name-question>')($scope);
$scope.$digest();

it('is false when the profile type is NAME', () => {
$compile('<name-question></name-question>')($scope);
$scope.$digest();
expect($scope.lockedStaffProfileBlock).toBe(true);
});

expect($scope.lockedStaffProfileBlock).toBe(false);
});
it('is false when profile has not loaded', () => {
globalUserSpy.and.returnValue(null);

it('is false when the profile type is not NAME', () => {
$scope.block.profileType = null;
$compile('<name-question></name-question>')($scope);
$scope.$digest();
$compile('<name-question></name-question>')($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 for non-staff', () => {
globalUserSpy.and.returnValue({ employeeId: null });

it('is false when the profile type is NAME', () => {
$compile('<name-question></name-question>')($scope);
$scope.$digest();
$compile('<name-question></name-question>')($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('<name-question></name-question>')($scope);
$scope.$digest();
it('is false when an admin is editing', () => {
$scope.adminEditRegistrant = {};

expect($scope.lockedStaffProfileBlock).toBe(false);
});
$compile('<name-question></name-question>')($scope);
$scope.$digest();

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('<name-question></name-question>')($scope);
$scope.$digest();
$compile('<name-question></name-question>')($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('<name-question></name-question>')($scope);
$scope.$digest();
it('is false when editing a secondary registrant', () => {
$scope.currentRegistrant = 'other';

expect($scope.lockedStaffProfileBlock).toBe(false);
});
$compile('<name-question></name-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});
});
Expand All @@ -118,6 +92,7 @@ describe('Directive: blocks', () => {
$rootScope = _$rootScope_;

$scope = $rootScope.$new();
$scope.currentRegistration = testData.registration;
$templateCache.put('views/blocks/emailQuestion.html', '');

$scope.block = _.cloneDeep(
Expand All @@ -126,93 +101,66 @@ 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('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(true);
});

it('is false when the profile type is not EMAIL', () => {
$scope.block.profileType = null;
$compile('<email-question></email-question>')($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('<email-question></email-question>')($scope);
$scope.$digest();

it('is false when the profile type is EMAIL', () => {
$compile('<email-question></email-question>')($scope);
$scope.$digest();
expect($scope.lockedStaffProfileBlock).toBe(true);
});

expect($scope.lockedStaffProfileBlock).toBe(false);
});
it('is false when profile has not loaded', () => {
globalUserSpy.and.returnValue(null);

it('is false when the profile type is not EMAIL', () => {
$scope.block.profileType = null;
$compile('<email-question></email-question>')($scope);
$scope.$digest();
$compile('<email-question></email-question>')($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 for non-staff', () => {
globalUserSpy.and.returnValue({ employeeId: null });

it('is false when the profile type is EMAIL', () => {
$compile('<email-question></email-question>')($scope);
$scope.$digest();
$compile('<email-question></email-question>')($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('<email-question></email-question>')($scope);
$scope.$digest();
it('is false when an admin is editing', () => {
$scope.adminEditRegistrant = {};

expect($scope.lockedStaffProfileBlock).toBe(false);
});
$compile('<email-question></email-question>')($scope);
$scope.$digest();

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('<email-question></email-question>')($scope);
$scope.$digest();
$compile('<email-question></email-question>')($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('<email-question></email-question>')($scope);
$scope.$digest();
it('is false when editing a secondary registrant', () => {
$scope.currentRegistrant = 'other';

expect($scope.lockedStaffProfileBlock).toBe(false);
});
$compile('<email-question></email-question>')($scope);
$scope.$digest();

expect($scope.lockedStaffProfileBlock).toBe(false);
});
});
});
Expand Down

0 comments on commit cdd5825

Please sign in to comment.