diff --git a/src-ui/src/app/app.component.spec.ts b/src-ui/src/app/app.component.spec.ts index 75f84d410..769f7a30b 100644 --- a/src-ui/src/app/app.component.spec.ts +++ b/src-ui/src/app/app.component.spec.ts @@ -5,8 +5,7 @@ import { fakeAsync, tick, } from '@angular/core/testing' -import { Router } from '@angular/router' -import { RouterTestingModule } from '@angular/router/testing' +import { Router, RouterModule } from '@angular/router' import { TourService, TourNgBootstrapModule } from 'ngx-ui-tour-ng-bootstrap' import { Subject } from 'rxjs' import { routes } from './app-routing.module' @@ -23,6 +22,7 @@ import { FileDropComponent } from './components/file-drop/file-drop.component' import { NgxFileDropModule } from 'ngx-file-drop' import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap' import { HotKeyService } from './services/hot-key.service' +import { PermissionsGuard } from './guards/permissions.guard' describe('AppComponent', () => { let component: AppComponent @@ -38,11 +38,11 @@ describe('AppComponent', () => { beforeEach(async () => { TestBed.configureTestingModule({ declarations: [AppComponent, ToastsComponent, FileDropComponent], - providers: [], + providers: [PermissionsGuard], imports: [ HttpClientTestingModule, TourNgBootstrapModule, - RouterTestingModule.withRoutes(routes), + RouterModule.forRoot(routes), NgxFileDropModule, NgbModalModule, ], @@ -150,9 +150,10 @@ describe('AppComponent', () => { const routerSpy = jest.spyOn(router, 'navigate') component.ngOnInit() expect(addShortcutSpy).toHaveBeenCalled() - document.dispatchEvent( - new KeyboardEvent('keydown', { key: 'h', ctrlKey: true }) - ) + document.dispatchEvent(new KeyboardEvent('keydown', { key: 'h' })) expect(routerSpy).toHaveBeenCalledWith(['/dashboard']) + jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) + document.dispatchEvent(new KeyboardEvent('keydown', { key: 'd' })) + expect(routerSpy).toHaveBeenCalledWith(['/documents']) }) }) diff --git a/src-ui/src/app/app.component.ts b/src-ui/src/app/app.component.ts index bc18c8f31..565f4cd9f 100644 --- a/src-ui/src/app/app.component.ts +++ b/src-ui/src/app/app.component.ts @@ -126,12 +126,12 @@ export class AppComponent implements OnInit, OnDestroy { }) this.hotKeyService - .addShortcut({ keys: 'control.h', description: $localize`Dashboard` }) + .addShortcut({ keys: 'h', description: $localize`Dashboard` }) .subscribe(() => { this.router.navigate(['/dashboard']) }) this.hotKeyService - .addShortcut({ keys: 'control.d', description: $localize`Documents` }) + .addShortcut({ keys: 'd', description: $localize`Documents` }) .subscribe(() => { this.router.navigate(['/documents']) }) diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts index 7d5d628a4..58b7ca894 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts @@ -150,14 +150,8 @@ describe('GlobalSearchComponent', () => { it('should handle keyboard nav', () => { const focusSpy = jest.spyOn(component.searchInput.nativeElement, 'focus') - document.dispatchEvent( - new KeyboardEvent('keydown', { key: 'k', ctrlKey: true }) - ) + document.dispatchEvent(new KeyboardEvent('keydown', { key: '/' })) expect(focusSpy).toHaveBeenCalled() - // coverage - document.dispatchEvent( - new KeyboardEvent('keydown', { key: 'k', metaKey: true }) - ) component.searchResults = searchResults as any component.resultsDropdown.open() diff --git a/src-ui/src/app/components/app-frame/global-search/global-search.component.ts b/src-ui/src/app/components/app-frame/global-search/global-search.component.ts index f05192b5b..1ae0b9499 100644 --- a/src-ui/src/app/components/app-frame/global-search/global-search.component.ts +++ b/src-ui/src/app/components/app-frame/global-search/global-search.component.ts @@ -88,7 +88,7 @@ export class GlobalSearchComponent implements OnInit { ngOnInit() { this.hotkeyService - .addShortcut({ keys: 'control.k', description: $localize`Global search` }) + .addShortcut({ keys: '/', description: $localize`Global search` }) .subscribe(() => { this.searchInput.nativeElement.focus() })