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 54812992ae
REFACTOR: badge-button (#16500)
- drops jquery
- uses native class syntax
- tagless
- tests
- removes unnecessary alias
2022-04-19 15:01:28 +02:00

98 lines
2.1 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");
},
});
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"));
},
});
});