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/badge-button-test.js
Joffrey JAFFEUX c8757c9d1d
FIX: prefers computed over discourseComputed (#16562)
We have currently unexpected behaviors when using @discourseComputed in a native class.
2022-04-26 11:43:41 +02:00

106 lines
2.3 KiB
JavaScript

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";
discourseModule("Integration | Component | badge-button", function (hooks) {
setupRenderingTest(hooks);
componentTest("disabled badge", {
template: hbs`{{badge-button badge=badge}}`,
beforeEach() {
this.set("badge", { enabled: false });
},
async test(assert) {
assert.ok(exists(".user-badge.disabled"));
},
});
componentTest("enabled badge", {
template: hbs`{{badge-button badge=badge}}`,
beforeEach() {
this.set("badge", { enabled: true });
},
async test(assert) {
assert.notOk(exists(".user-badge.disabled"));
},
});
componentTest("data-badge-name", {
template: hbs`{{badge-button badge=badge}}`,
beforeEach() {
this.set("badge", { name: "foo" });
},
async test(assert) {
assert.ok(exists('.user-badge[data-badge-name="foo"]'));
},
});
componentTest("title", {
template: hbs`{{badge-button badge=badge}}`,
beforeEach() {
this.set("badge", { description: "a <a href>good</a> run" });
},
async test(assert) {
assert.equal(query(".user-badge").title, "a good run", "it strips html");
this.set("badge", { description: "a bad run" });
assert.equal(
query(".user-badge").title,
"a bad run",
"it updates title when changing description"
);
},
});
componentTest("icon", {
template: hbs`{{badge-button badge=badge}}`,
beforeEach() {
this.set("badge", { icon: "times" });
},
async test(assert) {
assert.ok(exists(".d-icon.d-icon-times"));
},
});
componentTest("accepts block", {
template: hbs`{{#badge-button badge=badge}}<span class="test"></span>{{/badge-button}}`,
beforeEach() {
this.set("badge", {});
},
async test(assert) {
assert.ok(exists(".test"));
},
});
componentTest("badgeTypeClassName", {
template: hbs`{{badge-button badge=badge}}`,
beforeEach() {
this.set("badge", { badgeTypeClassName: "foo" });
},
async test(assert) {
assert.ok(exists(".user-badge.foo"));
},
});
});