FIX: Make `docsCategories` ignore invalid ids (#125)
This commit is contained in:
parent
018301d004
commit
f4c8e72293
|
@ -229,10 +229,10 @@ export default Controller.extend({
|
|||
return [];
|
||||
}
|
||||
|
||||
return this.siteSettings.docs_categories.split("|").map((c) => {
|
||||
const id = parseInt(c, 10);
|
||||
return this.site.categories.findBy("id", id).name;
|
||||
});
|
||||
return this.siteSettings.docs_categories
|
||||
.split("|")
|
||||
.map((c) => this.site.categories.findBy("id", parseInt(c, 10))?.name)
|
||||
.filter(Boolean);
|
||||
},
|
||||
|
||||
@discourseComputed()
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { module, test } from "qunit";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { getOwner } from "discourse-common/lib/get-owner";
|
||||
|
||||
module("Unit | Controller | docs-index", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test("docsCategories ignores invalid category ids", function (assert) {
|
||||
const siteSettings = getOwner(this).lookup("service:site-settings");
|
||||
siteSettings.docs_categories = "1|2|3|333|999";
|
||||
|
||||
const controller = getOwner(this).lookup("controller:docs-index");
|
||||
assert.deepEqual(controller.docsCategories, ["bug", "feature", "meta"]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue