DEV: allows category-badge helper to display a link (#17206)
This commit is contained in:
parent
278752fa87
commit
684bc821be
|
@ -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,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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}"]`
|
||||
)
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue