DEV: Remove undefined in Sidebar::SectionLink class attribute (#17881)

This commit is contained in:
Alan Guo Xiang Tan 2022-08-12 12:12:39 +08:00 committed by GitHub
parent 68cefc9f9d
commit b653b86806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -9,7 +9,16 @@ export default class SectionLink extends Component {
} }
get classNames() { get classNames() {
return `${this.args.class} sidebar-section-link sidebar-section-link-${this.args.linkName}`; let classNames = [
"sidebar-section-link",
`sidebar-section-link-${this.args.linkName}`,
];
if (this.args.class) {
classNames.push(this.args.class);
}
return classNames.join(" ");
} }
get models() { get models() {

View File

@ -0,0 +1,35 @@
import { module, test } from "qunit";
import { hbs } from "ember-cli-htmlbars";
import { render } from "@ember/test-helpers";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Component | sidebar | section-link", function (hooks) {
setupRenderingTest(hooks);
test("default class attribute for link", async function (assert) {
const template = hbs`<Sidebar::SectionLink @linkName="test" @route="discovery.latest" />`;
await render(template);
assert.strictEqual(
query("a").className,
"sidebar-section-link sidebar-section-link-test ember-view",
"has the right class attribute for the link"
);
});
test("custom class attribute for link", async function (assert) {
const template = hbs`<Sidebar::SectionLink @linkName="test" @route="discovery.latest" @class="123 abc" />`;
await render(template);
assert.strictEqual(
query("a").className,
"sidebar-section-link sidebar-section-link-test 123 abc ember-view",
"has the right class attribute for the link"
);
});
});