-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3604 from alphagov/show-autocomplete-on-search
Add autocomplete to search index
- Loading branch information
Showing
6 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "spec_helper" | ||
require "gds_api/test_helpers/content_store" | ||
|
||
describe SearchController, type: :controller do | ||
include GdsApi::TestHelpers::ContentStore | ||
|
||
before do | ||
stub_content_store_has_item("/search") | ||
end | ||
|
||
describe "GET index" do | ||
render_views | ||
|
||
it "renders the search page" do | ||
get :index | ||
expect(response.status).to eq(200) | ||
expect(response).to render_template("search/no_search_term") | ||
end | ||
|
||
context "when given search parameters" do | ||
it "redirects to the all content finder" do | ||
get :index, params: { q: "my search" } | ||
|
||
destination = finder_path("search/all", | ||
params: { keywords: "my search", order: "relevance" }) | ||
expect(response).to redirect_to(destination) | ||
end | ||
end | ||
|
||
context "when JSON is requested" do | ||
it "redirects to the all content finder" do | ||
get :index, format: :json | ||
|
||
destination = finder_path("search/all", | ||
params: { order: "relevance", format: "json" }) | ||
expect(response).to redirect_to(destination) | ||
end | ||
end | ||
|
||
context "when GOVUK_DISABLE_SEARCH_AUTOCOMPLETE is not set" do | ||
it "renders the search autocomplete component" do | ||
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: nil do | ||
get :index | ||
|
||
expect(response.body).to include("gem-c-search-with-autocomplete") | ||
end | ||
end | ||
end | ||
|
||
context "when GOVUK_DISABLE_SEARCH_AUTOCOMPLETE is set" do | ||
it "renders the search component instead of the autocomplete component" do | ||
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: "1" do | ||
get :index | ||
|
||
expect(response.body).not_to include("gem-c-search-with-autocomplete") | ||
expect(response.body).to include("gem-c-search") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe ApplicationHelper, type: :helper do | ||
describe "#search_component" do | ||
context "when ENV['GOVUK_DISABLE_SEARCH_AUTOCOMPLETE'] is not set" do | ||
it "returns 'search_with_autocomplete'" do | ||
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: nil do | ||
expect(helper.search_component).to eq("search_with_autocomplete") | ||
end | ||
end | ||
end | ||
|
||
context "when ENV['GOVUK_DISABLE_SEARCH_AUTOCOMPLETE'] is set" do | ||
it "returns 'search'" do | ||
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: "1" do | ||
expect(helper.search_component).to eq("search") | ||
end | ||
end | ||
end | ||
end | ||
end |