Integrate platform chat with persistent drafts and local harness support
This commit is contained in:
parent
b092cdc6c6
commit
cbf50defbd
10 changed files with 450 additions and 3 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
Engine entry point: `dist/wrapper.js` from `fuji-engine`. The wrapper exports init, move, ended, scores, rankings, currentPlayer, dropPlayer, logLength, logSlice, stripSecret, round, replay and setPlayerMetaData, plus the optional isLiveUpdate hook. `hashSeed = true`; the seed never appears in a stripped view. `moveAI(state, player)` returns a new state using the shared baseline bot; the harness and simulations use the same implementation.
|
||||
|
||||
Viewer: self-contained IIFE, global `fuji`, function `launch(selector)` returning an emitter. The bridge consumes state/player events, requests fresh state on state updates and game logs, forwards moves without double wrapping, and announces readiness after rendering the initial state. The host continues to provide chat, clocks, identity and iframe messaging. Source assets are bundled as data URLs, so the initial viewer has no independent asset-hosting requirement.
|
||||
Viewer: self-contained IIFE, global `fuji`, function `launch(selector)` returning an emitter. The bridge consumes state/player events, requests fresh state on state updates and game logs, forwards moves without double wrapping, and announces readiness after rendering the initial state. The host provides chat transport and storage, clocks, identity and iframe messaging. Set `viewer.chat: true`: Fuji renders chat during and after the expedition, including lobby history. The bridge handles `chat:messages`, `chat:appended`, `chat:updated`, `chat:deleted`, `chat:state`, `chat:disabled` and `chat:result`; sends carry a request ID and visible messages emit `chat:read`. Chat drafts and updates are independent of game animation playback. The local harness keeps its chat separately in local storage; switch seats to test multiple authors. Source assets are bundled as data URLs, so the initial viewer has no independent asset-hosting requirement.
|
||||
|
||||
```sh
|
||||
pnpm check
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"fmt": "oxfmt",
|
||||
"fmt:check": "oxfmt --check",
|
||||
"simulate": "pnpm --filter fuji-engine build && node scripts/simulate.mjs",
|
||||
"test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs && node tests/presentation-smoke.mjs"
|
||||
"test:browser": "node tests/browser-smoke.mjs && node tests/bgs-bundle-smoke.mjs && node tests/presentation-smoke.mjs && node tests/chat-smoke.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"oxfmt": "0.61.0",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<script lang="ts">
|
||||
import ChatPanel from "./lib/ChatPanel.svelte";
|
||||
import { untrack } from "svelte";
|
||||
import {
|
||||
terrain,
|
||||
|
|
@ -389,6 +390,15 @@
|
|||
: s.phase}</span
|
||||
>
|
||||
</div>
|
||||
{#if store.chat.enabled}<button
|
||||
class="text-button"
|
||||
onclick={() => {
|
||||
store.chat.open = true;
|
||||
requestAnimationFrame(() =>
|
||||
document.querySelector(".expedition-chat")?.scrollIntoView({ behavior: "smooth", block: "center" })
|
||||
);
|
||||
}}>Chat</button
|
||||
>{/if}
|
||||
<button class="text-button" onclick={() => (help = true)} aria-label="Open playing guide">Help</button>
|
||||
<button
|
||||
class="text-button"
|
||||
|
|
@ -696,6 +706,7 @@
|
|||
</div>{/if}
|
||||
{/if}
|
||||
</section>
|
||||
<ChatPanel {store} />
|
||||
<section class="journal inline-journal" aria-label="Expedition journal">
|
||||
<header class="journal-header">
|
||||
<h2>Expedition journal</h2>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,28 @@ import "./lib/theme.css";
|
|||
import enginePackage from "../../engine/package.json";
|
||||
const store = new Store();
|
||||
store.local = true;
|
||||
store.chat.enabled = true;
|
||||
store.chat.canSend = true;
|
||||
try {
|
||||
store.chat.replace(JSON.parse(localStorage.getItem("fuji-dev-chat") ?? "[]"));
|
||||
} catch {
|
||||
store.chat.replace([]);
|
||||
}
|
||||
store.chat.send = ({ text, requestId }) => {
|
||||
const playerIndex = store.seat ?? 0;
|
||||
store.chat.append([
|
||||
{
|
||||
_id: crypto.randomUUID(),
|
||||
author: store.state?.players[playerIndex]?.name ?? `Player ${playerIndex + 1}`,
|
||||
playerIndex,
|
||||
text,
|
||||
type: "text",
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
]);
|
||||
localStorage.setItem("fuji-dev-chat", JSON.stringify(store.chat.messages));
|
||||
store.chat.result({ requestId, ok: true });
|
||||
};
|
||||
store.setSound(localStorage.getItem("fuji-sound") !== "false");
|
||||
store.colorblind = localStorage.getItem("fuji-colorblind") === "true";
|
||||
store.savePreference = (_name, value) => localStorage.setItem("fuji-colorblind", String(value));
|
||||
|
|
@ -69,6 +91,9 @@ store.selectSeat = (seat) => {
|
|||
store.restart = (players, seed, difficulty, scenario = 1, skillAssignment = "random") => {
|
||||
game = initGame(players, { difficulty, scenario, skillAssignment }, seed);
|
||||
store.seat = 0;
|
||||
store.chat.replace([]);
|
||||
store.chat.draft = "";
|
||||
localStorage.removeItem("fuji-dev-chat");
|
||||
publish();
|
||||
};
|
||||
store.exportDebug = () =>
|
||||
|
|
|
|||
250
packages/viewer/src/lib/ChatPanel.svelte
Normal file
250
packages/viewer/src/lib/ChatPanel.svelte
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
<script lang="ts">
|
||||
import { tick } from "svelte";
|
||||
import type { Store } from "./store.svelte";
|
||||
let { store }: { store: Store } = $props();
|
||||
const chat = $derived(store.chat);
|
||||
|
||||
let list: HTMLDivElement | undefined = $state();
|
||||
let pinned = true;
|
||||
let lastRead = "";
|
||||
const colors = ["#e6c780", "#83ca90", "#80c5d7", "#d999b8"];
|
||||
const notice = $derived(
|
||||
chat.disabled
|
||||
? "Chat is disabled."
|
||||
: ({
|
||||
"not-logged-in": "Sign in to chat.",
|
||||
"not-confirmed": "Confirm your account to chat.",
|
||||
"not-a-player": "Only participants can send messages.",
|
||||
"chat-disabled": "Chat is disabled.",
|
||||
}[chat.reason] ?? "Chat is read-only.")
|
||||
);
|
||||
function visibleRead() {
|
||||
if (!list || !chat.open || document.visibilityState !== "visible" || !document.hasFocus()) return;
|
||||
const bounds = list.getBoundingClientRect();
|
||||
const rows = [...list.querySelectorAll<HTMLElement>("[data-message-id]")];
|
||||
const latest = rows.reverse().find((row) => {
|
||||
const r = row.getBoundingClientRect();
|
||||
return r.bottom <= Math.min(bounds.bottom, window.innerHeight) && r.bottom > Math.max(bounds.top, 0);
|
||||
});
|
||||
const id = latest?.dataset.messageId;
|
||||
if (id && id !== lastRead) {
|
||||
lastRead = id;
|
||||
chat.read(id);
|
||||
}
|
||||
}
|
||||
$effect(() => {
|
||||
const element = list;
|
||||
chat.messages;
|
||||
chat.open;
|
||||
if (!element || !chat.open) return;
|
||||
let disposed = false;
|
||||
void tick().then(() => {
|
||||
if (!disposed) {
|
||||
if (pinned) element.scrollTop = element.scrollHeight;
|
||||
visibleRead();
|
||||
}
|
||||
});
|
||||
const observer = new IntersectionObserver(visibleRead);
|
||||
observer.observe(element);
|
||||
return () => {
|
||||
disposed = true;
|
||||
observer.disconnect();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window onfocus={visibleRead} onscroll={visibleRead} />
|
||||
<svelte:document onvisibilitychange={visibleRead} />
|
||||
{#if chat.enabled}
|
||||
<section class="expedition-chat" aria-label="Expedition chat">
|
||||
<header>
|
||||
<h2>Expedition chat</h2>
|
||||
<button
|
||||
class="text-button"
|
||||
aria-label={chat.open ? "Collapse chat" : "Expand chat"}
|
||||
aria-expanded={chat.open}
|
||||
onclick={() => {
|
||||
chat.open = !chat.open;
|
||||
pinned = true;
|
||||
}}>{chat.open ? "−" : "+"}</button
|
||||
>
|
||||
</header>
|
||||
{#if chat.open}
|
||||
<div
|
||||
class="chat-messages"
|
||||
bind:this={list}
|
||||
role="region"
|
||||
aria-label="Chat messages"
|
||||
tabindex="0"
|
||||
onscroll={() => {
|
||||
if (list) pinned = list.scrollHeight - list.scrollTop - list.clientHeight < 32;
|
||||
visibleRead();
|
||||
}}
|
||||
>
|
||||
{#if !chat.messages.length}<p class="empty">Plan your escape together.</p>{/if}
|
||||
{#each chat.messages as message, i (message._id ?? i)}
|
||||
<article data-message-id={message._id} class:system={message.type === "system"}>
|
||||
{#if message.author}
|
||||
<div class="chat-author">
|
||||
{#if message.playerIndex !== undefined}
|
||||
<button
|
||||
style:color={colors[message.playerIndex]}
|
||||
onclick={() => store.clickPlayer(message.playerIndex!)}
|
||||
>
|
||||
{#if store.avatars[message.playerIndex]}<img
|
||||
src={store.avatars[message.playerIndex]}
|
||||
alt=""
|
||||
/>{/if}{message.author}
|
||||
</button>
|
||||
{:else}<strong>{message.author}</strong>{/if}
|
||||
{#if message.createdAt}<time
|
||||
datetime={message.createdAt}
|
||||
title={new Date(message.createdAt).toLocaleString()}
|
||||
>{new Date(message.createdAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}</time
|
||||
>{/if}
|
||||
{#if message.editedAt}<span title={new Date(message.editedAt).toLocaleString()}>edited</span>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<p>{message.text}</p>
|
||||
</article>
|
||||
{/each}
|
||||
</div>
|
||||
{#if chat.canSend && !chat.disabled}
|
||||
<form
|
||||
onsubmit={(event) => {
|
||||
event.preventDefault();
|
||||
chat.submit();
|
||||
}}
|
||||
>
|
||||
<textarea
|
||||
aria-label="Chat message"
|
||||
placeholder="Message your teammates…"
|
||||
rows="2"
|
||||
bind:value={chat.draft}
|
||||
onkeydown={(event) => {
|
||||
if (event.key === "Enter" && !event.shiftKey && !event.isComposing) {
|
||||
event.preventDefault();
|
||||
chat.submit();
|
||||
}
|
||||
}}></textarea>
|
||||
<button class="chat-send" disabled={!!chat.pending || !chat.draft.trim()} type="submit"
|
||||
>{chat.pending ? "Sending…" : "Send"}</button
|
||||
>
|
||||
</form>
|
||||
{:else}<p class="notice">{notice}</p>{/if}
|
||||
{#if chat.error}<p class="chat-error" role="alert">{chat.error}</p>{/if}
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.expedition-chat {
|
||||
border-top: 1px solid #e6c78030;
|
||||
padding: 20px 24px;
|
||||
background: #102a23;
|
||||
min-width: 0;
|
||||
}
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 19px;
|
||||
margin: 0;
|
||||
font-weight: 500;
|
||||
}
|
||||
.chat-messages {
|
||||
max-height: 260px;
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
overflow-anchor: none;
|
||||
margin: 14px 0;
|
||||
}
|
||||
article {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #ffffff0a;
|
||||
}
|
||||
.chat-author {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.chat-author button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
font: inherit;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.chat-author button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
img {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
object-fit: cover;
|
||||
}
|
||||
time,
|
||||
.chat-author span {
|
||||
color: #93aea2;
|
||||
font-size: 12px;
|
||||
}
|
||||
p {
|
||||
margin: 5px 0;
|
||||
font-size: 15px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.system,
|
||||
.empty,
|
||||
.notice {
|
||||
color: #a5bdb0;
|
||||
}
|
||||
form {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: stretch;
|
||||
}
|
||||
textarea {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
background: #0b211c;
|
||||
color: #f5ebce;
|
||||
border: 1px solid #6d8976;
|
||||
border-radius: 5px;
|
||||
padding: 10px;
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
resize: vertical;
|
||||
}
|
||||
textarea:focus-visible {
|
||||
outline: 2px solid #e6c780;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.chat-send {
|
||||
background: #e6c780;
|
||||
color: #142a22;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
padding: 10px 18px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.chat-send:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: default;
|
||||
}
|
||||
.chat-error {
|
||||
color: #ffbd98;
|
||||
}
|
||||
</style>
|
||||
58
packages/viewer/src/lib/chat.svelte.ts
Normal file
58
packages/viewer/src/lib/chat.svelte.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
export type ChatMessage = {
|
||||
_id?: string;
|
||||
author?: string;
|
||||
authorId?: string;
|
||||
playerIndex?: number;
|
||||
createdAt?: string;
|
||||
text: string;
|
||||
type: "text" | "system";
|
||||
editedAt?: string;
|
||||
};
|
||||
export class Chat {
|
||||
enabled = $state(false);
|
||||
open = $state(true);
|
||||
messages: ChatMessage[] = $state([]);
|
||||
canSend = $state(false);
|
||||
disabled = $state(false);
|
||||
reason = $state("");
|
||||
draft = $state("");
|
||||
error = $state("");
|
||||
pending = $state("");
|
||||
private sent = "";
|
||||
private sequence = 0;
|
||||
private timer: ReturnType<typeof setTimeout> | undefined;
|
||||
send: (data: { text: string; requestId: string }) => void = () => {};
|
||||
read: (messageId: string) => void = () => {};
|
||||
replace(messages: ChatMessage[]) {
|
||||
this.enabled = true;
|
||||
this.messages = messages;
|
||||
}
|
||||
append(messages: ChatMessage[]) {
|
||||
this.messages = [
|
||||
...this.messages,
|
||||
...messages.filter((m) => !m._id || !this.messages.some((old) => old._id === m._id)),
|
||||
];
|
||||
}
|
||||
submit() {
|
||||
if (!this.canSend || this.disabled || this.pending || !this.draft.trim()) return;
|
||||
this.error = "";
|
||||
this.sent = this.draft;
|
||||
this.pending = `fuji-chat-${Date.now()}-${++this.sequence}`;
|
||||
this.timer = setTimeout(() => {
|
||||
this.pending = "";
|
||||
this.error = "Delivery could not be confirmed. Check the chat before retrying.";
|
||||
}, 20000);
|
||||
this.send({ text: this.sent.trim(), requestId: this.pending });
|
||||
}
|
||||
result(result: { requestId: string; ok: boolean; error?: string }) {
|
||||
if (result.requestId !== this.pending) return;
|
||||
clearTimeout(this.timer);
|
||||
this.pending = "";
|
||||
if (result.ok) {
|
||||
if (this.draft === this.sent) this.draft = "";
|
||||
} else this.error = result.error || "Message could not be sent. Please try again.";
|
||||
}
|
||||
destroy() {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { Chat } from "./chat.svelte";
|
||||
import { SoundDesign, type SoundCue } from "./sound";
|
||||
import type { View, Move } from "fuji-engine";
|
||||
export class Store {
|
||||
chat = new Chat();
|
||||
state: View | null = $state(null);
|
||||
avatars: string[] = $state([]);
|
||||
clickPlayer: (index: number) => void = () => {};
|
||||
|
|
@ -15,6 +17,7 @@ export class Store {
|
|||
}
|
||||
destroy() {
|
||||
this.dispose();
|
||||
this.chat.destroy();
|
||||
this.audio.destroy();
|
||||
}
|
||||
scene: View | null = $state(null);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { mount, tick } from "svelte";
|
|||
import App from "./App.svelte";
|
||||
import { Store } from "./lib/store.svelte";
|
||||
import { Emitter } from "./lib/emitter";
|
||||
import type { ChatMessage } from "./lib/chat.svelte";
|
||||
import type { View } from "fuji-engine";
|
||||
import "./lib/theme.css";
|
||||
export function launch(selector: string) {
|
||||
|
|
@ -10,6 +11,27 @@ export function launch(selector: string) {
|
|||
const events = new Emitter();
|
||||
const store = new Store();
|
||||
let ready = false;
|
||||
const chat = store.chat;
|
||||
chat.send = (data) => events.emit("chat:send", data);
|
||||
chat.read = (messageId) => events.emit("chat:read", { messageId });
|
||||
events.on<ChatMessage[]>("chat:messages", (messages) => chat.replace(messages));
|
||||
events.on<ChatMessage[]>("chat:appended", (messages) => chat.append(messages));
|
||||
events.on<ChatMessage[]>("chat:updated", (messages) => {
|
||||
chat.messages = chat.messages.map((m) => messages.find((update) => update._id === m._id) ?? m);
|
||||
});
|
||||
events.on<string[]>("chat:deleted", (ids) => {
|
||||
chat.messages = chat.messages.filter((m) => !m._id || !ids.includes(m._id));
|
||||
});
|
||||
events.on<boolean>("chat:disabled", (disabled) => {
|
||||
chat.disabled = disabled;
|
||||
});
|
||||
events.on<{ canSend: boolean; reason?: string }>("chat:state", (state) => {
|
||||
chat.enabled = true;
|
||||
chat.canSend = state.canSend;
|
||||
chat.reason = state.reason ?? "";
|
||||
});
|
||||
events.on<{ requestId: string; ok: boolean; error?: string }>("chat:result", (result) => chat.result(result));
|
||||
|
||||
store.savePreference = (name, value) => events.emit("update:preference", { name, value });
|
||||
events.on<Record<string, unknown>>("preferences", (preferences) => {
|
||||
store.colorblind = preferences?.colorblind === true;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ await request(version, "PUT", {
|
|||
...current,
|
||||
alias: current.alias ?? null,
|
||||
public: false,
|
||||
viewer: { ...draft.viewer, url: js.url, dependencies: { scripts: [], stylesheets: [css.url] } },
|
||||
viewer: { ...draft.viewer, chat: true, url: js.url, dependencies: { scripts: [], stylesheets: [css.url] } },
|
||||
});
|
||||
await request("/admin/page/fuji:rules/en", "PUT", {
|
||||
title: "Fuji: how to play",
|
||||
|
|
|
|||
78
tests/chat-smoke.mjs
Normal file
78
tests/chat-smoke.mjs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import { chromium } from "playwright";
|
||||
import assert from "node:assert/strict";
|
||||
import { initGame, stripSecret } from "../packages/engine/dist/index.js";
|
||||
const browser = await chromium.launch({ headless: true, executablePath: process.env.FUJI_CHROMIUM_EXECUTABLE });
|
||||
try {
|
||||
const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.setContent('<div id="app"></div>');
|
||||
await page.addStyleTag({ path: "packages/viewer/dist/fuji-viewer.css" });
|
||||
await page.addScriptTag({ path: "packages/viewer/dist/fuji-viewer.iife.js" });
|
||||
await page.evaluate(
|
||||
(view) => {
|
||||
window.events = [];
|
||||
window.bridge = window.fuji.launch("#app");
|
||||
for (const name of ["chat:send", "chat:read"])
|
||||
window.bridge.on(name, (data) => window.events.push({ name, data }));
|
||||
window.bridge.emit("state", view);
|
||||
window.bridge.emit("player", { index: 0 });
|
||||
window.bridge.emit("chat:messages", [
|
||||
{ _id: "000000010000000000000001", author: "Alice", playerIndex: 0, type: "text", text: "From the lobby" },
|
||||
]);
|
||||
window.bridge.emit("chat:state", { canSend: true });
|
||||
},
|
||||
stripSecret(initGame(3, {}, "chat-test"), 0)
|
||||
);
|
||||
const panel = page.getByRole("region", { name: "Expedition chat", exact: true });
|
||||
await panel.scrollIntoViewIfNeeded();
|
||||
await page.waitForFunction(() => window.events.some((e) => e.name === "chat:read"));
|
||||
await page.getByRole("textbox", { name: "Chat message" }).fill("Let's go");
|
||||
await page.getByRole("button", { name: "Send", exact: true }).click();
|
||||
let request = await page.evaluate(() => window.events.find((e) => e.name === "chat:send").data);
|
||||
assert.equal(request.text, "Let's go");
|
||||
await page.evaluate(
|
||||
(request) => window.bridge.emit("chat:result", { requestId: request.requestId, ok: false, error: "Rate limited" }),
|
||||
request
|
||||
);
|
||||
assert.equal(await page.getByRole("textbox", { name: "Chat message" }).inputValue(), "Let's go");
|
||||
assert.equal(await page.getByRole("alert").innerText(), "Rate limited");
|
||||
await page.getByRole("button", { name: "Send", exact: true }).click();
|
||||
request = await page.evaluate(() => window.events.filter((e) => e.name === "chat:send").at(-1).data);
|
||||
await page.evaluate((request) => {
|
||||
window.bridge.emit("chat:result", { requestId: request.requestId, ok: true });
|
||||
window.bridge.emit("chat:appended", [
|
||||
{ _id: "000000020000000000000002", author: "Me", text: request.text, type: "text" },
|
||||
]);
|
||||
}, request);
|
||||
assert.equal(await page.getByRole("textbox", { name: "Chat message" }).inputValue(), "");
|
||||
await page.getByRole("textbox", { name: "Chat message" }).fill("Still drafting");
|
||||
await page.evaluate(() => {
|
||||
window.bridge.emit("chat:updated", [
|
||||
{ _id: "000000010000000000000001", author: "Alice", text: "Edited lobby message", type: "text" },
|
||||
]);
|
||||
window.bridge.emit("chat:deleted", ["000000020000000000000002"]);
|
||||
});
|
||||
assert.equal(await panel.getByText("Edited lobby message").count(), 1);
|
||||
assert.equal(await panel.getByText("Let's go", { exact: true }).count(), 0);
|
||||
assert.equal(await page.getByRole("textbox", { name: "Chat message" }).inputValue(), "Still drafting");
|
||||
await page.evaluate(() => {
|
||||
window.bridge.emit("chat:messages", [{ _id: "000000030000000000000003", text: "Reconnected", type: "system" }]);
|
||||
});
|
||||
assert.equal(await panel.getByText("Edited lobby message").count(), 0);
|
||||
assert.equal(await panel.getByText("Reconnected").count(), 1);
|
||||
assert.equal(await page.getByRole("textbox", { name: "Chat message" }).inputValue(), "Still drafting");
|
||||
await page.screenshot({ path: "work/chat-desktop.png" });
|
||||
await page.evaluate(() => window.bridge.emit("chat:disabled", true));
|
||||
assert.equal(await page.getByRole("textbox", { name: "Chat message" }).count(), 0);
|
||||
assert.equal(await panel.getByText("Chat is disabled.").count(), 1);
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await panel.scrollIntoViewIfNeeded();
|
||||
await page.screenshot({ path: "work/chat-mobile.png" });
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(
|
||||
"Chat bridge: history, send success/failure, draft preservation, edits, deletes and disabled state passed."
|
||||
);
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue