From b7cac159017d40ebac71ad19a5fe681179151a79 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 31 Dec 2023 10:20:48 -0800 Subject: [PATCH] Fix frontend coverage --- .../app-frame/app-frame.component.spec.ts | 7 ++++-- .../profile-edit-dialog.component.spec.ts | 24 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.spec.ts b/src-ui/src/app/components/app-frame/app-frame.component.spec.ts index b9e036f46..d548383df 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.spec.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.spec.ts @@ -403,13 +403,16 @@ describe('AppFrameComponent', () => { const toastInfoSpy = jest.spyOn(toastService, 'showInfo') jest.spyOn(messagesService, 'get').mockReturnValue( of([ + { level: 'warning', message: 'Test warning', tags: '' }, { level: 'error', message: 'Test error', tags: '' }, + { level: 'success', message: 'Test success', tags: '' }, { level: 'info', message: 'Test info', tags: '' }, + { level: 'debug', message: 'Test debug', tags: '' }, ]) ) component.ngOnInit() httpTestingController.expectOne(`${environment.apiBaseUrl}messages/`) - expect(toastErrorSpy).toHaveBeenCalled() - expect(toastInfoSpy).toHaveBeenCalled() + expect(toastErrorSpy).toHaveBeenCalledTimes(2) + expect(toastInfoSpy).toHaveBeenCalledTimes(3) }) }) diff --git a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts index ea8665d2a..563eb7431 100644 --- a/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts +++ b/src-ui/src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.spec.ts @@ -267,28 +267,26 @@ describe('ProfileEditDialogComponent', () => { expect(getProvidersSpy).toHaveBeenCalled() }) - it('should remove disconnected social account from component', async () => { + it('should remove disconnected social account from component, show error if needed', async () => { const disconnectSpy = jest.spyOn(profileService, 'disconnectSocialAccount') - disconnectSpy.mockReturnValue(of(socialAccount.id)) - - let resolve - const p = new Promise((r) => (resolve = r)) - const getSpy = jest.spyOn(profileService, 'get') - getSpy.mockImplementation(() => { - resolve() - return of(profile) - }) - + getSpy.mockImplementation(() => of(profile)) component.ngOnInit() - await p + const errorSpy = jest.spyOn(toastService, 'showError') - expect(getSpy).toHaveBeenCalled() expect(component.socialAccounts).toContainEqual(socialAccount) + // fail first + disconnectSpy.mockReturnValueOnce( + throwError(() => new Error('unable to disconnect')) + ) component.disconnectSocialAccount(socialAccount.id) + expect(errorSpy).toHaveBeenCalled() + // succeed + disconnectSpy.mockReturnValue(of(socialAccount.id)) + component.disconnectSocialAccount(socialAccount.id) expect(disconnectSpy).toHaveBeenCalled() expect(component.socialAccounts).not.toContainEqual(socialAccount) })