Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/tests/e2e/chat-interim.smoke.spec.ts
T

96 lines
5.3 KiB
TypeScript

// AK-P15b interim-UI smoke (AD-28): log in, open the dedicated private
// readiness channel, send through the live WebSocket gateway, then reload and
// prove that the acknowledged message was persisted by the server.
import { getTenantCredentials, loginAsTenantUser } from "./utils/auth";
import { skipIfUnavailable, waitForHydration } from "./utils/navigation";
import { skipOrFailWhenE2eInputsMissing, skipOrFailWhenE2eOptInMissing } from "./utils/readiness";
import { expect, test } from "./utils/test";
const credentials = getTenantCredentials();
const peerCredentials =
process.env.E2E_PLUGIN_READONLY_EMAIL && process.env.E2E_PLUGIN_READONLY_PASSWORD
? { email: process.env.E2E_PLUGIN_READONLY_EMAIL, password: process.env.E2E_PLUGIN_READONLY_PASSWORD }
: null;
const chatPath = process.env.E2E_TENANT_CHAT_PATH;
test.describe("AK-P15b team chat interim smoke", () => {
test.beforeEach(() => {
skipOrFailWhenE2eInputsMissing(
["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_PLUGIN_READONLY_EMAIL", "E2E_PLUGIN_READONLY_PASSWORD", "E2E_TENANT_CHAT_PATH"],
"Team chat smoke inputs not configured"
);
skipOrFailWhenE2eOptInMissing("E2E_ALLOW_CHAT_SEND", "skipping the mutating team chat send flow");
});
test("delivers typing, messages, and reads live between two members, then reloads the persisted result", async ({ browser, page }, testInfo) => {
const peerContext = await browser.newContext();
const peerPage = await peerContext.newPage();
try {
await loginAsTenantUser(peerPage, peerCredentials!);
const peerChatUrl = new URL(chatPath!, peerPage.url()).toString();
const peerResponse = await peerPage.goto(peerChatUrl, { waitUntil: "domcontentloaded" });
await waitForHydration(peerPage);
await skipIfUnavailable(peerPage, peerResponse, `Team chat channel path ${chatPath}`);
expect(peerResponse?.ok(), `Peer team chat channel returned ${peerResponse?.status() ?? "no response"}`).toBe(true);
const peerScreen = peerPage.locator('[data-ui-id="ui.chat.channelDetail"]').first();
await expect(peerScreen).toBeVisible();
await expect(peerScreen.locator("[data-connection-state]")).toHaveCount(0, { timeout: 45_000 });
await loginAsTenantUser(page, credentials!);
const chatUrl = new URL(chatPath!, page.url()).toString();
const response = await page.goto(chatUrl, { waitUntil: "domcontentloaded" });
await skipIfUnavailable(page, response, `Team chat channel path ${chatPath}`);
expect(response?.ok(), `Team chat channel returned ${response?.status() ?? "no response"}`).toBe(true);
const screen = page.locator('[data-ui-id="ui.chat.channelDetail"]').first();
await expect(screen).toBeVisible();
// The connection alert is rendered for every non-online state. Waiting for
// it to disappear proves authentication and channel gap-sync completed.
await expect(screen.locator("[data-connection-state]")).toHaveCount(0, { timeout: 45_000 });
await expect(screen.locator('[data-ui-id="ui.chat.channelDetail.presence"]')).toBeVisible({ timeout: 15_000 });
const peerComposer = peerScreen.locator('[data-ui-id="ui.chat.channelDetail.composer"] textarea').first();
await peerComposer.fill(`typing probe ${Date.now()}`);
await expect(screen.locator('[data-ui-id="ui.chat.channelDetail.typing"]')).toBeVisible({ timeout: 10_000 });
await peerComposer.fill("");
const body = `E2E chat smoke ${testInfo.project.name} ${Date.now()}`;
const composer = screen.locator('[data-ui-id="ui.chat.channelDetail.composer"] textarea').first();
await expect(composer).toBeVisible();
await expect(composer).toBeEnabled();
await composer.fill(body);
const sendButton = screen.getByRole("button", { name: /^(Senden|Send)$/iu }).first();
await expect(sendButton).toBeEnabled();
await sendButton.click();
const acknowledgedMessage = screen.locator("[data-message-id]").filter({ hasText: body }).last();
await expect(acknowledgedMessage).toBeVisible();
const acknowledgedDelivery = acknowledgedMessage.locator("[data-delivery-state]").first();
await expect(acknowledgedDelivery).toHaveAttribute("data-delivery-state", "sent", { timeout: 30_000 });
await expect(acknowledgedDelivery).toHaveAttribute("data-transport-source", /^(http_ack|websocket)$/u);
const peerLiveMessage = peerScreen.locator("[data-message-id]").filter({ hasText: body }).last();
await expect(peerLiveMessage).toBeVisible({ timeout: 15_000 });
await expect(peerLiveMessage.locator("[data-delivery-state]").first()).toHaveAttribute("data-transport-source", "websocket");
const readReceipt = acknowledgedMessage.locator('[data-ui-id="ui.chat.channelDetail.readReceipt"]');
await expect(readReceipt).toHaveAttribute("data-read-count", "1", { timeout: 15_000 });
await expect(readReceipt).toHaveAttribute("data-recipient-count", "1");
await page.reload({ waitUntil: "domcontentloaded" });
const persistedMessage = page.locator('[data-ui-id="ui.chat.channelDetail"] [data-message-id]').filter({ hasText: body }).last();
await expect(persistedMessage).toBeVisible({ timeout: 15_000 });
await expect(persistedMessage.locator("[data-delivery-state]").first()).toHaveAttribute("data-transport-source", "persisted");
} finally {
await peerContext.close();
}
});
});