diff --git a/app/controllers/admin/poll/booths_controller.rb b/app/controllers/admin/poll/booths_controller.rb index 514389203..c27a65694 100644 --- a/app/controllers/admin/poll/booths_controller.rb +++ b/app/controllers/admin/poll/booths_controller.rb @@ -2,6 +2,7 @@ class Admin::Poll::BoothsController < Admin::Poll::BaseController load_and_authorize_resource class: "Poll::Booth" def index + @booths = @booths.search params[:search] if params[:search] @booths = @booths.order(name: :asc).page(params[:page]) end diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index 6a03b38fa..9a7e38247 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -10,6 +10,8 @@ <% end %> +<%= render "/admin/shared/booth_search", url: admin_booths_path %> + <% if @booths.any? %>

<%= page_entries_info @booths %>

diff --git a/app/views/admin/shared/_booth_search.html.erb b/app/views/admin/shared/_booth_search.html.erb new file mode 100644 index 000000000..eb22940db --- /dev/null +++ b/app/views/admin/shared/_booth_search.html.erb @@ -0,0 +1,10 @@ +<%= form_for(Poll::Booth.new, url: url, as: :booth, method: :get) do |f| %> +
+
+ <%= text_field_tag :search, params[:search], placeholder: t("admin.shared.booths_search.placeholder") %> +
+ <%= f.submit t("admin.shared.booths_search.button"), class: "button" %> +
+
+
+<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8ce3dab12..6529b19bb 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1330,7 +1330,7 @@ en: false_value: "No" booths_search: button: Search - placeholder: Search booth by name + placeholder: Search booth by name or location poll_officers_search: button: Search placeholder: Search poll officers diff --git a/spec/features/admin/poll/booths_spec.rb b/spec/features/admin/poll/booths_spec.rb index c49a34b6b..e81f4e539 100644 --- a/spec/features/admin/poll/booths_spec.rb +++ b/spec/features/admin/poll/booths_spec.rb @@ -123,4 +123,22 @@ describe "Admin booths" do click_link "Go back" expect(page).to have_current_path(available_admin_booths_path) end + + scenario "Search" do + booth = create(:poll_booth) + + visit admin_booths_path + + fill_in "search", with: booth.name + click_button "Search" + expect(page).to have_css(".booth", count: 1) + + fill_in "search", with: booth.location + click_button "Search" + expect(page).to have_css(".booth", count: 1) + + fill_in "search", with: "Wrong search criteria" + click_button "Search" + expect(page).to have_content "There are no active booths for any upcoming poll." + end end diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 8e02ca9b4..bbde7be25 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -48,6 +48,8 @@ describe "Admin shifts" do click_link "Manage shifts" end + expect(page).to have_content "This booth has no shifts" + fill_in "search", with: officer.email click_button "Search" click_link "Edit shifts" @@ -72,6 +74,8 @@ describe "Admin shifts" do click_link "Manage shifts" end + expect(page).to have_css(".shift", count: 1) + fill_in "search", with: officer.email click_button "Search" click_link "Edit shifts" @@ -115,6 +119,8 @@ describe "Admin shifts" do click_link "Manage shifts" end + expect(page).to have_css(".shift", count: 2) + fill_in "search", with: officer.email click_button "Search" click_link "Edit shifts" @@ -154,6 +160,8 @@ describe "Admin shifts" do click_link "Manage shifts" end + expect(page).to have_content "This booth has no shifts" + fill_in "search", with: officer.email click_button "Search" click_link "Edit shifts"