coverage, visual thing, allow immediate enter to run search

This commit is contained in:
shamoon 2024-05-10 12:34:07 -07:00
parent 393b4c5dd3
commit 18e78964f3
3 changed files with 53 additions and 12 deletions

View File

@ -36,6 +36,7 @@ import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-e
import { ElementRef } from '@angular/core' import { ElementRef } from '@angular/core'
import { ToastService } from 'src/app/services/toast.service' import { ToastService } from 'src/app/services/toast.service'
import { DataType } from 'src/app/data/datatype' import { DataType } from 'src/app/data/datatype'
import { queryParamsFromFilterRules } from 'src/app/utils/query-params'
const searchResults = { const searchResults = {
total: 11, total: 11,
@ -283,7 +284,6 @@ describe('GlobalSearchComponent', () => {
it('should support primary action', () => { it('should support primary action', () => {
const object = { id: 1 } const object = { id: 1 }
const routerSpy = jest.spyOn(router, 'navigate') const routerSpy = jest.spyOn(router, 'navigate')
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
const modalSpy = jest.spyOn(modalService, 'open') const modalSpy = jest.spyOn(modalService, 'open')
let modal: NgbModalRef let modal: NgbModalRef
@ -296,23 +296,41 @@ describe('GlobalSearchComponent', () => {
expect(routerSpy).toHaveBeenCalledWith(['/view', object.id]) expect(routerSpy).toHaveBeenCalledWith(['/view', object.id])
component.primaryAction(DataType.Correspondent, object) component.primaryAction(DataType.Correspondent, object)
expect(qfSpy).toHaveBeenCalledWith([ expect(routerSpy).toHaveBeenCalledWith([
{ rule_type: FILTER_HAS_CORRESPONDENT_ANY, value: object.id.toString() }, '/documents',
queryParamsFromFilterRules([
{
rule_type: FILTER_HAS_CORRESPONDENT_ANY,
value: object.id.toString(),
},
]),
]) ])
component.primaryAction(DataType.DocumentType, object) component.primaryAction(DataType.DocumentType, object)
expect(qfSpy).toHaveBeenCalledWith([ expect(routerSpy).toHaveBeenCalledWith([
{ rule_type: FILTER_HAS_DOCUMENT_TYPE_ANY, value: object.id.toString() }, '/documents',
queryParamsFromFilterRules([
{
rule_type: FILTER_HAS_DOCUMENT_TYPE_ANY,
value: object.id.toString(),
},
]),
]) ])
component.primaryAction(DataType.StoragePath, object) component.primaryAction(DataType.StoragePath, object)
expect(qfSpy).toHaveBeenCalledWith([ expect(routerSpy).toHaveBeenCalledWith([
{ rule_type: FILTER_HAS_STORAGE_PATH_ANY, value: object.id.toString() }, '/documents',
queryParamsFromFilterRules([
{ rule_type: FILTER_HAS_STORAGE_PATH_ANY, value: object.id.toString() },
]),
]) ])
component.primaryAction(DataType.Tag, object) component.primaryAction(DataType.Tag, object)
expect(qfSpy).toHaveBeenCalledWith([ expect(routerSpy).toHaveBeenCalledWith([
{ rule_type: FILTER_HAS_TAGS_ANY, value: object.id.toString() }, '/documents',
queryParamsFromFilterRules([
{ rule_type: FILTER_HAS_TAGS_ANY, value: object.id.toString() },
]),
]) ])
component.primaryAction(DataType.User, object) component.primaryAction(DataType.User, object)
@ -472,4 +490,25 @@ describe('GlobalSearchComponent', () => {
{ rule_type: FILTER_FULLTEXT_QUERY, value: 'test' }, { rule_type: FILTER_FULLTEXT_QUERY, value: 'test' },
]) ])
}) })
it('should support open in new window', () => {
const openSpy = jest.spyOn(window, 'open')
const event = new Event('click')
event['ctrlKey'] = true
component.primaryAction(DataType.Document, { id: 2 }, event as any)
expect(openSpy).toHaveBeenCalledWith('/documents/2', '_blank')
component.searchResults = searchResults as any
component.resultsDropdown.open()
fixture.detectChanges()
const button = component.primaryButtons.get(0).nativeElement
const keyboardEvent = new KeyboardEvent('keydown', {
key: 'Enter',
ctrlKey: true,
})
const dispatchSpy = jest.spyOn(button, 'dispatchEvent')
button.dispatchEvent(keyboardEvent)
expect(dispatchSpy).toHaveBeenCalledTimes(2) // once for keydown, second for click
})
}) })

View File

@ -220,6 +220,7 @@ export class GlobalSearchComponent implements OnInit {
private reset(close: boolean = false) { private reset(close: boolean = false) {
this.queryDebounce.next(null) this.queryDebounce.next(null)
this.query = null
this.searchResults = null this.searchResults = null
this.currentItemIndex = -1 this.currentItemIndex = -1
if (close) { if (close) {
@ -273,11 +274,11 @@ export class GlobalSearchComponent implements OnInit {
if (this.searchResults?.total === 1 && this.resultsDropdown.isOpen()) { if (this.searchResults?.total === 1 && this.resultsDropdown.isOpen()) {
this.primaryButtons.first.nativeElement.click() this.primaryButtons.first.nativeElement.click()
this.searchInput.nativeElement.blur() this.searchInput.nativeElement.blur()
} else if (this.searchResults?.total && !this.resultsDropdown.isOpen()) {
this.resultsDropdown.open()
} else if (this.query?.length) { } else if (this.query?.length) {
this.runAdvanedSearch() this.runAdvanedSearch()
this.reset(true) this.reset(true)
} else if (this.searchResults?.total && !this.resultsDropdown.isOpen()) {
this.resultsDropdown.open()
} }
} else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) { } else if (event.key === 'Escape' && !this.resultsDropdown.isOpen()) {
if (this.query?.length) { if (this.query?.length) {

View File

@ -332,7 +332,8 @@ textarea,
} }
} }
.input-group .form-control-sm { .input-group .form-control-sm,
.input-group .btn-sm {
// accommodate larger font size on mobile // accommodate larger font size on mobile
padding-top: .15rem; padding-top: .15rem;
padding-bottom: .15rem; padding-bottom: .15rem;