Skip to content

Commit 2cc6158

Browse files
committed
test: Add test for check Admin page in user menu is present if user is admin
1 parent b719828 commit 2cc6158

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/app/layout/user-menu/user-menu.component.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { of, ReplaySubject } from 'rxjs'
2525
import { Config } from '../../types/togglz.endpoint'
2626
import { MatIconModule } from '@angular/material/icon'
2727
import { MatIconHarness } from '@angular/material/icon/testing'
28-
import { MatMenuHarness } from '@angular/material/menu/testing'
28+
import { MatMenuHarness, MatMenuItemHarness } from '@angular/material/menu/testing'
2929

3030
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
3131

@@ -85,6 +85,28 @@ describe('UserMenuComponent', () => {
8585
expect(component).toBeTruthy()
8686
})
8787

88+
it('should display user admin actions option if user is admin', async () => {
89+
let mockUserSessionResponse: UserSession = getUserSession();
90+
mockUserSessionResponse.userInfo.ADMIN_MENU = 'true';
91+
92+
component.userInfo = mockUserSessionResponse.userInfo;
93+
94+
fixture.detectChanges()
95+
96+
const matMenu = await loader.getHarness(MatMenuHarness)
97+
await matMenu.open()
98+
99+
fixture.detectChanges()
100+
101+
const isMatMenuOpen = await matMenu.isOpen()
102+
const matMenuItems: MatMenuItemHarness[] = await matMenu.getItems()
103+
const adminPageItem = await matMenuItems[5].getText()
104+
105+
expect(isMatMenuOpen).toBe(true)
106+
expect(matMenuItems.length).toBe(7)
107+
expect(adminPageItem).toContain('Admin page')
108+
})
109+
88110
it('should display 3 as unread notifications count', async () => {
89111
const userMenuButton = fixture.debugElement.query(By.css('#cy-user-info'))
90112
userMenuButton.triggerEventHandler('click', null)
@@ -107,6 +129,7 @@ function getUserSession(): UserSession {
107129
userSession.userInfo = {
108130
REAL_USER_ORCID: '0000-0000-0000-000X',
109131
EFFECTIVE_USER_ORCID: '0000-0000-0000-000X',
132+
IN_DELEGATION_MODE: 'false',
110133
} as UserInfo
111134
userSession.loggedIn = true
112135
userSession.displayName = 'Test Name'

0 commit comments

Comments
 (0)