2022-11-02 09:41:30 -04:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { render, waitUntil } from "@ember/test-helpers";
|
|
|
|
import { module, test } from "qunit";
|
|
|
|
|
|
|
|
module("Discourse Chat | Component | on-visibility-action", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
test("Calling an action on visibility gained", async function (assert) {
|
|
|
|
this.set("value", null);
|
|
|
|
this.set("display", false);
|
|
|
|
this.set("action", () => {
|
|
|
|
this.set("value", "foo");
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set("root", document.querySelector("#ember-testing"));
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`
|
|
|
|
{{#if display}}
|
|
|
|
<OnVisibilityAction @action={{this.action}} @root={{this.root}} />
|
|
|
|
{{/if}}
|
|
|
|
`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.strictEqual(this.value, null);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
|
|
this.set("display", true);
|
|
|
|
await waitUntil(() => this.value !== null);
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.strictEqual(this.value, "foo");
|
2022-11-02 09:41:30 -04:00
|
|
|
});
|
|
|
|
});
|