summaryrefslogtreecommitdiff
path: root/test/controllers
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-13 03:48:28 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-13 03:48:28 +0200
commit5f56fa867f073d8d1aecbfbba4a340ea414cfb0d (patch)
tree5f39c0386b2e5819289e916ccdb67b987c2131fa /test/controllers
parent70653b681d10917b77dced08f577446ced7568f1 (diff)
Add loadOnFocus to initSearchPicker; asset search shows recent by default
initSearchPicker's input handler has always short-circuited on an empty term -- correct for every existing picker, none of which want results appearing before anything's typed. The asset picker does want exactly that (show the last few uploaded images without requiring a search first), so this adds an opt-in loadOnFocus option instead of changing the shared default: it fires once when the input gains focus with no term yet, reusing the same request/render path a real search uses rather than a separate code path. The AJAX call itself was pulled out into a named runSearch function so both triggers could share it without duplicating the success/render logic. RelatedAssetsController#search now treats a blank term as "show the most recently created, unattached images" (limit 5) rather than returning nothing, matching the new client behavior. A real search term still returns up to 10 name-matched results, unchanged.
Diffstat (limited to 'test/controllers')
-rw-r--r--test/controllers/related_assets_controller_test.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/test/controllers/related_assets_controller_test.rb b/test/controllers/related_assets_controller_test.rb
index a3082c2..7f6d487 100644
--- a/test/controllers/related_assets_controller_test.rb
+++ b/test/controllers/related_assets_controller_test.rb
@@ -11,7 +11,7 @@ class RelatedAssetsControllerTest < ActionController::TestCase
11 Asset.create!(:name => "biometrics-poster", :upload_content_type => "image/png") 11 Asset.create!(:name => "biometrics-poster", :upload_content_type => "image/png")
12 Asset.create!(:name => "chaostreff-flyer", :upload_content_type => "image/png") 12 Asset.create!(:name => "chaostreff-flyer", :upload_content_type => "image/png")
13 13
14 get :search, params: { :node_id => node.id, :q => "biometrics" } 14 get :search, params: { :node_id => node.id, :search_term => "biometrics" }
15 15
16 json = JSON.parse(response.body) 16 json = JSON.parse(response.body)
17 names = json.map { |a| a["name"] } 17 names = json.map { |a| a["name"] }
@@ -20,13 +20,19 @@ class RelatedAssetsControllerTest < ActionController::TestCase
20 assert_not_includes names, "chaostreff-flyer" 20 assert_not_includes names, "chaostreff-flyer"
21 end 21 end
22 22
23 test "search returns an empty list for a blank term" do 23 test "search with a blank term returns the most recently created assets" do
24 Asset.delete_all
25 RelatedAsset.delete_all
24 login_as :quentin 26 login_as :quentin
25 node = Node.root.children.create!(:slug => "related_assets_blank_search_test") 27 node = Node.root.children.create!(:slug => "related_assets_recent_test")
26 28
27 get :search, params: { :node_id => node.id, :q => "" } 29 Asset.create!(:name => "older-photo", :upload_content_type => "image/png", :created_at => 2.days.ago)
30 Asset.create!(:name => "newer-photo", :upload_content_type => "image/png", :created_at => 1.hour.ago)
28 31
29 assert_equal [], JSON.parse(response.body) 32 get :search, params: { :node_id => node.id, :search_term => "" }
33
34 json = JSON.parse(response.body)
35 assert_equal ["newer-photo", "older-photo"], json.map { |a| a["name"] }
30 end 36 end
31 37
32 test "create attaches an asset to the node's editable page" do 38 test "create attaches an asset to the node's editable page" do