Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,26 @@ describe('EndorsementApprovalComponent', () => {
});


it('should return effectiveEndorserName as currentUser when endorseFiscalActivity checked', () => {
it('should return effectiveEndorserName as fiscal endorser when present', () => {
component.fiscal = mockFiscal;
component.endorsementApprovalForm.get('endorseFiscalActivity')?.setValue(true);
expect(component.effectiveEndorserName).toBe('Alice');
});

it('should return currentUser when no fiscal endorser and endorseFiscalActivity checked', () => {
const noEndorserFiscal: ProjectFiscal = { ...mockFiscal, endorserName: undefined };
component.fiscal = noEndorserFiscal;
component.endorsementApprovalForm.get('endorseFiscalActivity')?.setValue(true);
expect(component.effectiveEndorserName).toBe('Test User');
});

it('should clear effectiveEndorserName as fiscal endorser when endorseFiscalActivity unchecked', () => {
component.fiscal = mockFiscal;
it('should return empty string when no fiscal endorser and endorseFiscalActivity unchecked', () => {
const noEndorserFiscal: ProjectFiscal = { ...mockFiscal, endorserName: undefined };
component.fiscal = noEndorserFiscal;
component.endorsementApprovalForm.get('endorseFiscalActivity')?.setValue(false);
expect(component.effectiveEndorserName).toBe('');
});

it('should emit saveEndorsement with updated fiscal on save', () => {
const emitSpy = spyOn(component.saveEndorsement, 'emit');
component.fiscal = mockFiscal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ export class EndorsementApprovalComponent implements OnChanges, OnInit {
}

get effectiveEndorserName(): string {
// use the endorserName if set
if (this.fiscal?.endorserName) {
return this.fiscal.endorserName;
}
// or fall back to currentUser if the form is checked
const checked = this.endorsementApprovalForm.get('endorseFiscalActivity')?.value;
return checked ? this.currentUser : '';
}
Expand Down
Loading