Skip to content

Commit

Permalink
[DURACOM-195] auth nav menu test WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-negretti committed Dec 5, 2023
1 parent e7d4b21 commit 2fa1f14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/app/shared/auth-nav-menu/auth-nav-menu.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="navbar-nav mr-auto" *ngIf="!(isMobile$ | async); else mobileButtons">
<div class="navbar-nav mr-auto" *ngIf="!(isMobile$ | async); else mobileButtons" data-test="auth-nav">
<div *ngIf="!(isAuthenticated | async) && (showAuth | async)"
class="nav-item"
(click)="$event.stopPropagation();">
Expand Down Expand Up @@ -38,15 +38,17 @@


<ng-template #mobileButtons>
<div *ngIf="!(isAuthenticated | async)">
<div *ngIf="!(isAuthenticated | async)" data-test="auth-nav">
<a routerLink="/login" routerLinkActive="active" class="loginLink px-0.5" role="button">
{{ 'nav.login' | translate }}<span class="sr-only">(current)</span>
</a>
</div>
<div *ngIf="(isAuthenticated | async)">
<div *ngIf="(isAuthenticated | async)" data-test="auth-nav">
<a role="button" [attr.aria-label]="'nav.logout' |translate" [title]="'nav.logout' | translate" routerLink="/logout" routerLinkActive="active" class="logoutLink px-1">
<i class="fas fa-sign-out-alt fa-lg fa-fw"></i>
<span class="sr-only">(current)</span>
</a>
</div>
</ng-template>

<!-- Do not use ul/li in this menu as it breaks e2e accessibility tests -->
18 changes: 10 additions & 8 deletions src/app/shared/auth-nav-menu/auth-nav-menu.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { AuthService } from '../../core/auth/auth.service';
import { of } from 'rxjs';
import { BrowserOnlyMockPipe } from '../testing/browser-only-mock.pipe';
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';

describe('AuthNavMenuComponent', () => {
fdescribe('AuthNavMenuComponent', () => {

let component: AuthNavMenuComponent;
let deNavMenu: DebugElement;
Expand Down Expand Up @@ -75,6 +76,7 @@ describe('AuthNavMenuComponent', () => {
strictActionImmutability: false
}
}),
NgbDropdown,
TranslateModule.forRoot()
],
declarations: [
Expand Down Expand Up @@ -120,7 +122,7 @@ describe('AuthNavMenuComponent', () => {
const navMenuSelector = '.navbar-nav';
deNavMenu = fixture.debugElement.query(By.css(navMenuSelector));

const navMenuItemSelector = 'li';
const navMenuItemSelector = '.nav-item';
deNavMenuItem = deNavMenu.query(By.css(navMenuItemSelector));
}));
afterEach(() => {
Expand Down Expand Up @@ -158,7 +160,7 @@ describe('AuthNavMenuComponent', () => {
const navMenuSelector = '.navbar-nav';
deNavMenu = fixture.debugElement.query(By.css(navMenuSelector));

const navMenuItemSelector = 'li';
const navMenuItemSelector = '.nav-item';
deNavMenuItem = deNavMenu.query(By.css(navMenuItemSelector));
}));

Expand Down Expand Up @@ -200,7 +202,7 @@ describe('AuthNavMenuComponent', () => {
const navMenuSelector = '.navbar-nav';
deNavMenu = fixture.debugElement.query(By.css(navMenuSelector));

const navMenuItemSelector = 'li';
const navMenuItemSelector = '.nav-item';
deNavMenuItem = deNavMenu.query(By.css(navMenuItemSelector));
}));

Expand All @@ -210,7 +212,7 @@ describe('AuthNavMenuComponent', () => {
});

it('should render login dropdown menu', () => {
const loginDropdownMenu = deNavMenuItem.query(By.css('div.loginDropdownMenu'));
const loginDropdownMenu = deNavMenuItem.query(By.css('div#loginDropdownMenu'));
expect(loginDropdownMenu.nativeElement).toBeDefined();
});
});
Expand Down Expand Up @@ -239,7 +241,7 @@ describe('AuthNavMenuComponent', () => {
const navMenuSelector = '.navbar-nav';
deNavMenu = fixture.debugElement.query(By.css(navMenuSelector));

const navMenuItemSelector = 'li';
const navMenuItemSelector = '.nav-item';
deNavMenuItem = deNavMenu.query(By.css(navMenuItemSelector));
}));

Expand Down Expand Up @@ -309,10 +311,10 @@ describe('AuthNavMenuComponent', () => {

fixture.detectChanges();

const navMenuSelector = '.navbar-nav';
const navMenuSelector = '[data-test="auth-nav"]';
deNavMenu = fixture.debugElement.query(By.css(navMenuSelector));

const navMenuItemSelector = 'li';
const navMenuItemSelector = '.nav-item';
deNavMenuItem = deNavMenu.query(By.css(navMenuItemSelector));
}));

Expand Down

0 comments on commit 2fa1f14

Please sign in to comment.