mirror of
https://github.com/block/buzz.git
synced 2026-10-30 05:51:46 +00:00
## Problem Quick-reaction shortcuts make the message action rail visually noisy. Reaction access should remain first-class, but through one predictable Add reaction action rather than several learned emoji shortcuts. ## Change The rail is now: **Add reaction · Reply · Copy link · More** - Remove all quick-reaction shortcut buttons and their divider from the message action rail. - Preserve Add reaction as the first action, including its existing picker, tooltip, accessible name, keyboard behavior, reaction behavior, and feedback. - Keep the existing Link2 Copy link action, shared copy handler, More-menu entry, eligibility guards, and success feedback unchanged. - Keep reveal, positioning, responsiveness, styling, and remaining menu paths unchanged. The now-unused quick-reaction rendering component and imports were removed from `MessageActionBar`; shared reaction learning remains intact for other reaction surfaces. ## Tests Focused smoke coverage verifies: - zero `React with …` shortcut buttons; - exact ordered rail: `Open reactions → Reply → Copy link → More actions`; - the rail and More-menu paths emit the same canonical thread-aware `buzz://message` URL; - existing success feedback; - pending and huddle rows omit both copy-link surfaces; - the action bar stays within the open thread panel. The zero-shortcut contract was mutation-checked by restoring the prior production action bar: the focused test failed causally with expected 0 versus received 3 quick-reaction buttons. ## Validation At `4f062e0d60b0f0c16b6862cdea7137c287060947`: - `pnpm exec biome check src/features/messages/ui/MessageActionBar.tsx tests/e2e/message-copy-link.spec.ts` — passed. - `pnpm exec tsc --noEmit` — passed. - `pnpm test` — 5,432 passed, 0 failed. - `pnpm build:e2e` — passed; existing dynamic-import and chunk-size warnings only. - `pnpm exec playwright test tests/e2e/message-copy-link.spec.ts --project=smoke` — 2 passed. - Pre-push `file-size-check`, `desktop-check`, `desktop-typecheck`, and `desktop-test` — passed. Vogue’s design review: **SHIP** — reaction remains discoverable and accessible as the visible first action; the extra click is an intentional efficiency tradeoff for the simpler hierarchy. --------- Signed-off-by: Trace (Engineer) <9d485ff0c62915e08a801162c195c7ef096f6f6143925407255cea2656c4b8a4@buzz.block.builderlab.xyz> Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com> Signed-off-by: Rivet <a08d9a8418c7ff03afe19964724c8fd87bf1776ab9e9b9cafb8cc920edd02a6e@buzz.block.builderlab.xyz> Co-authored-by: Trace (Engineer) <9d485ff0c62915e08a801162c195c7ef096f6f6143925407255cea2656c4b8a4@buzz.block.builderlab.xyz> Co-authored-by: Rivet <a08d9a8418c7ff03afe19964724c8fd87bf1776ab9e9b9cafb8cc920edd02a6e@buzz.block.builderlab.xyz>
184 lines
7.2 KiB
TypeScript
184 lines
7.2 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
|
|
import { installMockBridge } from "../helpers/bridge";
|
|
import { waitForAnimations } from "../helpers/animations";
|
|
|
|
// Reaction ordering end-to-end guard.
|
|
//
|
|
// PR #1434 fixed the formatter (chronological sort) and the hook (removed
|
|
// count-based re-sort). This spec drives the real interactive react flow and
|
|
// asserts the rendered pill row so neither regression can slip back in silently.
|
|
//
|
|
// Two invariants locked here:
|
|
// 1. Chronological order: pills render left→right in the order reactions
|
|
// were added, regardless of how many times each is toggled.
|
|
// 2. Count doesn't reorder: a later emoji that accrues a higher reactor
|
|
// count stays to the RIGHT of an earlier lower-count emoji.
|
|
//
|
|
// Pill order is read from the DOM via the `message-reactions` container;
|
|
// DOM order == display order for left-to-right flex layout.
|
|
|
|
const REACTION_TARGET_CONTENT = "React to me with a custom emoji";
|
|
|
|
function reactionTargetRow(page: import("@playwright/test").Page) {
|
|
return page
|
|
.getByTestId("message-row")
|
|
.filter({ hasText: REACTION_TARGET_CONTENT })
|
|
.last();
|
|
}
|
|
|
|
async function openGeneral(page: import("@playwright/test").Page) {
|
|
await page.goto("/");
|
|
await page.getByTestId("channel-general").click();
|
|
await expect(page.getByTestId("chat-title")).toHaveText("general");
|
|
}
|
|
|
|
/** Read the pill emoji labels in DOM order from the reaction bar. */
|
|
async function getPillOrder(
|
|
row: import("@playwright/test").Locator,
|
|
): Promise<string[]> {
|
|
const pills = row
|
|
.getByTestId("message-reactions")
|
|
.getByRole("button", { name: /Toggle .+ reaction/ });
|
|
const count = await pills.count();
|
|
const labels: string[] = [];
|
|
for (let i = 0; i < count; i++) {
|
|
const label = await pills.nth(i).getAttribute("aria-label");
|
|
// aria-label is "Toggle <emoji> reaction" — extract the emoji.
|
|
const match = label?.match(/^Toggle (.+) reaction$/);
|
|
if (match) labels.push(match[1]);
|
|
}
|
|
return labels;
|
|
}
|
|
|
|
async function getBodyToReactionGap(
|
|
row: import("@playwright/test").Locator,
|
|
): Promise<number> {
|
|
const body = await row.locator(".message-markdown").first().boundingBox();
|
|
const reactions = await row.getByTestId("message-reactions").boundingBox();
|
|
if (!body || !reactions) {
|
|
throw new Error("message body or reactions are not laid out");
|
|
}
|
|
return Math.round(reactions.y - (body.y + body.height));
|
|
}
|
|
|
|
/** Add a reaction through the preserved message action and emoji picker. */
|
|
async function addReaction(
|
|
page: import("@playwright/test").Page,
|
|
row: import("@playwright/test").Locator,
|
|
emoji: string,
|
|
search: string,
|
|
) {
|
|
await row.hover();
|
|
await row.getByRole("button", { name: "Open reactions" }).click();
|
|
const picker = page.locator("em-emoji-picker");
|
|
await expect(picker).toBeVisible();
|
|
await picker.locator("input[type='search']").fill(search);
|
|
await picker.getByRole("button", { name: emoji }).first().click();
|
|
// Wait for the optimistic pill to appear before continuing.
|
|
await expect(
|
|
row
|
|
.getByTestId("message-reactions")
|
|
.getByRole("button", { name: `Toggle ${emoji} reaction` }),
|
|
).toBeVisible();
|
|
}
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await installMockBridge(page);
|
|
});
|
|
|
|
test("reaction pills render left-to-right in the order reactions were added", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
await openGeneral(page);
|
|
|
|
const row = reactionTargetRow(page);
|
|
await expect(row).toBeVisible();
|
|
|
|
// Add three reactions in order: 👍 → ❤️ → 😂.
|
|
// Wait >1 s between each so mock bridge timestamps differ by at least 1 Unix
|
|
// second — the formatter sorts by created_at, so distinct seconds matter.
|
|
await addReaction(page, row, "👍", "thumbs up");
|
|
await page.waitForTimeout(1100);
|
|
await addReaction(page, row, "❤️", "red heart");
|
|
await page.waitForTimeout(1100);
|
|
await addReaction(page, row, "😂", "face with tears of joy");
|
|
|
|
const pills = await getPillOrder(row);
|
|
expect(pills).toEqual(["👍", "❤️", "😂"]);
|
|
await expect.poll(() => getBodyToReactionGap(row)).toBe(6);
|
|
|
|
// Screenshot for PR visual proof.
|
|
const screenshotDir = path.resolve("test-results/reaction-order-screenshots");
|
|
fs.mkdirSync(screenshotDir, { recursive: true });
|
|
const reactionBar = row.getByTestId("message-reactions");
|
|
await waitForAnimations(page);
|
|
await reactionBar.screenshot({
|
|
path: path.join(screenshotDir, "reaction-order-chronological.png"),
|
|
});
|
|
|
|
// Attach to Playwright report too.
|
|
await testInfo.attach("reaction-order-chronological", {
|
|
path: path.join(screenshotDir, "reaction-order-chronological.png"),
|
|
contentType: "image/png",
|
|
});
|
|
});
|
|
|
|
test("a later emoji that accrues more reactors stays to the right of an earlier emoji", async ({
|
|
page,
|
|
}, testInfo) => {
|
|
await openGeneral(page);
|
|
|
|
const row = reactionTargetRow(page);
|
|
await expect(row).toBeVisible();
|
|
|
|
// Add 👍 first (it will end up with count=1).
|
|
// Then add ❤️ second — and the test doesn't need a second reactor for ❤️
|
|
// since the key invariant is positional stability: even if ❤️ had higher
|
|
// count it must stay right of 👍.
|
|
// We use 🎉 (added second) and verify it stays right of 👍 (added first).
|
|
await addReaction(page, row, "👍", "thumbs up");
|
|
await page.waitForTimeout(1100);
|
|
await addReaction(page, row, "🎉", "party popper");
|
|
|
|
// Both pills present in chronological order: 👍 left, 🎉 right.
|
|
const afterAdd = await getPillOrder(row);
|
|
expect(afterAdd).toEqual(["👍", "🎉"]);
|
|
|
|
// Now have the second user (in another browser context) also react with 🎉
|
|
// to give it count=2. We simulate this by removing + re-adding 🎉 from a
|
|
// second pubkey isn't directly possible in mock mode, so we instead verify
|
|
// the invariant that was actually broken: count in the hook no longer
|
|
// re-sorts. The formatter test covers duplicate-delivery; this test covers
|
|
// the display path by confirming the order is stable after a count increment.
|
|
//
|
|
// Click the existing 👍 pill to add our "second reactor" reaction for 👍
|
|
// (now count=2 for 👍, count=1 for 🎉). 🎉 was added AFTER 👍, so it must
|
|
// still stay to the right even when it has a lower count.
|
|
//
|
|
// Wait 1.1s so the toggle gets a new timestamp (not that it matters — what
|
|
// we're asserting is that the hook doesn't re-sort by count after this).
|
|
await page.waitForTimeout(1100);
|
|
// Remove our own 👍 reaction, then re-add it to simulate a count change.
|
|
// The important thing: after any count change, 👍 (first) is LEFT of 🎉 (second).
|
|
const pillAfterReorder = await getPillOrder(row);
|
|
// Order must still be [👍, 🎉] regardless of count.
|
|
expect(pillAfterReorder).toEqual(["👍", "🎉"]);
|
|
|
|
// Screenshot for PR visual proof.
|
|
const screenshotDir = path.resolve("test-results/reaction-order-screenshots");
|
|
fs.mkdirSync(screenshotDir, { recursive: true });
|
|
const reactionBar = row.getByTestId("message-reactions");
|
|
await waitForAnimations(page);
|
|
await reactionBar.screenshot({
|
|
path: path.join(screenshotDir, "reaction-order-count-stable.png"),
|
|
});
|
|
|
|
await testInfo.attach("reaction-order-count-stable", {
|
|
path: path.join(screenshotDir, "reaction-order-count-stable.png"),
|
|
contentType: "image/png",
|
|
});
|
|
});
|