Changed my mind about shortcut keys

This commit is contained in:
shamoon 2024-04-04 23:46:48 -07:00
parent 63157583f3
commit 097566e3d1
4 changed files with 12 additions and 17 deletions

View File

@ -5,8 +5,7 @@ import {
fakeAsync, fakeAsync,
tick, tick,
} from '@angular/core/testing' } from '@angular/core/testing'
import { Router } from '@angular/router' import { Router, RouterModule } from '@angular/router'
import { RouterTestingModule } from '@angular/router/testing'
import { TourService, TourNgBootstrapModule } from 'ngx-ui-tour-ng-bootstrap' import { TourService, TourNgBootstrapModule } from 'ngx-ui-tour-ng-bootstrap'
import { Subject } from 'rxjs' import { Subject } from 'rxjs'
import { routes } from './app-routing.module' 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 { 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'
describe('AppComponent', () => { describe('AppComponent', () => {
let component: AppComponent let component: AppComponent
@ -38,11 +38,11 @@ describe('AppComponent', () => {
beforeEach(async () => { beforeEach(async () => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [AppComponent, ToastsComponent, FileDropComponent], declarations: [AppComponent, ToastsComponent, FileDropComponent],
providers: [], providers: [PermissionsGuard],
imports: [ imports: [
HttpClientTestingModule, HttpClientTestingModule,
TourNgBootstrapModule, TourNgBootstrapModule,
RouterTestingModule.withRoutes(routes), RouterModule.forRoot(routes),
NgxFileDropModule, NgxFileDropModule,
NgbModalModule, NgbModalModule,
], ],
@ -150,9 +150,10 @@ describe('AppComponent', () => {
const routerSpy = jest.spyOn(router, 'navigate') const routerSpy = jest.spyOn(router, 'navigate')
component.ngOnInit() component.ngOnInit()
expect(addShortcutSpy).toHaveBeenCalled() expect(addShortcutSpy).toHaveBeenCalled()
document.dispatchEvent( document.dispatchEvent(new KeyboardEvent('keydown', { key: 'h' }))
new KeyboardEvent('keydown', { key: 'h', ctrlKey: true })
)
expect(routerSpy).toHaveBeenCalledWith(['/dashboard']) expect(routerSpy).toHaveBeenCalledWith(['/dashboard'])
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'd' }))
expect(routerSpy).toHaveBeenCalledWith(['/documents'])
}) })
}) })

View File

@ -126,12 +126,12 @@ export class AppComponent implements OnInit, OnDestroy {
}) })
this.hotKeyService this.hotKeyService
.addShortcut({ keys: 'control.h', description: $localize`Dashboard` }) .addShortcut({ keys: 'h', description: $localize`Dashboard` })
.subscribe(() => { .subscribe(() => {
this.router.navigate(['/dashboard']) this.router.navigate(['/dashboard'])
}) })
this.hotKeyService this.hotKeyService
.addShortcut({ keys: 'control.d', description: $localize`Documents` }) .addShortcut({ keys: 'd', description: $localize`Documents` })
.subscribe(() => { .subscribe(() => {
this.router.navigate(['/documents']) this.router.navigate(['/documents'])
}) })

View File

@ -150,14 +150,8 @@ describe('GlobalSearchComponent', () => {
it('should handle keyboard nav', () => { it('should handle keyboard nav', () => {
const focusSpy = jest.spyOn(component.searchInput.nativeElement, 'focus') const focusSpy = jest.spyOn(component.searchInput.nativeElement, 'focus')
document.dispatchEvent( document.dispatchEvent(new KeyboardEvent('keydown', { key: '/' }))
new KeyboardEvent('keydown', { key: 'k', ctrlKey: true })
)
expect(focusSpy).toHaveBeenCalled() expect(focusSpy).toHaveBeenCalled()
// coverage
document.dispatchEvent(
new KeyboardEvent('keydown', { key: 'k', metaKey: true })
)
component.searchResults = searchResults as any component.searchResults = searchResults as any
component.resultsDropdown.open() component.resultsDropdown.open()

View File

@ -88,7 +88,7 @@ export class GlobalSearchComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.hotkeyService this.hotkeyService
.addShortcut({ keys: 'control.k', description: $localize`Global search` }) .addShortcut({ keys: '/', description: $localize`Global search` })
.subscribe(() => { .subscribe(() => {
this.searchInput.nativeElement.focus() this.searchInput.nativeElement.focus()
}) })