reflect search query in page title (#15434)

This commit is contained in:
Suzanne Aitchison 2021-11-22 13:32:28 +00:00 committed by GitHub
parent 50f8cb21fc
commit e5cda63391
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View file

@ -1,4 +1,5 @@
<% title t("views.search.meta.title") %>
<% title t("views.search.meta.title", for: (params[:q].present? ? t("views.search.meta.for", query: params[:q]) : "")) %>
<link rel="canonical" href="<%= app_url(search_path) %>" />
<meta name="description" content="<%= Settings::Community.community_description %>">
<%= meta_keywords_default %>

View file

@ -85,7 +85,8 @@ en:
newest: Newest
oldest: Oldest
meta:
title: Search Results
title: Search Results%{for}
for: " for %{query}"
description: "%{site} => Search Results"
series:
meta:

View file

@ -85,7 +85,8 @@ fr:
newest: Newest
oldest: Oldest
meta:
title: Search Results
title: Search Results%{for}
for: " for %{query}"
description: "%{site} => Search Results"
series:
meta:

View file

@ -0,0 +1,27 @@
require "rails_helper"
RSpec.describe "Search page title", type: :system do
let!(:current_user) { create(:user) }
before do
sign_in current_user
end
context "when search query param exists" do
it "includes the search term in title and heading" do
visit "/search?q=helloworld"
expect(page).to have_title("Search Results for helloworld - DEV(local)")
expect(page.find("h1")).to have_content("Search results for helloworld")
end
end
context "when search query param doesn't exist" do
it "does not include search term in title and heading" do
visit "/search"
expect(page).to have_title("Search Results - DEV(local)")
expect(page.find("h1")).to have_content("Search results")
end
end
end