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/helpers/concat-class-test.js
Joffrey JAFFEUX 0760b249ff
DEV: introduces {{concat-class}} helper (#17526)
Usage:

```
<button class={{concat-class "foo" this.bar (if true "baz")}} />
```
2022-07-16 14:09:54 +02:00

45 lines
1.4 KiB
JavaScript

import { assert, module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { query } from "discourse/tests/helpers/qunit-helpers";
module("Integration | Helper | concat-class", function (hooks) {
setupRenderingTest(hooks);
test("One class given", async function () {
await render(hbs`<button class={{concat-class "foo"}} />`);
assert.equal(query("button").className, "foo");
});
test("Multiple class given", async function () {
this.set("bar", "bar");
await render(hbs`<button class={{concat-class "foo" this.bar}} />`);
assert.equal(query("button").className, "foo bar");
});
test("One undefined class given", async function () {
this.set("bar", null);
await render(hbs`<button class={{concat-class "foo" this.bar}} />`);
assert.equal(query("button").className, "foo");
});
test("Only undefined class given", async function () {
this.set("bar", null);
await render(hbs`<button class={{concat-class null this.bar}} />`);
assert.notOk(query("button").hasAttribute("class"));
});
test("Helpers used", async function () {
await render(
hbs`<button class={{concat-class (if true "foo") (if true "bar")}} />`
);
assert.equal(query("button").className, "foo bar");
});
});