mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-30 22:47:15 +00:00
Fix: set global search earlier to avoid awaiting debounce (#13865)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
[ngModel]="query()"
|
||||
(ngModelChange)="queryDebounce.next($event)"
|
||||
(ngModelChange)="onQueryChange($event)"
|
||||
(keydown)="searchInputKeyDown($event)"
|
||||
ngbDropdownAnchor>
|
||||
<div class="position-absolute top-50 end-0 translate-middle">
|
||||
|
||||
@@ -272,6 +272,19 @@ describe('GlobalSearchComponent', () => {
|
||||
expect(advancedSearchSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should set query immediately and run full search on enter without waiting for debounce', () => {
|
||||
jest.useFakeTimers()
|
||||
const searchSpy = jest.spyOn(searchService, 'globalSearch')
|
||||
searchSpy.mockReturnValue(of({} as any))
|
||||
const fullSearchSpy = jest.spyOn(component, 'runFullSearch')
|
||||
component.onQueryChange('test')
|
||||
expect(component.query()).toBe('test')
|
||||
component.searchInputKeyDown(new KeyboardEvent('keydown', { key: 'Enter' }))
|
||||
expect(fullSearchSpy).toHaveBeenCalled()
|
||||
expect(searchSpy).not.toHaveBeenCalled()
|
||||
jest.useRealTimers()
|
||||
})
|
||||
|
||||
it('should search on query debounce', () => {
|
||||
jest.useFakeTimers()
|
||||
const query = 'test'
|
||||
|
||||
@@ -119,6 +119,12 @@ export class GlobalSearchComponent implements OnInit {
|
||||
})
|
||||
}
|
||||
|
||||
public onQueryChange(text: string) {
|
||||
// set immediately so Enter / the full search button work without waiting for the debounce
|
||||
this.query.set(text)
|
||||
this.queryDebounce.next(text)
|
||||
}
|
||||
|
||||
public ngOnInit() {
|
||||
this.hotkeyService
|
||||
.addShortcut({ keys: '/', description: $localize`Global search` })
|
||||
|
||||
Reference in New Issue
Block a user