From 478b6e6f94ea6a6505a287685e518caaa10ac272 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:17:26 -0700 Subject: [PATCH] Add settings shortcut --- src-ui/src/app/app.component.spec.ts | 9 +++++++-- src-ui/src/app/app.component.ts | 29 +++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src-ui/src/app/app.component.spec.ts b/src-ui/src/app/app.component.spec.ts index 769f7a30b..e5fac4cc5 100644 --- a/src-ui/src/app/app.component.spec.ts +++ b/src-ui/src/app/app.component.spec.ts @@ -23,6 +23,7 @@ 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' +import { DirtySavedViewGuard } from './guards/dirty-saved-view.guard' describe('AppComponent', () => { let component: AppComponent @@ -38,7 +39,7 @@ describe('AppComponent', () => { beforeEach(async () => { TestBed.configureTestingModule({ declarations: [AppComponent, ToastsComponent, FileDropComponent], - providers: [PermissionsGuard], + providers: [PermissionsGuard, DirtySavedViewGuard], imports: [ HttpClientTestingModule, TourNgBootstrapModule, @@ -148,12 +149,16 @@ describe('AppComponent', () => { it('should support hotkeys', () => { const addShortcutSpy = jest.spyOn(hotKeyService, 'addShortcut') const routerSpy = jest.spyOn(router, 'navigate') + // prevent actual navigation + routerSpy.mockReturnValue(new Promise(() => {})) + jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) component.ngOnInit() expect(addShortcutSpy).toHaveBeenCalled() 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']) + document.dispatchEvent(new KeyboardEvent('keydown', { key: 's' })) + expect(routerSpy).toHaveBeenCalledWith(['/settings']) }) }) diff --git a/src-ui/src/app/app.component.ts b/src-ui/src/app/app.component.ts index 565f4cd9f..7e8abdf34 100644 --- a/src-ui/src/app/app.component.ts +++ b/src-ui/src/app/app.component.ts @@ -130,11 +130,30 @@ export class AppComponent implements OnInit, OnDestroy { .subscribe(() => { this.router.navigate(['/dashboard']) }) - this.hotKeyService - .addShortcut({ keys: 'd', description: $localize`Documents` }) - .subscribe(() => { - this.router.navigate(['/documents']) - }) + if ( + this.permissionsService.currentUserCan( + PermissionAction.View, + PermissionType.Document + ) + ) { + this.hotKeyService + .addShortcut({ keys: 'd', description: $localize`Documents` }) + .subscribe(() => { + this.router.navigate(['/documents']) + }) + } + if ( + this.permissionsService.currentUserCan( + PermissionAction.Change, + PermissionType.UISettings + ) + ) { + this.hotKeyService + .addShortcut({ keys: 's', description: $localize`Settings` }) + .subscribe(() => { + this.router.navigate(['/settings']) + }) + } const prevBtnTitle = $localize`Prev` const nextBtnTitle = $localize`Next`