diff --git a/app/views/administrate/application/index.html.erb b/app/views/administrate/application/index.html.erb
index 36e64b0030..25db68c996 100644
--- a/app/views/administrate/application/index.html.erb
+++ b/app/views/administrate/application/index.html.erb
@@ -29,6 +29,7 @@ It renders the `_table` partial to display details about the resources.
search_term: search_term,
page: page,
show_search_bar: show_search_bar,
+ filters: filters,
)
%>
diff --git a/lib/administrate/search.rb b/lib/administrate/search.rb
index ac04587c9f..672c05c9f2 100644
--- a/lib/administrate/search.rb
+++ b/lib/administrate/search.rb
@@ -63,6 +63,14 @@ def run
end
end
+ def valid_filters
+ if @dashboard.class.const_defined?(:COLLECTION_FILTERS)
+ @dashboard.class.const_get(:COLLECTION_FILTERS).stringify_keys
+ else
+ {}
+ end
+ end
+
private
def apply_filter(filter, filter_param, resources)
@@ -116,14 +124,6 @@ def search_results(resources)
.where(query_template, *query_values)
end
- def valid_filters
- if @dashboard.class.const_defined?(:COLLECTION_FILTERS)
- @dashboard.class.const_get(:COLLECTION_FILTERS).stringify_keys
- else
- {}
- end
- end
-
def attribute_types
@dashboard.class.const_get(:ATTRIBUTE_TYPES)
end
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index 5c193929cf..07d82139b0 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -25,6 +25,49 @@ def have_a_search_bar
end
end
+ describe "search bar tooltip" do
+ def have_a_search_tooltip
+ have_css("button[popovertarget=search-tooltip]")
+ end
+
+ it "is visible when the current dashboard has collection filters" do
+ visit admin_customers_path
+
+ expect(page).to have_a_search_tooltip
+ end
+
+ context "when clicked" do
+ it "shows a popover with the available filters" do
+ visit admin_customers_path
+ click_on "?"
+
+ expect(page).to have_content("Use filters to refine your search:")
+ expect(page).to have_content("vip:")
+ expect(page).to have_content("kind:")
+ end
+ end
+
+ it "is hidden when the current dashboard has no collection filters" do
+ CustomerDashboard::COLLECTION_FILTERS = {}.freeze
+
+ visit admin_customers_path
+
+ expect(page).not_to have_a_search_tooltip
+ end
+
+ it "is hidden when nothing is searchable in the current dashboard" do
+ CustomerDashboard::ATTRIBUTE_TYPES.each do |_name, field_class|
+ allow(field_class).to(
+ receive(:searchable?).and_return(false)
+ )
+ end
+
+ visit admin_customers_path
+
+ expect(page).not_to have_a_search_tooltip
+ end
+ end
+
scenario "admin searches for customer by email", :js do
query = "bar@baz.com"
perfect_match = create(:customer, email: "bar@baz.com")