|
| 1 | +// Control UI E2E: grapheme-aware avatar initials remain intact across every |
| 2 | +// live agent-avatar fallback surface. |
| 3 | +import { mkdir } from "node:fs/promises"; |
| 4 | +import path from "node:path"; |
| 5 | +import { chromium, type Browser, type Page } from "playwright"; |
| 6 | +import { afterAll, beforeAll, describe, expect, it } from "vitest"; |
| 7 | +import { |
| 8 | + canRunPlaywrightChromium, |
| 9 | + installMockGateway, |
| 10 | + resolvePlaywrightChromiumExecutablePath, |
| 11 | + startControlUiE2eServer, |
| 12 | + type ControlUiE2eServer, |
| 13 | +} from "../test-helpers/control-ui-e2e.ts"; |
| 14 | + |
| 15 | +const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath()); |
| 16 | +const chromiumAvailable = canRunPlaywrightChromium(chromiumExecutablePath); |
| 17 | +const allowMissingChromium = process.env.OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM === "1"; |
| 18 | +const describeControlUiE2e = chromiumAvailable || !allowMissingChromium ? describe : describe.skip; |
| 19 | +const captureUiProof = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1"; |
| 20 | +const proofDir = path.join(process.cwd(), ".artifacts", "control-ui-e2e", "avatar-initial-emoji"); |
| 21 | + |
| 22 | +const emojiAgent = { id: "emoji", identity: { name: "🚀Rocket" }, name: "🚀Rocket" }; |
| 23 | +const asciiAgent = { id: "main", identity: { name: "Main" }, name: "Main" }; |
| 24 | +const emojiGrapheme = "🚀"; |
| 25 | +const agentsList = { |
| 26 | + defaultId: "main", |
| 27 | + mainKey: "main", |
| 28 | + scope: "agent", |
| 29 | + agents: [asciiAgent, emojiAgent], |
| 30 | +}; |
| 31 | +const agentIdentities = { |
| 32 | + cases: [ |
| 33 | + { |
| 34 | + match: { agentId: "emoji" }, |
| 35 | + response: { agentId: "emoji", avatar: "", avatarStatus: "none", name: "🚀Rocket" }, |
| 36 | + }, |
| 37 | + { |
| 38 | + match: { agentId: "main" }, |
| 39 | + response: { agentId: "main", avatar: "", avatarStatus: "none", name: "Main" }, |
| 40 | + }, |
| 41 | + ], |
| 42 | +}; |
| 43 | + |
| 44 | +let browser: Browser; |
| 45 | +let server: ControlUiE2eServer; |
| 46 | + |
| 47 | +async function screenshot(page: Page, name: string) { |
| 48 | + if (!captureUiProof) { |
| 49 | + return; |
| 50 | + } |
| 51 | + await mkdir(proofDir, { recursive: true }); |
| 52 | + await page.screenshot({ |
| 53 | + animations: "disabled", |
| 54 | + fullPage: true, |
| 55 | + path: path.join(proofDir, name), |
| 56 | + }); |
| 57 | +} |
| 58 | + |
| 59 | +describeControlUiE2e("Control UI grapheme-aware avatar initials", () => { |
| 60 | + beforeAll(async () => { |
| 61 | + if (!chromiumAvailable) { |
| 62 | + throw new Error(`Playwright Chromium is not available at ${chromiumExecutablePath}`); |
| 63 | + } |
| 64 | + server = await startControlUiE2eServer(); |
| 65 | + browser = await chromium.launch({ executablePath: chromiumExecutablePath }); |
| 66 | + }); |
| 67 | + |
| 68 | + afterAll(async () => { |
| 69 | + await browser?.close(); |
| 70 | + await server?.close(); |
| 71 | + }); |
| 72 | + |
| 73 | + it("renders the emoji grapheme initial in the sidebar chip and agent menu row", async () => { |
| 74 | + const context = await browser.newContext({ |
| 75 | + locale: "en-US", |
| 76 | + serviceWorkers: "block", |
| 77 | + viewport: { height: 900, width: 1440 }, |
| 78 | + }); |
| 79 | + const page = await context.newPage(); |
| 80 | + const gateway = await installMockGateway(page, { |
| 81 | + defaultAgentId: "main", |
| 82 | + methodResponses: { |
| 83 | + "agent.identity.get": agentIdentities, |
| 84 | + "agents.list": agentsList, |
| 85 | + "chat.startup": { |
| 86 | + agentsList, |
| 87 | + messages: [], |
| 88 | + metadata: { models: [] }, |
| 89 | + sessionId: "control-ui-e2e-session", |
| 90 | + thinkingLevel: null, |
| 91 | + }, |
| 92 | + "sessions.list": { |
| 93 | + count: 0, |
| 94 | + defaults: { contextTokens: null, model: null, modelProvider: null }, |
| 95 | + path: "", |
| 96 | + sessions: [], |
| 97 | + ts: Date.now(), |
| 98 | + }, |
| 99 | + }, |
| 100 | + }); |
| 101 | + |
| 102 | + try { |
| 103 | + const response = await page.goto(`${server.baseUrl}usage`); |
| 104 | + expect(response?.status()).toBe(200); |
| 105 | + await gateway.waitForRequest("agents.list"); |
| 106 | + const sidebar = page.locator("openclaw-app-sidebar"); |
| 107 | + |
| 108 | + await sidebar.getByRole("button", { name: /Switch agent/ }).click(); |
| 109 | + const emojiRow = sidebar |
| 110 | + .locator("wa-dropdown.sidebar-agent-menu") |
| 111 | + .getByRole("menuitemradio", { name: "🚀Rocket", exact: true }); |
| 112 | + const menuAvatar = emojiRow.locator(".agent-select__avatar--text"); |
| 113 | + await expect.poll(() => menuAvatar.getAttribute("data-avatar")).toBe(emojiGrapheme); |
| 114 | + // The shared picker paints its text through CSS, not a text node. |
| 115 | + await expect |
| 116 | + .poll(() => menuAvatar.evaluate((element) => getComputedStyle(element, "::before").content)) |
| 117 | + .toContain(emojiGrapheme); |
| 118 | + await screenshot(page, "01-sidebar-menu-emoji.png"); |
| 119 | + |
| 120 | + await emojiRow.click(); |
| 121 | + await expect |
| 122 | + .poll(async () => |
| 123 | + (await gateway.getRequests("sessions.list")).some( |
| 124 | + (request) => |
| 125 | + request.params && (request.params as { agentId?: string }).agentId === "emoji", |
| 126 | + ), |
| 127 | + ) |
| 128 | + .toBe(true); |
| 129 | + await expect |
| 130 | + .poll(() => sidebar.locator(".sidebar-agent-card__avatar-text").textContent()) |
| 131 | + .toBe(emojiGrapheme); |
| 132 | + await screenshot(page, "01-sidebar-chip-emoji.png"); |
| 133 | + } finally { |
| 134 | + await context.close(); |
| 135 | + } |
| 136 | + }); |
| 137 | + |
| 138 | + it("renders the emoji grapheme initial in the agent selector dropdown", async () => { |
| 139 | + const context = await browser.newContext({ |
| 140 | + locale: "en-US", |
| 141 | + serviceWorkers: "block", |
| 142 | + viewport: { height: 900, width: 1440 }, |
| 143 | + }); |
| 144 | + const page = await context.newPage(); |
| 145 | + const gateway = await installMockGateway(page, { |
| 146 | + defaultAgentId: "main", |
| 147 | + methodResponses: { |
| 148 | + "agent.identity.get": agentIdentities, |
| 149 | + "agents.list": agentsList, |
| 150 | + }, |
| 151 | + }); |
| 152 | + |
| 153 | + try { |
| 154 | + const response = await page.goto(`${server.baseUrl}agents`); |
| 155 | + expect(response?.status()).toBe(200); |
| 156 | + await gateway.waitForRequest("agents.list"); |
| 157 | + const agentSelect = page.locator("openclaw-agents-page openclaw-agent-select"); |
| 158 | + await agentSelect.locator(".agent-select__trigger").click(); |
| 159 | + const emojiItem = agentSelect.getByRole("menuitemradio", { |
| 160 | + name: "🚀Rocket", |
| 161 | + exact: true, |
| 162 | + }); |
| 163 | + const pickerAvatar = emojiItem.locator(".agent-select__avatar--text"); |
| 164 | + await expect.poll(() => pickerAvatar.getAttribute("data-avatar")).toBe(emojiGrapheme); |
| 165 | + await expect |
| 166 | + .poll(() => |
| 167 | + pickerAvatar.evaluate((element) => getComputedStyle(element, "::before").content), |
| 168 | + ) |
| 169 | + .toContain(emojiGrapheme); |
| 170 | + await screenshot(page, "02-agent-selector-emoji.png"); |
| 171 | + } finally { |
| 172 | + await context.close(); |
| 173 | + } |
| 174 | + }); |
| 175 | + |
| 176 | + it("renders the emoji grapheme initial in the agents overview identity editor", async () => { |
| 177 | + const context = await browser.newContext({ |
| 178 | + locale: "en-US", |
| 179 | + serviceWorkers: "block", |
| 180 | + viewport: { height: 900, width: 1440 }, |
| 181 | + }); |
| 182 | + const page = await context.newPage(); |
| 183 | + const config = { agents: { list: [{ id: "main" }, { id: "emoji" }] } }; |
| 184 | + const gateway = await installMockGateway(page, { |
| 185 | + defaultAgentId: "main", |
| 186 | + methodResponses: { |
| 187 | + "agent.identity.get": agentIdentities, |
| 188 | + "agents.list": agentsList, |
| 189 | + "config.get": { |
| 190 | + config, |
| 191 | + sourceConfig: config, |
| 192 | + hash: "hash-1", |
| 193 | + issues: [], |
| 194 | + raw: JSON.stringify(config), |
| 195 | + valid: true, |
| 196 | + }, |
| 197 | + }, |
| 198 | + }); |
| 199 | + |
| 200 | + try { |
| 201 | + const response = await page.goto(`${server.baseUrl}settings/agents/main/tools`); |
| 202 | + expect(response?.status()).toBe(200); |
| 203 | + await gateway.waitForRequest("agents.list"); |
| 204 | + await gateway.waitForRequest("config.get"); |
| 205 | + const agentSelect = page.locator("openclaw-agents-page openclaw-agent-select"); |
| 206 | + await agentSelect.locator(".agent-select__trigger").click(); |
| 207 | + await agentSelect.getByRole("menuitemradio", { name: "🚀Rocket", exact: true }).click(); |
| 208 | + await expect.poll(() => new URL(page.url()).pathname).toBe("/settings/agents/emoji/tools"); |
| 209 | + await page.getByRole("tab", { name: "Overview", exact: true }).click(); |
| 210 | + await expect.poll(() => new URL(page.url()).pathname).toBe("/settings/agents/emoji/overview"); |
| 211 | + await expect |
| 212 | + .poll(() => page.locator(".agent-identity-editor__avatar-text").textContent()) |
| 213 | + .toBe(emojiGrapheme); |
| 214 | + await screenshot(page, "03-agents-overview-emoji.png"); |
| 215 | + } finally { |
| 216 | + await context.close(); |
| 217 | + } |
| 218 | + }); |
| 219 | +}); |
0 commit comments