2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/spec/system/discovery_breadcrumb_navigation_spec.rb
Natalie Tay 737577e8b4
DEV: Move canonical tag routes to /tag/slug/id keeping /tag/name support (#37055)
Switches tag URLs from name-based (`/tag/my-tag`) to slug+id-based
(`/tag/my-tag/123`), making tag references stable across renames and
enabling translated tag names.

  | Type | Before | After |
  |------|--------|-------|
  | Browser | `/tag/my-tag` | `/tag/my-tag/123` |
  | Browser | `/tag/my-tag/l/latest` | `/tag/my-tag/123/l/latest` |
  | API | `/tag/my-tag.json` | `/tag/123.json` |

- Old `/tag/:name` URLs still work
- Browser requests get 301 redirected to canonical URLs
- API (JSON) requests return data without redirect
-  Untagged (`/tag/none`) and intersection routes remain unchanged.


Depends on https://github.com/discourse/discourse/pull/36678

---------

Co-authored-by: Krzysztof Kotlarek <kotlarek.krzysztof@gmail.com>
2026-02-11 10:21:19 +08:00

110 lines
4.6 KiB
Ruby

# frozen_string_literal: true
describe "Navigating with breadcrumbs", type: :system do
let(:discovery) { PageObjects::Pages::Discovery.new }
fab!(:category1, :category)
fab!(:c1_topic) { Fabricate(:topic, category: category1) }
fab!(:category2, :category)
fab!(:c2_topic) { Fabricate(:topic, category: category2) }
fab!(:category2_child) { Fabricate(:category, parent_category: category2) }
fab!(:c2_child_topic) { Fabricate(:topic, category: category2_child) }
fab!(:category3) { Fabricate(:category, default_list_filter: "none") }
fab!(:c3_topic) { Fabricate(:topic, category: category3) }
fab!(:category3_child) { Fabricate(:category, parent_category: category3) }
fab!(:c3_child_topic) { Fabricate(:topic, category: category3_child) }
it "can navigate between categories" do
visit("/c/#{category1.id}")
expect(page).to have_current_path("/c/#{category1.slug}/#{category1.id}")
expect(discovery.topic_list).to have_topic(c1_topic)
expect(discovery.topic_list).to have_topics(count: 1)
expect(discovery.category_drop).to have_selected_value(category1.id)
discovery.category_drop.select_row_by_value(category2.id)
expect(page).to have_current_path("/c/#{category2.slug}/#{category2.id}")
expect(discovery.topic_list).to have_topic(c2_topic)
expect(discovery.topic_list).to have_topic(c2_child_topic)
expect(discovery.topic_list).to have_topics(count: 2)
# When using breadcrumbs for navigation, default_list_filter does not apply
discovery.category_drop.select_row_by_value(category3.id)
expect(discovery.topic_list).to have_topic(c3_topic)
expect(discovery.topic_list).to have_topic(c3_child_topic)
expect(discovery.topic_list).to have_topics(count: 2)
expect(discovery.subcategory_drop).to have_selected_value("") # all
discovery.subcategory_drop.select_row_by_value("no-categories")
expect(discovery.topic_list).to have_topic(c3_topic)
expect(discovery.topic_list).to have_topics(count: 1)
discovery.subcategory_drop.select_row_by_value(category3_child.id)
expect(discovery.topic_list).to have_topic(c3_child_topic)
expect(discovery.topic_list).to have_topics(count: 1)
end
context "with tags" do
fab!(:tag)
fab!(:c1_topic_tagged) { Fabricate(:topic, category: category1, tags: [tag]) }
fab!(:c3_topic_tagged) { Fabricate(:topic, category: category3, tags: [tag]) }
fab!(:c3_child_topic_tagged) { Fabricate(:topic, category: category3_child, tags: [tag]) }
it "can filter by tags" do
visit("/c/#{category1.id}")
expect(page).to have_current_path("/c/#{category1.slug}/#{category1.id}")
expect(discovery.topic_list).to have_topic(c1_topic)
expect(discovery.topic_list).to have_topic(c1_topic_tagged)
expect(discovery.topic_list).to have_topics(count: 2)
expect(discovery.tag_drop).to have_selected_name("tags")
discovery.tag_drop.select_row_by_name(tag.name)
expect(discovery.topic_list).to have_topics(count: 1)
expect(discovery.topic_list).to have_topic(c1_topic_tagged)
end
it "maintains no-subcategories option" do
visit("/c/#{category3.slug}/#{category3.id}/none")
expect(discovery.topic_list).to have_topic(c3_topic)
expect(discovery.topic_list).to have_topic(c3_topic_tagged)
expect(discovery.topic_list).to have_topics(count: 2)
expect(discovery.subcategory_drop).to have_selected_name("no subcategories")
expect(discovery.tag_drop).to have_selected_name("tags")
discovery.tag_drop.select_row_by_name(tag.name)
expect(page).to have_current_path(
"/tags/c/#{category3.slug}/#{category3.id}/none/#{tag.slug}/#{tag.id}",
)
expect(discovery.topic_list).to have_topics(count: 1)
expect(discovery.topic_list).to have_topic(c3_topic_tagged)
end
end
describe "initial page loads for no-subcategories" do
it "shows correct data for /c/" do
visit("/c/#{category3.id}")
expect(page).to have_current_path("/c/#{category3.slug}/#{category3.id}/none")
expect(discovery.topic_list).to have_topic(c3_topic)
expect(discovery.topic_list).to have_topics(count: 1)
end
it "shows correct data for /tags/c/" do
tag = Fabricate(:tag)
c3_topic.update!(tags: [tag])
c3_child_topic.update!(tags: [tag])
visit("/tags/c/#{category3.slug}/#{category3.id}/#{tag.name}/#{tag.id}")
expect(page).to have_current_path(
"/tags/c/#{category3.slug}/#{category3.id}/none/#{tag.slug}/#{tag.id}",
)
expect(discovery.topic_list).to have_topic(c3_topic)
expect(discovery.topic_list).to have_topics(count: 1)
end
end
end