2022-12-22 21:35:18 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import { click, render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { exists, visible } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import { module, test } from "qunit";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { htmlSafe } from "@ember/template";
|
|
|
|
|
|
|
|
module("Discourse Chat | Component | collapser", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("renders header", async function (assert) {
|
|
|
|
this.set("header", htmlSafe(`<div class="cat">tomtom</div>`));
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<Collapser @header={{this.header}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.true(exists(".cat"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("collapses and expands yielded body", async function (assert) {
|
|
|
|
await render(hbs`
|
|
|
|
<Collapser>
|
|
|
|
<div class="cat">body text</div>
|
|
|
|
</Collapser>
|
|
|
|
`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
const openButton = ".chat-message-collapser-closed";
|
|
|
|
const closeButton = ".chat-message-collapser-opened";
|
|
|
|
const body = ".cat";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.true(visible(body));
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await click(closeButton);
|
|
|
|
assert.false(visible(body));
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await click(openButton);
|
|
|
|
assert.true(visible(body));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
});
|