2022-12-22 08:35:18 -05:00
|
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
|
import { click, render } from "@ember/test-helpers";
|
2022-11-02 09:41:30 -04:00
|
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2022-12-22 08:35:18 -05:00
|
|
|
|
import { module, test } from "qunit";
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-message-reaction", function (hooks) {
|
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
test("adds reacted class when user reacted", async function (assert) {
|
|
|
|
|
await render(hbs`
|
|
|
|
|
<ChatMessageReaction @reaction={{hash emoji="heart" reacted=true}} />
|
|
|
|
|
`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
assert.true(exists(".chat-message-reaction.reacted"));
|
2022-11-02 09:41:30 -04:00
|
|
|
|
});
|
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
test("adds reaction name as class", async function (assert) {
|
|
|
|
|
await render(hbs`<ChatMessageReaction @reaction={{hash emoji="heart"}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
assert.true(exists(`.chat-message-reaction[data-emoji-name="heart"]`));
|
2022-11-02 09:41:30 -04:00
|
|
|
|
});
|
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
test("title/alt attributes", async function (assert) {
|
|
|
|
|
await render(hbs`<ChatMessageReaction @reaction={{hash emoji="heart"}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
assert.strictEqual(query(".chat-message-reaction").title, ":heart:");
|
|
|
|
|
assert.strictEqual(query(".chat-message-reaction img").alt, ":heart:");
|
2022-11-02 09:41:30 -04:00
|
|
|
|
});
|
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
test("count of reactions", async function (assert) {
|
|
|
|
|
this.set("count", 0);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
await render(hbs`
|
|
|
|
|
<ChatMessageReaction @reaction={{hash emoji="heart" count=this.count}} />
|
|
|
|
|
`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
assert.false(exists(".chat-message-reaction .count"));
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
this.set("count", 2);
|
|
|
|
|
assert.strictEqual(query(".chat-message-reaction .count").innerText, "2");
|
2022-11-02 09:41:30 -04:00
|
|
|
|
});
|
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
test("reaction’s image", async function (assert) {
|
|
|
|
|
await render(hbs`<ChatMessageReaction @reaction={{hash emoji="heart"}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
const src = query(".chat-message-reaction img").src;
|
|
|
|
|
assert.true(/heart\.png/.test(src));
|
2022-11-02 09:41:30 -04:00
|
|
|
|
});
|
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
test("click action", async function (assert) {
|
|
|
|
|
this.set("count", 0);
|
|
|
|
|
this.set("react", () => {
|
|
|
|
|
this.set("count", 1);
|
|
|
|
|
});
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
await render(hbs`
|
|
|
|
|
<ChatMessageReaction class="show" @reaction={{hash emoji="heart" count=this.count}} @react={{this.react}} />
|
|
|
|
|
`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
assert.false(exists(".chat-message-reaction .count"));
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
|
await click(".chat-message-reaction");
|
|
|
|
|
assert.strictEqual(query(".chat-message-reaction .count").innerText, "1");
|
2022-11-02 09:41:30 -04:00
|
|
|
|
});
|
|
|
|
|
});
|