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/widgets/button-test.js
2021-11-08 10:26:28 +01:00

84 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 | Widget | button", function (hooks) {
setupRenderingTest(hooks);
componentTest("icon only button", {
template: hbs`{{mount-widget widget="button" args=args}}`,
beforeEach() {
this.set("args", { icon: "far-smile" });
},
test(assert) {
assert.ok(
exists("button.btn.btn-icon.no-text"),
"it has all the classes"
);
assert.ok(exists("button .d-icon.d-icon-far-smile"), "it has the icon");
},
});
componentTest("icon and text button", {
template: hbs`{{mount-widget widget="button" args=args}}`,
beforeEach() {
this.set("args", { icon: "plus", label: "topic.create" });
},
test(assert) {
assert.ok(exists("button.btn.btn-icon-text"), "it has all the classes");
assert.ok(exists("button .d-icon.d-icon-plus"), "it has the icon");
assert.ok(exists("button span.d-button-label"), "it has the label");
},
});
componentTest("text only button", {
template: hbs`{{mount-widget widget="button" args=args}}`,
beforeEach() {
this.set("args", { label: "topic.create" });
},
test(assert) {
assert.ok(exists("button.btn.btn-text"), "it has all the classes");
assert.ok(exists("button span.d-button-label"), "it has the label");
},
});
componentTest("translatedLabel", {
template: hbs`{{mount-widget widget="button" args=args}}`,
beforeEach() {
this.set("args", { translatedLabel: "foo bar" });
},
test(assert) {
assert.strictEqual(
query("button span.d-button-label").innerText,
"foo bar"
);
},
});
componentTest("translatedTitle", {
template: hbs`{{mount-widget widget="button" args=args}}`,
beforeEach() {
this.set("args", { label: "topic.create", translatedTitle: "foo bar" });
},
test(assert) {
assert.strictEqual(query("button").title, "foo bar");
},
});
});