|
| 1 | +import { expect, it } from "vitest"; |
| 2 | +import { createPlaybackMediaFixture } from "../../../test/fixtures/media-playback.js"; |
| 3 | +import { installMockGateway } from "../test-helpers/control-ui-e2e.ts"; |
| 4 | +import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts"; |
| 5 | + |
| 6 | +const suite = createControlUiE2eSuite({ name: "Attachment file styles" }); |
| 7 | + |
| 8 | +suite.define(() => { |
| 9 | + it("preserves large, preview, and unavailable file visuals in both themes", async () => { |
| 10 | + await suite.withPage({ locale: "en-US", serviceWorkers: "block" }, async ({ page }) => { |
| 11 | + await page.route("**/style-proof.mp3", (route) => |
| 12 | + route.fulfill({ contentType: "audio/mpeg", body: createPlaybackMediaFixture("mp3") }), |
| 13 | + ); |
| 14 | + await installMockGateway(page, { |
| 15 | + historyMessages: [ |
| 16 | + { |
| 17 | + role: "assistant", |
| 18 | + content: [ |
| 19 | + { |
| 20 | + type: "attachment", |
| 21 | + attachment: { |
| 22 | + kind: "document", |
| 23 | + label: "report.pdf", |
| 24 | + mimeType: "application/pdf", |
| 25 | + url: new URL("report.pdf", suite.server.baseUrl).href, |
| 26 | + }, |
| 27 | + }, |
| 28 | + { |
| 29 | + type: "attachment", |
| 30 | + attachment: { |
| 31 | + kind: "audio", |
| 32 | + label: "style-proof.mp3", |
| 33 | + mimeType: "audio/mpeg", |
| 34 | + url: new URL("style-proof.mp3", suite.server.baseUrl).href, |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + type: "attachment_error", |
| 39 | + attachment: { |
| 40 | + code: "file-not-found", |
| 41 | + kind: "document", |
| 42 | + label: "missing.pdf", |
| 43 | + }, |
| 44 | + }, |
| 45 | + ], |
| 46 | + timestamp: 1, |
| 47 | + }, |
| 48 | + ], |
| 49 | + }); |
| 50 | + await page.goto(`${suite.server.baseUrl}chat`); |
| 51 | + const compact = page.locator('.chat-attachment-file-icon[data-mode="preview-with-favicon"]'); |
| 52 | + await compact.waitFor({ state: "visible" }); |
| 53 | + const documentCard = page.locator(".chat-assistant-attachment-card--compact", { |
| 54 | + hasText: "report.pdf", |
| 55 | + }); |
| 56 | + const unavailable = page.locator(".chat-assistant-attachment-card--definitive", { |
| 57 | + hasText: "missing.pdf", |
| 58 | + }); |
| 59 | + await unavailable.waitFor({ state: "visible" }); |
| 60 | + |
| 61 | + for (const theme of ["dark", "light"]) { |
| 62 | + await page.evaluate((mode) => { |
| 63 | + document.documentElement.dataset.themeMode = mode; |
| 64 | + }, theme); |
| 65 | + const large = documentCard.locator(".chat-attachment-file-icon"); |
| 66 | + const largeStyle = await large.evaluate((icon) => { |
| 67 | + const style = getComputedStyle(icon); |
| 68 | + const overlay = icon.querySelector(".chat-attachment-file-icon__overlay")!; |
| 69 | + const glyph = getComputedStyle(overlay); |
| 70 | + return { |
| 71 | + width: style.width, |
| 72 | + height: style.height, |
| 73 | + background: style.backgroundImage, |
| 74 | + glyphWidth: glyph.width, |
| 75 | + glyphHeight: glyph.height, |
| 76 | + mask: glyph.maskImage, |
| 77 | + webkitMask: glyph.webkitMaskImage, |
| 78 | + }; |
| 79 | + }); |
| 80 | + expect(largeStyle).toMatchObject({ |
| 81 | + width: "44px", |
| 82 | + height: "44px", |
| 83 | + glyphWidth: "14px", |
| 84 | + glyphHeight: "14px", |
| 85 | + }); |
| 86 | + expect(largeStyle.background).toContain(`large/shell-${theme}.svg`); |
| 87 | + expect(largeStyle.mask).toContain("overlays/pdf.svg"); |
| 88 | + expect(largeStyle.webkitMask).toBe(largeStyle.mask); |
| 89 | + const previewStyle = await compact.evaluate((icon) => { |
| 90 | + const style = getComputedStyle(icon); |
| 91 | + return { width: style.width, height: style.height, background: style.backgroundImage }; |
| 92 | + }); |
| 93 | + expect(previewStyle).toMatchObject({ width: "20px", height: "20px" }); |
| 94 | + expect(previewStyle.background).toContain(`compact/${theme}/mp3.svg`); |
| 95 | + expect( |
| 96 | + await documentCard.evaluate((card) => { |
| 97 | + const style = getComputedStyle(card); |
| 98 | + return [style.display, style.padding]; |
| 99 | + }), |
| 100 | + ).toEqual(["block", "0px"]); |
| 101 | + const failedStyle = await unavailable.evaluate((card) => { |
| 102 | + const icon = card.querySelector(".chat-attachment-file-icon")!; |
| 103 | + const metadata = card.querySelector(".chat-assistant-attachment-card__status-meta")!; |
| 104 | + const title = card.querySelector(".chat-assistant-attachment-card__title")!; |
| 105 | + return { |
| 106 | + color: getComputedStyle(card).color, |
| 107 | + danger: getComputedStyle(card).getPropertyValue("--danger").trim(), |
| 108 | + iconColor: getComputedStyle(icon).color, |
| 109 | + statusColor: getComputedStyle(metadata).color, |
| 110 | + opacity: getComputedStyle(icon).opacity, |
| 111 | + decoration: getComputedStyle(title).textDecorationLine, |
| 112 | + thickness: getComputedStyle(title).textDecorationThickness, |
| 113 | + display: getComputedStyle(card).display, |
| 114 | + padding: getComputedStyle(card).padding, |
| 115 | + }; |
| 116 | + }); |
| 117 | + expect(failedStyle).toMatchObject({ |
| 118 | + iconColor: failedStyle.color, |
| 119 | + statusColor: failedStyle.color, |
| 120 | + opacity: "0.42", |
| 121 | + decoration: "line-through", |
| 122 | + thickness: "1px", |
| 123 | + display: "block", |
| 124 | + padding: "0px", |
| 125 | + }); |
| 126 | + expect(failedStyle.color).toBe( |
| 127 | + await page.evaluate((color) => { |
| 128 | + const sample = document.createElement("span"); |
| 129 | + sample.style.color = color; |
| 130 | + document.body.append(sample); |
| 131 | + const resolved = getComputedStyle(sample).color; |
| 132 | + sample.remove(); |
| 133 | + return resolved; |
| 134 | + }, failedStyle.danger), |
| 135 | + ); |
| 136 | + } |
| 137 | + }); |
| 138 | + }); |
| 139 | +}); |
0 commit comments