FIX: Transitioning to tag-intersection route (#23931)

…didn't correctly update location query params.

A followup to 1df3ccc903 (things broke after merging `main` to PR's branch)
This commit is contained in:
Jarek Radosz 2023-10-13 17:23:04 +02:00 committed by GitHub
parent b3df0a362b
commit a5858e60e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 21 deletions

View File

@ -2,12 +2,5 @@ import { queryParams } from "discourse/controllers/discovery-sortable";
import TagShowController from "discourse/controllers/tag-show";
export default class TagsIntersectionController extends TagShowController {
constructor() {
super(...arguments);
this.set("queryParams", [
...Object.keys(queryParams),
{ categoryParam: "category" },
]);
}
queryParams = [...Object.keys(queryParams), { categoryParam: "category" }];
}

View File

@ -1,4 +1,3 @@
import { queryParams } from "discourse/controllers/discovery-sortable";
import { buildTagRoute } from "discourse/routes/tag-show";
// The tags-intersection route is exactly the same as the tags-show route, but the wildcard at the
@ -6,15 +5,6 @@ import { buildTagRoute } from "discourse/routes/tag-show";
// breaking all other tags-show routes. Ember thinks the query params are addition tags and should
// be handled by the intersection logic. Defining tags-intersection as something separate avoids
// that confusion.
export default buildTagRoute().extend({
controllerName: "tags.intersection",
init() {
this._super(...arguments);
// The only difference is support for `category` query param.
// Other routes include category in the route path.
this.set("queryParams", { ...queryParams });
this.queryParams["categoryParam"] = { replace: true, refreshModel: true };
},
});
export default class extends buildTagRoute() {
controllerName = "tags.intersection";
}

View File

@ -0,0 +1,34 @@
# frozen_string_literal: true
describe "Tags intersection", type: :system do
let(:discovery) { PageObjects::Pages::Discovery.new }
fab!(:category) { Fabricate(:category, name: "fruits") }
fab!(:some_topic) { Fabricate(:topic, category: category) }
fab!(:tag) { Fabricate(:tag, name: "sour") }
fab!(:tag2) { Fabricate(:tag, name: "tangy") }
fab!(:some_topic) { Fabricate(:topic, tags: [tag, tag2]) }
fab!(:the_topic) { Fabricate(:topic, category: category, tags: [tag, tag2]) }
it "filters by category" do
visit("/tags/intersection/sour/tangy?category=fruits")
expect(page).to have_current_path("/tags/intersection/sour/tangy?category=fruits")
expect(discovery.topic_list).to have_topic(the_topic)
expect(discovery.topic_list).to have_topics(count: 1)
visit("/")
# Confirm that frontend transitions work as well,
# even though UI doesn't support that
page.execute_script <<~JS
require("discourse/lib/url").default.routeTo("/tags/intersection/sour/tangy?category=fruits")
JS
expect(page).to have_current_path("/tags/intersection/sour/tangy?category=fruits")
expect(discovery.topic_list).to have_topic(the_topic)
expect(discovery.topic_list).to have_topics(count: 1)
end
end