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 { NgbModalModule } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { HotKeyService } from './services/hot-key.service'
|
import { HotKeyService } from './services/hot-key.service'
|
||||||
import { PermissionsGuard } from './guards/permissions.guard'
|
import { PermissionsGuard } from './guards/permissions.guard'
|
||||||
|
import { DirtySavedViewGuard } from './guards/dirty-saved-view.guard'
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
let component: AppComponent
|
let component: AppComponent
|
||||||
@ -38,7 +39,7 @@ describe('AppComponent', () => {
|
|||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [AppComponent, ToastsComponent, FileDropComponent],
|
declarations: [AppComponent, ToastsComponent, FileDropComponent],
|
||||||
providers: [PermissionsGuard],
|
providers: [PermissionsGuard, DirtySavedViewGuard],
|
||||||
imports: [
|
imports: [
|
||||||
HttpClientTestingModule,
|
HttpClientTestingModule,
|
||||||
TourNgBootstrapModule,
|
TourNgBootstrapModule,
|
||||||
@ -148,12 +149,16 @@ describe('AppComponent', () => {
|
|||||||
it('should support hotkeys', () => {
|
it('should support hotkeys', () => {
|
||||||
const addShortcutSpy = jest.spyOn(hotKeyService, 'addShortcut')
|
const addShortcutSpy = jest.spyOn(hotKeyService, 'addShortcut')
|
||||||
const routerSpy = jest.spyOn(router, 'navigate')
|
const routerSpy = jest.spyOn(router, 'navigate')
|
||||||
|
// prevent actual navigation
|
||||||
|
routerSpy.mockReturnValue(new Promise(() => {}))
|
||||||
|
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
|
||||||
component.ngOnInit()
|
component.ngOnInit()
|
||||||
expect(addShortcutSpy).toHaveBeenCalled()
|
expect(addShortcutSpy).toHaveBeenCalled()
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'h' }))
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'h' }))
|
||||||
expect(routerSpy).toHaveBeenCalledWith(['/dashboard'])
|
expect(routerSpy).toHaveBeenCalledWith(['/dashboard'])
|
||||||
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
|
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'd' }))
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'd' }))
|
||||||
expect(routerSpy).toHaveBeenCalledWith(['/documents'])
|
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(() => {
|
.subscribe(() => {
|
||||||
this.router.navigate(['/dashboard'])
|
this.router.navigate(['/dashboard'])
|
||||||
})
|
})
|
||||||
this.hotKeyService
|
if (
|
||||||
.addShortcut({ keys: 'd', description: $localize`Documents` })
|
this.permissionsService.currentUserCan(
|
||||||
.subscribe(() => {
|
PermissionAction.View,
|
||||||
this.router.navigate(['/documents'])
|
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 prevBtnTitle = $localize`Prev`
|
||||||
const nextBtnTitle = $localize`Next`
|
const nextBtnTitle = $localize`Next`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user