A platform for community discussion. Free, open, simple.
FIX: ensures category url of category drop is built using slug and id (#9069)
Joffrey JAFFEUX2db8ada22233
diff --git a/app/assets/javascripts/select-kit/components/category-drop.js.es6 b/app/assets/javascripts/select-kit/components/category-drop.js.es6index b5dcb7162a9..5ee9a6d12b9 100644--- a/app/assets/javascripts/select-kit/components/category-drop.js.es6+++ b/app/assets/javascripts/select-kit/components/category-drop.js.es6@@ -155,18 +155,16 @@ export default ComboBoxComponent.extend({},actions: {- onChange(value) {+ onChange(categoryId) {let categoryURL;- if (value === ALL_CATEGORIES_ID) {+ if (categoryId === ALL_CATEGORIES_ID) {categoryURL = this.allCategoriesUrl;- } else if (value === NO_CATEGORIES_ID) {+ } else if (categoryId === NO_CATEGORIES_ID) {categoryURL = this.noCategoriesUrl;} else {- const categoryId = parseInt(value, 10);- const category = Category.findById(categoryId);- const slug = Discourse.Category.slugFor(category);- categoryURL = `/c/${slug}`;+ const category = Category.findById(parseInt(categoryId, 10));+ categoryURL = category.url;}DiscourseURL.routeToUrl(categoryURL);diff --git a/test/javascripts/components/select-kit/category-drop-test.js.es6 b/test/javascripts/components/select-kit/category-drop-test.js.es6index e44b8d24a7e..2a3b7b6e562 100644--- a/test/javascripts/components/select-kit/category-drop-test.js.es6+++ b/test/javascripts/components/select-kit/category-drop-test.js.es6@@ -1,3 +1,4 @@+import DiscourseURL from "discourse/lib/url";import Category from "discourse/models/category";import componentTest from "helpers/component-test";import { testSelectKitModule } from "./select-kit-test-helper";@@ -335,3 +336,22 @@ componentTest(}});++componentTest("category url", {+ template: template(),++ beforeEach() {+ initCategoriesWithParentCategory(this);+ sandbox.stub(DiscourseURL, "routeTo");+ },++ async test(assert) {+ await this.subject.expand();+ await this.subject.selectRowByValue(26);++ assert.ok(+ DiscourseURL.routeTo.calledWith("/c/feature/spec/26"),+ "it builds a correct URL"+ );+ }+});