Show search source badges only with show_sources param
The badges are a debugging aid - render them only when explicitly requested via ?show_sources=1 instead of on every search.
This commit is contained in:
parent
323b7004ed
commit
4c736096ae
3 changed files with 19 additions and 4 deletions
|
|
@ -25,7 +25,7 @@ class PackagesControllerTest < ActionController::TestCase
|
|||
test 'exact package name search wins without calling the vector service' do
|
||||
with_stubbed_method(Package, :nearest_to_text,
|
||||
->(_text) { flunk 'should not call vector search' }) do
|
||||
get :grid, params: { search: 'vim' }
|
||||
get :grid, params: { search: 'vim', show_sources: '1' }
|
||||
assert_response :success
|
||||
assert_select 'div', 'vim'
|
||||
assert_equal({ packages(:vim).id => :exact }, assigns(:search_sources))
|
||||
|
|
@ -75,7 +75,7 @@ class PackagesControllerTest < ActionController::TestCase
|
|||
# "fire fox" should find "firefox" via name substring matching
|
||||
with_stubbed_method(Package, :nearest_to_text,
|
||||
->(_text, **_opts) { Package.none }) do
|
||||
get :grid, params: { search: 'fire fox' }
|
||||
get :grid, params: { search: 'fire fox', show_sources: '1' }
|
||||
assert_response :success
|
||||
assert_select 'div', text: 'firefox', count: 1
|
||||
assert_equal({ packages(:firefox).id => :name_contains },
|
||||
|
|
@ -84,6 +84,15 @@ class PackagesControllerTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'search source badges stay hidden without show_sources param' do
|
||||
with_stubbed_method(Package, :nearest_to_text,
|
||||
->(_text, **_opts) { Package.none }) do
|
||||
get :grid, params: { search: 'fire fox' }
|
||||
assert_response :success
|
||||
assert_select '.search-source', count: 0
|
||||
end
|
||||
end
|
||||
|
||||
test 'details shows semantically related packages' do
|
||||
packages(:vim).update_column(:embedding, Array.new(384, 0.25))
|
||||
packages(:firefox).update_column(:embedding, Array.new(384, 0.75))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue