FIX: improvements to chat message streaming (#26892)

- prevents re-rendering avatars while updating messages quickly in the thread preview indicator
- ensures the cancel button is shown when you are admin OR when the streamed message is a reply to the current user
This commit is contained in:
Joffrey JAFFEUX
2024-05-07 15:38:24 +02:00
committed by GitHub
parent 42297b2ec3
commit 278eb0a1a5
4 changed files with 82 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { getOwner } from "@ember/application";
import { render } from "@ember/test-helpers";
import { clearRender, render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
@ -58,4 +58,56 @@ module("Discourse Chat | Component | chat-message", function (hooks) {
"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"
);
});
});