Changed my mind about shortcut keys
This commit is contained in:
parent
63157583f3
commit
097566e3d1
@ -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'])
|
||||
})
|
||||
})
|
||||
|
@ -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'])
|
||||
})
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user