FIX: ensures category url of category drop is built using slug and id (#9069)
This commit is contained in:
parent
ff5ff8d0d2
commit
2db8ada222
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue