Skip to content

Commit

Permalink
fix home component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
auumgn committed Apr 19, 2024
1 parent 99b113c commit 09d0f76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
14 changes: 3 additions & 11 deletions ui/src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { HomeComponent } from './home.component'
import { MemberService } from '../member/service/member.service'
import { AccountService } from '../account'
import { of } from 'rxjs'

describe('HomeComponent', () => {
let component: HomeComponent
let fixture: ComponentFixture<HomeComponent>
let memberServiceSpy: jasmine.SpyObj<MemberService>
let accountServiceSpy: jasmine.SpyObj<AccountService>

beforeEach(() => {
accountServiceSpy = jasmine.createSpyObj('AccountService', ['getAccountData'])
memberServiceSpy = jasmine.createSpyObj('MemberService', ['getMemberData'])

TestBed.configureTestingModule({
declarations: [HomeComponent],
providers: [
{ provide: MemberService, useValue: memberServiceSpy },
{ provide: AccountService, useValue: accountServiceSpy },
],
providers: [{ provide: AccountService, useValue: accountServiceSpy }],
})
fixture = TestBed.createComponent(HomeComponent)
component = fixture.componentInstance

accountServiceSpy = TestBed.inject(AccountService) as jasmine.SpyObj<AccountService>
memberServiceSpy = TestBed.inject(MemberService) as jasmine.SpyObj<MemberService>
})

it('should call getAccountData but not getMemberData', () => {
Expand All @@ -37,7 +30,7 @@ describe('HomeComponent', () => {
component.ngOnInit()

expect(accountServiceSpy.getAccountData).toHaveBeenCalled()
expect(memberServiceSpy.getMemberData).toHaveBeenCalledTimes(0)
expect(component.loggedInMessage).toBeUndefined()
})

it('should call getMemberData if account data is not null', () => {
Expand All @@ -57,13 +50,12 @@ describe('HomeComponent', () => {
mfaEnabled: false,
})
)
memberServiceSpy.getMemberData.and.returnValue(of({}))

expect(component).toBeTruthy()

component.ngOnInit()

expect(accountServiceSpy.getAccountData).toHaveBeenCalled()
expect(memberServiceSpy.getMemberData).toHaveBeenCalled()
expect(component.loggedInMessage).toEqual('You are logged in as user email@email.com')
})
})
26 changes: 6 additions & 20 deletions ui/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,24 @@ import { IAccount } from '../account/model/account.model'
export class HomeComponent implements OnInit, OnDestroy {
account: IAccount | undefined | null
memberData: ISFMemberData | undefined | null
authenticationStateSubscription: Subscription | undefined
memberDataSubscription: Subscription | undefined
manageMemberSubscription: Subscription | undefined
salesforceId: string | undefined
loggedInMessage: string | undefined
accountServiceSubscription: Subscription | undefined

constructor(
private accountService: AccountService,
private memberService: MemberService
) {}
constructor(private accountService: AccountService) {}

ngOnInit() {
this.accountService.getAccountData().subscribe((account) => {
this.accountServiceSubscription = this.accountService.getAccountData().subscribe((account) => {
this.account = account
if (account) {
/* this.memberDataSubscription = this.memberService.getMemberData(account.salesforceId).subscribe((data) => {
this.memberData = data
}) */
this.loggedInMessage = $localize`:@@home.loggedIn.message.string:You are logged in as user ${account.email}`
}
})
}

ngOnDestroy() {
if (this.authenticationStateSubscription) {
this.authenticationStateSubscription.unsubscribe()
ngOnDestroy(): void {
if (this.accountServiceSubscription) {
this.accountServiceSubscription.unsubscribe()
}
/* if (this.memberDataSubscription) {
this.memberDataSubscription.unsubscribe()
} */
/* if (this.manageMemberSubscription) {
this.manageMemberSubscription.unsubscribe()
} */
}
}

0 comments on commit 09d0f76

Please sign in to comment.