From 7c89b53928a20b499c0c160f3f56ef8b536e05a7 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 14 Feb 2023 12:48:17 -0500 Subject: [PATCH] update view profile unit tests --- .../view-profile/view-profile.component.html | 11 +- .../view-profile/view-profile.component.scss | 2 +- .../view-profile.component.spec.ts | 140 +++++++++++------- .../view-profile/view-profile.component.ts | 13 +- 4 files changed, 96 insertions(+), 70 deletions(-) diff --git a/projects/aca-content/src/lib/components/view-profile/view-profile.component.html b/projects/aca-content/src/lib/components/view-profile/view-profile.component.html index 8eba5198a..203bd95e2 100644 --- a/projects/aca-content/src/lib/components/view-profile/view-profile.component.html +++ b/projects/aca-content/src/lib/components/view-profile/view-profile.component.html @@ -9,9 +9,9 @@
- - {{ generalSectionDropdown ? 'expand_more' : 'chevron_right'}} - +

{{'APP.EDIT_PROFILE.GENERAL' | translate}}

@@ -92,8 +92,9 @@
- - {{ contactSectionDropdown ? 'expand_more' : 'chevron_right'}} +

{{'APP.EDIT_PROFILE.COMPANY_DETAILS' | translate}}

diff --git a/projects/aca-content/src/lib/components/view-profile/view-profile.component.scss b/projects/aca-content/src/lib/components/view-profile/view-profile.component.scss index 56817ab33..162e8afda 100644 --- a/projects/aca-content/src/lib/components/view-profile/view-profile.component.scss +++ b/projects/aca-content/src/lib/components/view-profile/view-profile.component.scss @@ -57,7 +57,7 @@ .app-general-title { margin-left: 0.6rem; - margin-top: 4px; + margin-top: 11px; letter-spacing: .5px; } diff --git a/projects/aca-content/src/lib/components/view-profile/view-profile.component.spec.ts b/projects/aca-content/src/lib/components/view-profile/view-profile.component.spec.ts index 5d5dc302c..cde68b5af 100644 --- a/projects/aca-content/src/lib/components/view-profile/view-profile.component.spec.ts +++ b/projects/aca-content/src/lib/components/view-profile/view-profile.component.spec.ts @@ -32,80 +32,109 @@ describe('ViewProfileComponent', () => { router.initialNavigation(); }); + afterEach(() => { + fixture.destroy(); + }); + it('should company dropdown remains close', async () => { expect(component.contactSectionDropdown).toBe(false); }); - it('should save button is disabled if form has invalid mobile number', () => { - component.ngOnInit(); - const profileFormGroup = component.profileForm; + it('should save button is disabled if form has invalid mobile number', async () => { + spyOn(component.peopleApi, 'getPerson').and.returnValue( + Promise.resolve({ + entry: { + id: 'user1', + firstName: 'User1', + lastName: 'User1', + email: 'user1@company.com', + enabled: true, + jobTitle: 'Developer', + location: 'US', + telephone: '2744245', + mobile: 'AB8866322112', + company: { + organization: 'test Name', + postcode: '12345', + address1: 'test address', + telephone: '27442266', + email: 'email@test.com' + } + } + }) + ); - profileFormGroup.setValue({ - jobTitle: 'Developer', - location: 'US', - telephone: '2744245', - mobile: 'AB8866322112', - oldPassword: 'admin@123', - newPassword: 'admin@1234', - verifyPassword: 'admin@1234', - companyName: 'test Name', - companyPostCode: '12345', - companyAddress: 'test address', - companyTelephone: '27442266', - companyEmail: 'email@test.com' - }); + fixture.detectChanges(); + await fixture.whenStable(); - expect(profileFormGroup.valid).toEqual(false); + expect(component.profileForm.valid).toEqual(false); expect(component.isSaveButtonDisabled()).toBeTruthy(); }); - it('should save button is disabled if form has invalid email', () => { - component.ngOnInit(); - const profileFormGroup = component.profileForm; + it('should save button is disabled if form has invalid email', async () => { + spyOn(component.peopleApi, 'getPerson').and.returnValue( + Promise.resolve({ + entry: { + id: 'user1', + firstName: 'User1', + lastName: 'User1', + email: 'user1@company.com', + enabled: true, + jobTitle: 'Developer', + location: 'US', + telephone: '2744245', + mobile: 'AB8866322112', + company: { + organization: 'test Name', + postcode: '12345', + address1: 'test address', + telephone: '27442266', + email: 'email' + } + } + }) + ); - profileFormGroup.setValue({ - jobTitle: 'Developer', - location: 'US', - telephone: '27442445', - mobile: '457554', - oldPassword: 'admin@123', - newPassword: 'admin@1234', - verifyPassword: 'admin@1234', - companyName: 'test Name', - companyPostCode: '12345', - companyAddress: 'test address', - companyTelephone: '27442266', - companyEmail: 'email' - }); + fixture.detectChanges(); + await fixture.whenStable(); - expect(profileFormGroup.valid).toEqual(false); + expect(component.profileForm.valid).toEqual(false); expect(component.isSaveButtonDisabled()).toBeTruthy(); }); - it('should save button is enabled if form has valid inputs', () => { - component.ngOnInit(); - const profileFormGroup = component.profileForm; + it('should enable save button if form is valid', async () => { + spyOn(component.peopleApi, 'getPerson').and.returnValue( + Promise.resolve({ + entry: { + id: 'user1', + firstName: 'User1', + lastName: 'User1', + email: 'user1@company.com', + enabled: true, + jobTitle: 'Developer', + location: 'US', + telephone: '274-422-55', + mobile: '886-632-2112', + company: { + organization: 'testCompany', + postcode: '12345', + address1: 'test address', + telephone: '274-22-66', + email: 'testEmail@test.com' + } + } + }) + ); - profileFormGroup.setValue({ - jobTitle: 'Developer', - location: 'US', - telephone: '274-422-55', - mobile: '886-632-2112', - oldPassword: 'test@123', - newPassword: 'test@1234', - verifyPassword: 'test@1234', - companyName: 'testCompany', - companyPostCode: '12345', - companyAddress: 'test address', - companyTelephone: '274-22-66', - companyEmail: 'testEmail@test.com' - }); + fixture.detectChanges(); + await fixture.whenStable(); - expect(profileFormGroup.valid).toEqual(true); + expect(component.profileForm.valid).toEqual(true); expect(component.isSaveButtonDisabled()).toBeFalsy(); }); it('should expand or compress general dropdown when arrow button is clicked', () => { + component.populateForm({} as any); spyOn(component, 'toggleGeneralDropdown').and.callThrough(); component.generalSectionDropdown = false; fixture.detectChanges(); @@ -118,6 +147,7 @@ describe('ViewProfileComponent', () => { }); it('should expand or compress contact dropdown when arrow button is clicked', () => { + component.populateForm({} as any); spyOn(component, 'toggleContactDropdown').and.callThrough(); component.contactSectionDropdown = false; fixture.detectChanges(); @@ -130,6 +160,7 @@ describe('ViewProfileComponent', () => { }); it('should toggle form view when edit or cancel buttons is clicked for general form', () => { + component.populateForm({} as any); spyOn(component, 'toggleGeneralButtons').and.callThrough(); fixture.detectChanges(); @@ -144,6 +175,7 @@ describe('ViewProfileComponent', () => { }); it('should toggle form view when edit or cancel buttons is clicked for contact form', () => { + component.populateForm({} as any); spyOn(component, 'toggleContactButtons').and.callThrough(); fixture.detectChanges(); diff --git a/projects/aca-content/src/lib/components/view-profile/view-profile.component.ts b/projects/aca-content/src/lib/components/view-profile/view-profile.component.ts index b7ea56ede..7c0f49b54 100644 --- a/projects/aca-content/src/lib/components/view-profile/view-profile.component.ts +++ b/projects/aca-content/src/lib/components/view-profile/view-profile.component.ts @@ -43,24 +43,17 @@ export class ViewProfileComponent implements OnInit { ngOnInit() { this.peopleApi .getPerson('-me-') - .then((userInfo) => { - this.personDetails = userInfo?.entry; - this.populateForm(userInfo?.entry); - }) - .catch((error) => { - throwError(error); - }); + .then((userInfo) => this.populateForm(userInfo?.entry)) + .catch((error) => throwError(error)); } populateForm(userInfo: Person) { + this.personDetails = userInfo; this.profileForm = new FormGroup({ jobTitle: new FormControl(userInfo?.jobTitle || ''), location: new FormControl(userInfo?.location || ''), telephone: new FormControl(userInfo?.telephone || '', [Validators.pattern('^([0-9]+-)*[0-9]+$')]), mobile: new FormControl(userInfo?.mobile || '', [Validators.pattern('^([0-9]+-)*[0-9]+$')]), - oldPassword: new FormControl(''), - newPassword: new FormControl(''), - verifyPassword: new FormControl(''), companyName: new FormControl(userInfo?.company?.organization || ''), companyPostCode: new FormControl(userInfo?.company?.postcode || ''), companyAddress: new FormControl(userInfo?.company?.address1 || ''),