discourse/plugins/chat/test/javascripts/acceptance/chat-message-retry-test.js
Jarek Radosz c63f9cca90
DEV: Remove obsolete chat code and tests (#39451)
I believe the unreliable-network UI was removed in #19531.

The test cases are all covered by system specs now, with the exception
of message sending retry - this one is redone here.
2026-04-22 21:33:17 +02:00

66 lines
1.9 KiB
JavaScript

import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
const CHANNEL_ID = 11;
acceptance("Retry message on send failure", function (needs) {
needs.user({ has_chat_enabled: true });
needs.settings({ chat_enabled: true });
let sendAttempt;
needs.hooks.beforeEach(function () {
sendAttempt = 0;
pretender.get("/chat/api/me/channels", () =>
response({
direct_message_channels: [],
public_channels: [
{
id: CHANNEL_ID,
title: "My channel",
chatable_type: "Category",
meta: { message_bus_last_ids: {} },
current_user_membership: { following: true },
chatable: { color: "ff0000" },
},
],
meta: { message_bus_last_ids: {} },
tracking: {},
})
);
pretender.get(`/chat/api/channels/${CHANNEL_ID}/messages`, () =>
response({ messages: [], meta: {} })
);
pretender.post(`/chat/api/channels/${CHANNEL_ID}/drafts`, () =>
response({})
);
pretender.post(`/chat/${CHANNEL_ID}`, () => {
sendAttempt += 1;
return sendAttempt === 1
? response(500, {})
: response({ success: "OK" });
});
});
test("shows a retry button when sending fails and resends on click", async function (assert) {
await visit(`/chat/c/-/${CHANNEL_ID}`);
await fillIn(".chat-composer__input", "hello there");
await click(".chat-composer .-send");
assert
.dom(".chat-message-error__retry-btn")
.exists("shows the retry button after a network error");
await click(".chat-message-error__retry-btn");
assert
.dom(".chat-message-error__retry-btn")
.doesNotExist("clears the retry button after a successful resend");
});
});