FIX: ensures category url of category drop is built using slug and id (#9069)

This commit is contained in:
Joffrey JAFFEUX 2020-02-28 17:58:22 +01:00 committed by GitHub
parent ff5ff8d0d2
commit 2db8ada222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -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);

View File

@ -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"
);
}
});