diff --git a/assets/javascripts/discourse/controllers/docs-index.js b/assets/javascripts/discourse/controllers/docs-index.js index edf89a3..877abd8 100644 --- a/assets/javascripts/discourse/controllers/docs-index.js +++ b/assets/javascripts/discourse/controllers/docs-index.js @@ -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() diff --git a/test/javascripts/unit/controllers/docs-index-test.js b/test/javascripts/unit/controllers/docs-index-test.js new file mode 100644 index 0000000..fc36b39 --- /dev/null +++ b/test/javascripts/unit/controllers/docs-index-test.js @@ -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"]); + }); +});