Skip to content

Commit

Permalink
Removed keyword slug from search via title.
Browse files Browse the repository at this point in the history
  • Loading branch information
farahTW committed Oct 11, 2023
1 parent 945bd36 commit bed106b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def search
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"
redirect_to(action: :search_by_title, document_collection_id: @collection, group_id: @group) if params[:search_option] == "title"
end

def search_title_slug
def search_by_title
flash.now[:alert] = "Please enter a search query" if params[:title] && params[:title].empty?
if params[:title].present?
filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
text: "Search via URL",
},
{
value: "title-or-slug",
value: "title",
text: "Search via title",
},
]
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def redirect(path, options = { prefix: Whitehall.router_prefix })
resources :document_collection_groups, as: :groups, path: "groups" do
get :search_options, to: "document_collection_group_document_search#search_options"
post :search_options, to: "document_collection_group_document_search#search"
get :search_title_slug, to: "document_collection_group_document_search#search_title_slug"
get :search_by_title, to: "document_collection_group_document_search#search_by_title"
member { get :confirm_destroy }
resource :document_collection_group_membership, as: :members, path: "members", only: [:destroy]
resources :document_collection_group_memberships, path: "members", only: %i[index destroy] do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,46 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl
assert_template nil
end

test "POST #search redirects to #search_title_slug if search option passed is title-or-slug" do
@request_params[:search_option] = "title-or-slug"
test "POST #search redirects to #search_by_title if search option passed is title" do
@request_params[:search_option] = "title"
post :search, params: @request_params
assert_redirected_to admin_document_collection_group_search_title_slug_path(@collection, @group)
assert_redirected_to admin_document_collection_group_search_by_title_path(@collection, @group)
end

test "GET #search_title_slug without query renders search for title & slug page with no results section" do
get :search_title_slug, params: @request_params
assert_template "document_collection_group_document_search/search_title_slug"
test "GET #search_by_title without query renders search for title page with no results section" do
get :search_by_title, params: @request_params
assert_template "document_collection_group_document_search/search_by_title"
assert_select ".app-view-document-collection-document-search-results", count: 0
end

test "GET :search_title_slug with search value passes title and default params to filter" do
test "GET :search_by_title with search value passes title and default params to filter" do
edition_scope = Edition.with_translations(I18n.locale)
default_filter_params_with_title = @default_filter_params.merge(title: "Something")
Admin::EditionFilter.expects(:new).with(edition_scope, @user, default_filter_params_with_title)
@request_params[:title] = "Something"
get :search_title_slug, params: @request_params
assert_template "document_collection_group_document_search/search_title_slug"
get :search_by_title, params: @request_params
assert_template "document_collection_group_document_search/search_by_title"
end

view_test "GET #search_title_slug with a query that returns no results renders empty results list" do
view_test "GET #search_by_title with a query that returns no results renders empty results list" do
editions = []
stub_filter = stub_edition_filter({ editions:, options: { per_page: 15 } })
Admin::EditionFilter.stubs(:new).returns(stub_filter)
@request_params[:title] = "Something "

get :search_title_slug, params: @request_params
assert_template "document_collection_group_document_search/search_title_slug"
get :search_by_title, params: @request_params
assert_template "document_collection_group_document_search/search_by_title"
assert_select ".govuk-body", text: /No results found. Search again using the full URL./
end

view_test "GET #search_title_slug with an empty query string shows an alert flash" do
view_test "GET #search_by_title with an empty query string shows an alert flash" do
@request_params[:title] = ""
get :search_title_slug, params: @request_params
assert_template "document_collection_group_document_search/search_title_slug"
get :search_by_title, params: @request_params
assert_template "document_collection_group_document_search/search_by_title"
assert_select ".gem-c-error-alert__message", text: /Please enter a search query/
end

view_test "GET :search_title with search value renders paginated results" do
view_test "GET :search_by_title with search value renders paginated results" do
editions = []
edition = build(:news_article, title: "Something", document: build(:document, slug: "something"))
16.times { editions << edition }
Expand All @@ -86,9 +86,9 @@ class Admin::DocumentCollectionGroupDocumentSearchControllerTest < ActionControl
Admin::EditionFilter.stubs(:new).returns(stub_filter)
@request_params[:title] = "Something "

get :search_title_slug, params: @request_params
get :search_by_title, params: @request_params
assert_response :success
assert_template "document_collection_group_document_search/search_title_slug"
assert_template "document_collection_group_document_search/search_by_title"
assert_select "input[name='title']"
assert_select ".govuk-heading-s", "16 documents"
assert_select ".govuk-table" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Admin::LegacyDocumentCollectionGroupDocumentSearchControllerTest < ActionC
assert_template :forbidden
end

test "GET #search_title_slug blocks out users with no permissions" do
get :search_title_slug, params: @request_params
test "GET #search_title blocks out users with no permissions" do
get :search_title, params: @request_params
assert_template :forbidden
end
end

0 comments on commit bed106b

Please sign in to comment.