import { getOwner } from "@ember/owner";
import { clearRender, render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import CoreFabricators from "discourse/lib/fabricators";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-message", function (hooks) {
setupRenderingTest(hooks);
const template = hbs`
what test
"); }); test("Message with reply", async function (assert) { this.message = new ChatFabricators(getOwner(this)).message({ inReplyTo: new ChatFabricators(getOwner(this)).message(), }); await render(template); assert .dom(".chat-message-container.has-reply") .exists("has the correct css class"); }); test("Message with streaming", async function (assert) { // admin this.currentUser.admin = true; this.message = new ChatFabricators(getOwner(this)).message({ inReplyTo: new ChatFabricators(getOwner(this)).message(), streaming: true, }); await this.message.cook(); await render(template); assert .dom(".stop-streaming-btn") .exists("when admin, it has the stop streaming button"); await clearRender(); // not admin - not replying to current user this.currentUser.admin = false; this.message = new ChatFabricators(getOwner(this)).message({ inReplyTo: new ChatFabricators(getOwner(this)).message(), streaming: true, }); await this.message.cook(); await render(template); assert .dom(".stop-streaming-btn") .doesNotExist("when admin, it doesn't have the stop streaming button"); await clearRender(); // not admin - replying to current user this.currentUser.admin = false; this.message = new ChatFabricators(getOwner(this)).message({ inReplyTo: new ChatFabricators(getOwner(this)).message({ user: this.currentUser, }), streaming: true, }); await this.message.cook(); await render(template); assert .dom(".stop-streaming-btn") .exists( "when replying to current user, it has the stop streaming button" ); }); });