Skip to content

Commit

Permalink
fix: tests with avatar menu harness (#454)
Browse files Browse the repository at this point in the history
* fix: fix harness

* fix: sonar code smell

---------

Co-authored-by: Henry Täschner <[email protected]>
  • Loading branch information
markuczy and HenryT-CG authored Dec 2, 2024
1 parent c836eb4 commit 2a8e793
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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([])
Expand All @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion src/app/remotes/user-avatar-menu/user-avatar-menu.harness.ts
Original file line number Diff line number Diff line change
@@ -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<string | null> {
return await (await this.getUserAvatarButton()).getAttribute('id')
Expand Down

0 comments on commit 2a8e793

Please sign in to comment.