Skip to content

Commit

Permalink
Document collection search options alerts the user
Browse files Browse the repository at this point in the history
If no radio button is selected, then set an alert
  • Loading branch information
minhngocd committed Sep 25, 2023
1 parent 70cf844 commit 0dea505
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Admin::DocumentCollectionGroupDocumentSearchController < Admin::BaseContro
def search_options; end

def search
unless params[:search_option].present?
flash.now[:alert] = "Please select a search option"
render :search_options
end
redirect_to(action: :search_title_slug, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title-or-slug"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl
assert_template "document_collection_group_document_search/search_options"
end

view_test "POST #search with an empty option shows an alert flash" do
@request_params[:search_option] = ""
post :search, params: @request_params
assert_template "document_collection_group_document_search/search_options"
assert_select ".gem-c-error-alert__message", text: /Please select a search option/
end

view_test "POST #search with no search options shows an alert flash" do
post :search, params: @request_params
assert_template "document_collection_group_document_search/search_options"
assert_select ".gem-c-error-alert__message", text: /Please select a search option/
end

test "POST #search is a noop when passed param is unrecognised" do
@request_params[:search_option] = "non-existant"
post :search, params: @request_params
Expand Down

0 comments on commit 0dea505

Please sign in to comment.