diff --git a/app/assets/javascripts/discourse/tests/addons/truth-helpers/integration/helpers/includes-test.js b/app/assets/javascripts/discourse/tests/addons/truth-helpers/integration/helpers/includes-test.js new file mode 100644 index 00000000000..adf2000528d --- /dev/null +++ b/app/assets/javascripts/discourse/tests/addons/truth-helpers/integration/helpers/includes-test.js @@ -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)}}{{/if}}` + ); + + assert.ok(exists(".test"), "it returns true when element is found"); + + this.bar = 2; + await render( + hbs`{{#if (includes foo bar)}}{{/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)}}{{/if}}` + ); + + assert.ok(exists(".test"), "it returns true when element is found"); + + this.bar = "b"; + await render( + hbs`{{#if (includes foo bar)}}{{/if}}` + ); + + assert.notOk(exists(".test"), "it returns false when element is not found"); + }); +}); diff --git a/app/assets/javascripts/truth-helpers/addon/helpers/includes.js b/app/assets/javascripts/truth-helpers/addon/helpers/includes.js new file mode 100644 index 00000000000..d2b0a057c7c --- /dev/null +++ b/app/assets/javascripts/truth-helpers/addon/helpers/includes.js @@ -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);