DEV: adds includes helper to templates (#18259)

Usage :

```
{{#if (includes fooArray foo)}}
```

```
{{#if (includes fooString foo)}}
```
This commit is contained in:
Joffrey JAFFEUX 2022-09-15 14:20:37 +02:00 committed by GitHub
parent e567eeb927
commit 1a2bf52656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View File

@ -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");
});
});

View File

@ -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);