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