|
| 1 | +import { test, expect } from "./source-fixture.mjs"; |
| 2 | +import { watchPageErrors } from "./page-errors.mjs"; |
| 3 | + |
| 4 | +// Real overflow, tooltip placement and retained editor focus need a browser. |
| 5 | +// Reuse the emoji fixture's real composer/provider with only its small catalog. |
| 6 | +test("truncated emoji names reveal their full value without taking composer focus", async ({ |
| 7 | + page, |
| 8 | +}, testInfo) => { |
| 9 | + const errors = watchPageErrors(page); |
| 10 | + await page.route("**/emoji-media/**", (route) => |
| 11 | + route.fulfill({ |
| 12 | + contentType: "image/svg+xml", |
| 13 | + body: '<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22"><circle cx="11" cy="11" r="10" fill="purple"/></svg>', |
| 14 | + }), |
| 15 | + ); |
| 16 | + await page.goto("/tests/fixtures/emoji.html"); |
| 17 | + const input = page.getByRole("textbox", { name: "Message #general" }); |
| 18 | + const firstName = ":very-long-community-emoji-name-that-does-not-fit:"; |
| 19 | + const secondName = |
| 20 | + ":very-long-community-emoji-name-that-does-not-fit-either:"; |
| 21 | + const choices = page.getByRole("option"); |
| 22 | + const tooltip = page.getByRole("tooltip").and(page.locator("[data-open]")); |
| 23 | + |
| 24 | + for (const [mode, width, scale] of [ |
| 25 | + ["light", 1280, 1], |
| 26 | + ["dark", 1280, 1], |
| 27 | + ["light", 390, 1.5], |
| 28 | + ["dark", 390, 1.5], |
| 29 | + ]) { |
| 30 | + await page.setViewportSize({ width, height: 844 }); |
| 31 | + await page.evaluate( |
| 32 | + ({ mode, scale }) => { |
| 33 | + document.documentElement.dataset.colorMode = mode; |
| 34 | + document.documentElement.style.setProperty("--buzz-text-scale", scale); |
| 35 | + }, |
| 36 | + { mode, scale }, |
| 37 | + ); |
| 38 | + await page.mouse.move(0, 0); |
| 39 | + await input.fill(":very-long"); |
| 40 | + await expect(choices).toHaveCount(2); |
| 41 | + const label = choices.first().locator("[data-completion-label] > span"); |
| 42 | + await expect(label).toHaveCSS("text-overflow", "ellipsis"); |
| 43 | + await expect(label).toHaveCSS("white-space", "nowrap"); |
| 44 | + await expect |
| 45 | + .poll(() => label.evaluate((el) => el.scrollWidth > el.clientWidth)) |
| 46 | + .toBe(true); |
| 47 | + await label.hover(); |
| 48 | + await expect(tooltip).toHaveText(firstName); |
| 49 | + await expect(tooltip).toHaveCSS("opacity", "1"); |
| 50 | + await expect(input).toBeFocused(); |
| 51 | + await expect |
| 52 | + .poll(() => |
| 53 | + tooltip.evaluate((el) => { |
| 54 | + const bounds = el.getBoundingClientRect(); |
| 55 | + return ( |
| 56 | + bounds.left >= 0 && |
| 57 | + bounds.right <= innerWidth && |
| 58 | + bounds.top >= 0 && |
| 59 | + bounds.bottom <= innerHeight && |
| 60 | + el.scrollWidth <= el.clientWidth |
| 61 | + ); |
| 62 | + }), |
| 63 | + ) |
| 64 | + .toBe(true); |
| 65 | + await page.screenshot({ |
| 66 | + path: testInfo.outputPath(`emoji-name-${mode}-${width}.png`), |
| 67 | + }); |
| 68 | + await input.press("Escape"); |
| 69 | + await expect(page.getByRole("listbox")).toHaveCount(0); |
| 70 | + await expect(tooltip).toHaveCount(0); |
| 71 | + await expect(input).toHaveJSProperty("value", ":very-long"); |
| 72 | + await expect(input).toBeFocused(); |
| 73 | + } |
| 74 | + |
| 75 | + await page.mouse.move(0, 0); |
| 76 | + await input.fill(":very-long"); |
| 77 | + await expect(choices).toHaveCount(2); |
| 78 | + await input.press("ArrowDown"); |
| 79 | + await expect(choices.nth(1)).toHaveAttribute("aria-selected", "true"); |
| 80 | + await expect(tooltip).toHaveText(secondName); |
| 81 | + await expect(input).toBeFocused(); |
| 82 | + await page.mouse.move(1, 1); |
| 83 | + await expect(tooltip).toHaveCount(0); |
| 84 | + await expect(input).toBeFocused(); |
| 85 | + await input.press("ArrowUp"); |
| 86 | + await expect(tooltip).toHaveText(firstName); |
| 87 | + await input.press("Escape"); |
| 88 | + await expect(page.getByRole("listbox")).toHaveCount(0); |
| 89 | + await expect(tooltip).toHaveCount(0); |
| 90 | + await expect(input).toBeFocused(); |
| 91 | + await input.fill(":very-long"); |
| 92 | + await expect(choices).toHaveCount(2); |
| 93 | + await input.press("ArrowUp"); |
| 94 | + await expect(tooltip).toHaveText(secondName); |
| 95 | + await input.press("ArrowUp"); |
| 96 | + await expect(tooltip).toHaveText(firstName); |
| 97 | + await input.press("Tab"); |
| 98 | + await expect(input).toHaveJSProperty("value", firstName); |
| 99 | + await expect(tooltip).toHaveCount(0); |
| 100 | + await expect(input).toBeFocused(); |
| 101 | + |
| 102 | + await input.fill(":very-long"); |
| 103 | + await expect(choices).toHaveCount(2); |
| 104 | + await input.press("ArrowDown"); |
| 105 | + await expect(tooltip).toHaveText(secondName); |
| 106 | + await input.press("Enter"); |
| 107 | + await expect(input).toHaveJSProperty("value", secondName); |
| 108 | + await expect(tooltip).toHaveCount(0); |
| 109 | + |
| 110 | + await input.fill(":very-long"); |
| 111 | + await choices.first().locator("[data-completion-label]").hover(); |
| 112 | + await expect(tooltip).toHaveText(firstName); |
| 113 | + await choices.nth(1).click(); |
| 114 | + await expect(input).toHaveJSProperty("value", secondName); |
| 115 | + await expect(tooltip).toHaveCount(0); |
| 116 | + await expect(input).toBeFocused(); |
| 117 | + |
| 118 | + // Fully visible names keep their label without an unnecessary hint. |
| 119 | + await page.setViewportSize({ width: 1280, height: 844 }); |
| 120 | + await page.evaluate(() => |
| 121 | + document.documentElement.style.setProperty("--buzz-text-scale", "1"), |
| 122 | + ); |
| 123 | + await input.fill(":aonly"); |
| 124 | + const shortChoice = page.getByRole("option", { |
| 125 | + name: ":aonly:", |
| 126 | + exact: true, |
| 127 | + }); |
| 128 | + await expect(shortChoice).toBeVisible(); |
| 129 | + const short = shortChoice.locator("[data-completion-label] > span"); |
| 130 | + await expect |
| 131 | + .poll(() => short.evaluate((el) => el.scrollWidth <= el.clientWidth)) |
| 132 | + .toBe(true); |
| 133 | + await short.hover(); |
| 134 | + await input.press("ArrowDown"); |
| 135 | + await input.press("ArrowUp"); |
| 136 | + await expect(shortChoice).toHaveAttribute("aria-selected", "true"); |
| 137 | + await expect(tooltip).toHaveCount(0); |
| 138 | + // Resize the same mounted query to exercise overflow updates both ways. |
| 139 | + const selectedId = await shortChoice.getAttribute("id"); |
| 140 | + await page.mouse.move(0, 0); |
| 141 | + await input.press("ArrowDown"); |
| 142 | + await input.press("ArrowUp"); |
| 143 | + await page.setViewportSize({ width: 200, height: 844 }); |
| 144 | + await expect(tooltip).toHaveText(":aonly:"); |
| 145 | + await page.setViewportSize({ width: 1280, height: 844 }); |
| 146 | + await expect |
| 147 | + .poll(() => short.evaluate((el) => el.scrollWidth <= el.clientWidth)) |
| 148 | + .toBe(true); |
| 149 | + await expect(tooltip).toHaveCount(0); |
| 150 | + await expect(shortChoice).toHaveAttribute("id", selectedId); |
| 151 | + await input.press("Escape"); |
| 152 | + await expect(page.getByRole("listbox")).toHaveCount(0); |
| 153 | + expect(errors.unexplained()).toEqual([]); |
| 154 | +}); |
0 commit comments