FIX: Make `docsCategories` ignore invalid ids (#125)

This commit is contained in:
Jarek Radosz 2023-03-24 11:07:18 +01:00 committed by GitHub
parent 018301d004
commit f4c8e72293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

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

View File

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