DEV: adds includes helper to templates (#18259)
Usage : ``` {{#if (includes fooArray foo)}} ``` ``` {{#if (includes fooString foo)}} ```
This commit is contained in:
parent
e567eeb927
commit
1a2bf52656
|
@ -0,0 +1,43 @@
|
|||
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 { exists } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
module("Addons | truth-helpers | Integration | includes", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("when using an array", async function () {
|
||||
this.foo = [1];
|
||||
this.bar = 1;
|
||||
await render(
|
||||
hbs`{{#if (includes foo bar)}}<span class="test"></span>{{/if}}`
|
||||
);
|
||||
|
||||
assert.ok(exists(".test"), "it returns true when element is found");
|
||||
|
||||
this.bar = 2;
|
||||
await render(
|
||||
hbs`{{#if (includes foo bar)}}<span class="test"></span>{{/if}}`
|
||||
);
|
||||
|
||||
assert.notOk(exists(".test"), "it returns false when element is not found");
|
||||
});
|
||||
|
||||
test("when using a string", async function () {
|
||||
this.foo = "foo";
|
||||
this.bar = "f";
|
||||
await render(
|
||||
hbs`{{#if (includes foo bar)}}<span class="test"></span>{{/if}}`
|
||||
);
|
||||
|
||||
assert.ok(exists(".test"), "it returns true when element is found");
|
||||
|
||||
this.bar = "b";
|
||||
await render(
|
||||
hbs`{{#if (includes foo bar)}}<span class="test"></span>{{/if}}`
|
||||
);
|
||||
|
||||
assert.notOk(exists(".test"), "it returns false when element is not found");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
import Helper from "@ember/component/helper";
|
||||
|
||||
export function includes(params) {
|
||||
return params[0].includes(params[1]);
|
||||
}
|
||||
|
||||
export default Helper.helper(includes);
|
Loading…
Reference in New Issue