Add settings shortcut
This commit is contained in:
parent
a0f9e995d5
commit
478b6e6f94
@ -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'])
|
||||
})
|
||||
})
|
||||
|
@ -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`
|
||||
|
Loading…
x
Reference in New Issue
Block a user