DEV: allows category-badge helper to display a link (#17206)

This commit is contained in:
Joffrey JAFFEUX 2022-06-22 18:36:49 +02:00 committed by GitHub
parent 278752fa87
commit 684bc821be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -1,11 +1,12 @@
import { categoryLinkHTML } from "discourse/helpers/category-link";
import { registerUnbound } from "discourse-common/lib/helpers";
import { isPresent } from "@ember/utils";
registerUnbound("category-badge", function (cat, options) {
return categoryLinkHTML(cat, {
hideParent: options.hideParent,
allowUncategorized: options.allowUncategorized,
categoryStyle: options.categoryStyle,
link: false,
link: isPresent(options.link) ? options.link : false,
});
});

View File

@ -0,0 +1,45 @@
import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import {
discourseModule,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile";
import Category from "discourse/models/category";
discourseModule("Integration | Component | category-badge", function (hooks) {
setupRenderingTest(hooks);
componentTest("displays category", {
template: hbs`{{category-badge category}}`,
beforeEach() {
this.set("category", Category.findById(1));
},
async test(assert) {
assert.equal(
query(".category-name").innerText.trim(),
this.category.name
);
},
});
componentTest("options.link", {
template: hbs`{{category-badge category link=true}}`,
beforeEach() {
this.set("category", Category.findById(1));
},
async test(assert) {
assert.ok(
exists(
`a.badge-wrapper[href="/c/${this.category.slug}/${this.category.id}"]`
)
);
},
});
});