Use the canonical URLs to link from sorted pages (#16928)

Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
This commit is contained in:
Takuya N 2022-03-22 23:51:36 +09:00 committed by GitHub
parent 56f576c4f2
commit 26e10fc71e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 3 deletions

View file

@ -43,7 +43,7 @@
<nav class="-mx-3 m:mx-0 s:flex items-center justify-between" aria-label="<%= t("views.stories.sort.aria_label") %>">
<ul class="crayons-navigation crayons-navigation--horizontal">
<li>
<a data-text="<%= t("views.stories.sort.relevant") %>" href="<%= list_path %>/" class="crayons-navigation__item <%= "crayons-navigation__item--current" if %w[week month year infinity latest].exclude?(params[:timeframe]) %>"
<a data-text="<%= t("views.stories.sort.relevant") %>" href="<%= list_path.presence || "/" %>" class="crayons-navigation__item <%= "crayons-navigation__item--current" if %w[week month year infinity latest].exclude?(params[:timeframe]) %>"
<%= %w[week month year infinity latest].exclude?(params[:timeframe]) ? ' aria-current="page"'.html_safe : "" %>><%= t("views.stories.sort.relevant") %></a>
</li>
<li>

View file

@ -61,7 +61,7 @@
<nav class="-mx-3 m:mx-0 s:flex items-center justify-between w-100" aria-label="<%= t("views.stories.sort.aria_tagged") %>">
<ul class="crayons-navigation crayons-navigation--horizontal">
<li>
<a data-text="<%= t("views.stories.sort.relevant") %>" href="<%= list_path %>/" class="crayons-navigation__item <%= "crayons-navigation__item--current" if %w[week month year infinity latest].exclude?(params[:timeframe]) %>"
<a data-text="<%= t("views.stories.sort.relevant") %>" href="<%= list_path %>" class="crayons-navigation__item <%= "crayons-navigation__item--current" if %w[week month year infinity latest].exclude?(params[:timeframe]) %>"
<%= %w[week month year infinity latest].exclude?(params[:timeframe]) ? ' aria-current="page"'.html_safe : "" %>><%= t("views.stories.sort.relevant") %></a>
</li>
<li>

View file

@ -172,6 +172,14 @@ RSpec.describe "Stories::TaggedArticlesIndex", type: :request do
get "/t/#{tag.name}"
expect(response.body).not_to include('<span class="olderposts-pagenumber">')
end
it "includes a link to Relevant", :aggregate_failures do
get "/t/#{tag.name}/latest"
# The link should be `/t/tag2` (without a trailing slash) instead of `/t/tag2/`
expected_tag = "<a data-text=\"Relevant\" href=\"/t/#{tag.name}\""
expect(response.body).to include(expected_tag)
end
end
context "without user signed in" do

View file

@ -304,6 +304,28 @@ RSpec.describe "StoriesIndex", type: :request do
end
end
describe "GET stories index with timeframe" do
describe "/latest" do
it "includes a link to Relevant", :aggregate_failures do
get "/latest"
# The link should be `/`
expected_tag = "<a data-text=\"Relevant\" href=\"/\""
expect(response.body).to include(expected_tag)
end
end
describe "/top/week" do
it "includes a link to Relevant", :aggregate_failures do
get "/top/week"
# The link should be `/`
expected_tag = "<a data-text=\"Relevant\" href=\"/\""
expect(response.body).to include(expected_tag)
end
end
end
describe "GET locale index" do
it "names proper locale" do
get "/locale/fr"

View file

@ -70,7 +70,7 @@ RSpec.describe "User visits articles by tag", type: :system do
it "shows top level sort options" do
within("#on-page-nav-controls") do
expect(page).to have_link("Relevant", href: "/t/functional/")
expect(page).to have_link("Relevant", href: "/t/functional")
expect(page).to have_link("Top", href: "/t/functional/top/week")
expect(page).to have_link("Latest", href: "/t/functional/latest")
end