Allow disabling advanced search in global search
This commit is contained in:
@@ -6,10 +6,13 @@ import { Subscription } from 'rxjs'
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { SearchService } from './search.service'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: SearchService
|
||||
let subscription: Subscription
|
||||
let settingsService: SettingsService
|
||||
const endpoint = 'search/autocomplete'
|
||||
|
||||
describe('SearchService', () => {
|
||||
@@ -20,6 +23,7 @@ describe('SearchService', () => {
|
||||
})
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
settingsService = TestBed.inject(SettingsService)
|
||||
service = TestBed.inject(SearchService)
|
||||
})
|
||||
|
||||
@@ -36,4 +40,18 @@ describe('SearchService', () => {
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
||||
it('should call correct api endpoint on globalSearch', () => {
|
||||
const query = 'apple'
|
||||
service.globalSearch(query).subscribe()
|
||||
httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}search/?query=${query}`
|
||||
)
|
||||
|
||||
settingsService.set(SETTINGS_KEYS.SEARCH_DB_ONLY, true)
|
||||
subscription = service.globalSearch(query).subscribe()
|
||||
httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}search/?query=${query}&db_only=true`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,6 +13,8 @@ import { StoragePath } from 'src/app/data/storage-path'
|
||||
import { Tag } from 'src/app/data/tag'
|
||||
import { User } from 'src/app/data/user'
|
||||
import { Workflow } from 'src/app/data/workflow'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
export interface GlobalSearchResult {
|
||||
total: number
|
||||
@@ -33,7 +35,10 @@ export interface GlobalSearchResult {
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class SearchService {
|
||||
constructor(private http: HttpClient) {}
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private settingsService: SettingsService
|
||||
) {}
|
||||
|
||||
autocomplete(term: string): Observable<string[]> {
|
||||
return this.http.get<string[]>(
|
||||
@@ -43,9 +48,13 @@ export class SearchService {
|
||||
}
|
||||
|
||||
globalSearch(query: string): Observable<GlobalSearchResult> {
|
||||
let params = new HttpParams().set('query', query)
|
||||
if (this.settingsService.get(SETTINGS_KEYS.SEARCH_DB_ONLY)) {
|
||||
params = params.set('db_only', true)
|
||||
}
|
||||
return this.http.get<GlobalSearchResult>(
|
||||
`${environment.apiBaseUrl}search/`,
|
||||
{ params: new HttpParams().set('query', query) }
|
||||
{ params }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user