This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/components/sidebar/section-link-test.js
Krzysztof Kotlarek f2476d4b80
FIX: class for section link when name has space (#20569)
Sidebar section link has class name based on link title. Title can contain spaces, therefore they should be replaced.
2023-03-08 12:07:03 +11:00

73 lines
2.1 KiB
JavaScript

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";
function containsExactly(assert, expectation, actual, message) {
assert.deepEqual(
Array.from(expectation).sort(),
Array.from(actual).sort(),
message
);
}
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 Meta" @route="discovery.latest" />`;
await render(template);
containsExactly(
assert,
query("a").classList,
[
"ember-view",
"sidebar-row",
"sidebar-section-link",
"sidebar-section-link-test-meta",
],
"has the right class attribute for the link"
);
});
test("custom class attribute for link", async function (assert) {
const template = hbs`<Sidebar::SectionLink @linkName="Test Meta" @route="discovery.latest" @class="123 abc" />`;
await render(template);
containsExactly(
assert,
query("a").classList,
[
"123",
"abc",
"ember-view",
"sidebar-row",
"sidebar-section-link",
"sidebar-section-link-test-meta",
],
"has the right class attribute for the link"
);
});
test("target attribute for link", async function (assert) {
const template = hbs`<Sidebar::SectionLink @linkName="test" @href="https://discourse.org" />`;
await render(template);
assert.strictEqual(query("a").target, "_self");
});
test("target attribute for link when user set external links in new tab", async function (assert) {
this.currentUser.user_option.external_links_in_new_tab = true;
const template = hbs`<Sidebar::SectionLink @linkName="test" @href="https://discourse.org" />`;
await render(template);
assert.strictEqual(query("a").target, "_blank");
});
});