From 2a8e7939fa2779216b80135ea3cf5e7dbaf50cbe Mon Sep 17 00:00:00 2001 From: markuczy <129275100+markuczy@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:09:18 +0100 Subject: [PATCH] fix: tests with avatar menu harness (#454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fix harness * fix: sonar code smell --------- Co-authored-by: Henry Täschner <129834483+HenryT-CG@users.noreply.github.com> --- .../user-avatar-menu.component.spec.ts | 16 ++++++++-------- .../user-avatar-menu/user-avatar-menu.harness.ts | 6 +++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app/remotes/user-avatar-menu/user-avatar-menu.component.spec.ts b/src/app/remotes/user-avatar-menu/user-avatar-menu.component.spec.ts index f97f38d1..91ab70d3 100644 --- a/src/app/remotes/user-avatar-menu/user-avatar-menu.component.spec.ts +++ b/src/app/remotes/user-avatar-menu/user-avatar-menu.component.spec.ts @@ -214,7 +214,7 @@ describe('OneCXUserAvatarMenuComponent', () => { ) }) - xit('should render menu in correct positions', async () => { + it('should render menu in correct positions', async () => { const userProfileMenu = { workspaceName: 'test-workspace', menu: [ @@ -256,7 +256,7 @@ describe('OneCXUserAvatarMenuComponent', () => { expect(await menuItems[2].getText()).toEqual('Log out') }) - xit('should use translations whenever i18n translation is provided', async () => { + it('should use translations whenever i18n translation is provided', async () => { menuItemApiSpy.getMenuItems.and.returnValue( of({ workspaceName: 'test-workspace', @@ -289,7 +289,7 @@ describe('OneCXUserAvatarMenuComponent', () => { expect(await menuItems[0].getText()).toEqual('English personal info') }) - xit('should display icon if provided', async () => { + it('should display icon if provided', async () => { menuItemApiSpy.getMenuItems.and.returnValue( of({ workspaceName: 'test-workspace', @@ -320,7 +320,7 @@ describe('OneCXUserAvatarMenuComponent', () => { expect(await menuItems[0].hasIcon(PrimeIcons.HOME)).toBeTrue() }) - xit('should use routerLink for local urls', async () => { + it('should use routerLink for local urls', async () => { menuItemApiSpy.getMenuItems.and.returnValue( of({ workspaceName: 'test-workspace', @@ -352,7 +352,7 @@ describe('OneCXUserAvatarMenuComponent', () => { expect(router.url).toBe('/admin/user-profile') }) - xit('should use href for external urls', async () => { + it('should use href for external urls', async () => { menuItemApiSpy.getMenuItems.and.returnValue( of({ workspaceName: 'test-workspace', @@ -381,7 +381,7 @@ describe('OneCXUserAvatarMenuComponent', () => { expect(await menuItems[0].getLink()).toBe('https://www.google.com/') }) - xit('should only show logout on failed menu fetch call', async () => { + it('should only show logout on failed menu fetch call', async () => { menuItemApiSpy.getMenuItems.and.returnValue(throwError(() => {})) const { avatarMenuHarness } = await setUpWithHarnessAndInit([]) @@ -390,8 +390,8 @@ describe('OneCXUserAvatarMenuComponent', () => { expect(await menuItems[0].getText()).toEqual('Log out') }) - xit('should have correct icon for logout', async () => { - menuItemApiSpy.getMenuItems.and.returnValue(of({ workspaceName: 'test-workspace', menu: [] } as any)) + it('should have correct icon for logout', async () => { + menuItemApiSpy.getMenuItems.and.returnValue(of({ workspaceName: 'workspace', menu: [] } as any)) const { avatarMenuHarness } = await setUpWithHarness() const menuItems = await avatarMenuHarness.getMenuItems() diff --git a/src/app/remotes/user-avatar-menu/user-avatar-menu.harness.ts b/src/app/remotes/user-avatar-menu/user-avatar-menu.harness.ts index 4e875bc4..d4ba5e24 100644 --- a/src/app/remotes/user-avatar-menu/user-avatar-menu.harness.ts +++ b/src/app/remotes/user-avatar-menu/user-avatar-menu.harness.ts @@ -1,12 +1,16 @@ import { ComponentHarness } from '@angular/cdk/testing' import { MenuItemWithIconHarness } from '@onecx/angular-testing' +class AvatarMenuItemHarness extends MenuItemWithIconHarness { + static override readonly hostSelector = 'li>a' +} + export class OneCXUserAvatarMenuHarness extends ComponentHarness { static readonly hostSelector = 'app-user-avatar-menu' public getUserAvatarButton = this.locatorFor('#ws_user_avatar_menu_action') - public getMenuItems = this.locatorForAll(MenuItemWithIconHarness) + public getMenuItems = this.locatorForAll(AvatarMenuItemHarness) async getUserAvatarButtonId(): Promise { return await (await this.getUserAvatarButton()).getAttribute('id')