|
1 | | -import { expect, test } from "@playwright/test"; |
| 1 | +import { expect, test, type Locator } from "@playwright/test"; |
2 | 2 |
|
3 | 3 | import { truncateNpub } from "../../src/shared/lib/pubkey"; |
4 | 4 | import { waitForAnimations } from "../helpers/animations"; |
@@ -88,6 +88,43 @@ const JOIN_COLLAPSE_CAPTURE_WIDTH = 560; |
88 | 88 | const JOIN_COLLAPSE_CAPTURE_HEIGHT = 260; |
89 | 89 | const JOIN_COLLAPSE_CAPTURE_VERTICAL_PADDING = 24; |
90 | 90 |
|
| 91 | +async function timelineChipLayout(chip: Locator) { |
| 92 | + return chip.evaluate((element) => { |
| 93 | + const paragraph = element.closest("p"); |
| 94 | + if (!paragraph) throw new Error("Timeline chip is missing its paragraph"); |
| 95 | + const chipBounds = element.getBoundingClientRect(); |
| 96 | + const paragraphBounds = paragraph.getBoundingClientRect(); |
| 97 | + const chipFragmentRects = Array.from(element.getClientRects()) |
| 98 | + .filter((rect) => rect.width > 0 && rect.height > 0) |
| 99 | + .sort((a, b) => a.top - b.top); |
| 100 | + const chipStyle = getComputedStyle(element); |
| 101 | + return { |
| 102 | + boxDecorationBreak: |
| 103 | + chipStyle.getPropertyValue("box-decoration-break") || |
| 104 | + chipStyle.getPropertyValue("-webkit-box-decoration-break"), |
| 105 | + chipHeight: chipBounds.height, |
| 106 | + chipLineHeight: Number.parseFloat(chipStyle.lineHeight), |
| 107 | + fragmentCount: chipFragmentRects.length, |
| 108 | + fragmentGap: |
| 109 | + chipFragmentRects.length > 1 |
| 110 | + ? Math.round(chipFragmentRects[1].top - chipFragmentRects[0].bottom) |
| 111 | + : null, |
| 112 | + fragmentHeight: |
| 113 | + chipFragmentRects.length > 0 |
| 114 | + ? Math.round(chipFragmentRects[0].height) |
| 115 | + : null, |
| 116 | + fragmentStep: |
| 117 | + chipFragmentRects.length > 1 |
| 118 | + ? Math.round(chipFragmentRects[1].top - chipFragmentRects[0].top) |
| 119 | + : null, |
| 120 | + paragraphHeight: paragraphBounds.height, |
| 121 | + paragraphLineHeight: Number.parseFloat( |
| 122 | + getComputedStyle(paragraph).lineHeight, |
| 123 | + ), |
| 124 | + }; |
| 125 | + }); |
| 126 | +} |
| 127 | + |
91 | 128 | /** Locator scoped to the mention autocomplete dropdown inside the composer. */ |
92 | 129 | function autocomplete(page: import("@playwright/test").Page) { |
93 | 130 | return page |
@@ -1583,6 +1620,19 @@ test("selecting a persona mention creates a channel agent before sending and sta |
1583 | 1620 | .locator("[data-mention].agent-mention-highlight", { hasText: "Fizz" }); |
1584 | 1621 | await expect(mentionChip).toBeVisible(); |
1585 | 1622 | await expect(mentionChip).toHaveText("Fizz"); |
| 1623 | + await expect(mentionChip).toHaveClass(/wrapping-inline-chip/); |
| 1624 | + const timelineLayout = await timelineChipLayout(mentionChip); |
| 1625 | + expect(timelineLayout).toMatchObject({ |
| 1626 | + boxDecorationBreak: "clone", |
| 1627 | + chipHeight: 17, |
| 1628 | + chipLineHeight: 18, |
| 1629 | + fragmentCount: 1, |
| 1630 | + fragmentGap: null, |
| 1631 | + fragmentHeight: 17, |
| 1632 | + fragmentStep: null, |
| 1633 | + paragraphHeight: 20, |
| 1634 | + paragraphLineHeight: 20, |
| 1635 | + }); |
1586 | 1636 | }); |
1587 | 1637 |
|
1588 | 1638 | test("selecting a persona mention reuses an existing persona agent", async ({ |
@@ -4518,6 +4568,67 @@ test("mention text is highlighted in sent messages", async ({ page }) => { |
4518 | 4568 | await expect(mentionChip).toBeVisible(); |
4519 | 4569 | await expect(mentionChip).toHaveText("bob"); |
4520 | 4570 | await expect(mentionChip).toHaveClass(/inline-chip-icon-human/); |
| 4571 | + await expect(mentionChip).toHaveClass(/wrapping-inline-chip/); |
| 4572 | + |
| 4573 | + const timelineLayout = await timelineChipLayout(mentionChip); |
| 4574 | + expect(timelineLayout).toMatchObject({ |
| 4575 | + boxDecorationBreak: "clone", |
| 4576 | + chipHeight: 17, |
| 4577 | + chipLineHeight: 18, |
| 4578 | + fragmentCount: 1, |
| 4579 | + fragmentGap: null, |
| 4580 | + fragmentHeight: 17, |
| 4581 | + fragmentStep: null, |
| 4582 | + paragraphHeight: 20, |
| 4583 | + paragraphLineHeight: 20, |
| 4584 | + }); |
| 4585 | +}); |
| 4586 | + |
| 4587 | +test("qualified mentions wrap without changing message line rhythm", async ({ |
| 4588 | + page, |
| 4589 | +}) => { |
| 4590 | + const pubkey = TEST_IDENTITIES.bob.pubkey; |
| 4591 | + const qualifiedLabel = `bob (${pubkey})`; |
| 4592 | + |
| 4593 | + await page.goto("/"); |
| 4594 | + await page.getByTestId("channel-general").click(); |
| 4595 | + await expect(page.getByTestId("chat-title")).toHaveText("general"); |
| 4596 | + await waitForMockLiveSubscription(page, "general"); |
| 4597 | + await emitMockMessage(page, "general", `@${qualifiedLabel}`, { |
| 4598 | + mentionPubkeys: [pubkey], |
| 4599 | + }); |
| 4600 | + await waitForTimelineSettled(page); |
| 4601 | + |
| 4602 | + const row = page.getByTestId("message-row").filter({ hasText: "bob" }).last(); |
| 4603 | + await row.evaluate((element) => { |
| 4604 | + const prose = element.querySelector<HTMLElement>(".message-markdown"); |
| 4605 | + if (!prose) |
| 4606 | + throw new Error("Qualified mention is missing its prose wrapper"); |
| 4607 | + prose.style.width = "8rem"; |
| 4608 | + }); |
| 4609 | + const mentionChip = row.locator("[data-mention]", { hasText: "bob" }); |
| 4610 | + await expect(mentionChip).toHaveText(/bob \(npub1hv3…tpuc\)/); |
| 4611 | + await expect(mentionChip).toHaveClass(/wrapping-inline-chip/); |
| 4612 | + |
| 4613 | + const layout = await timelineChipLayout(mentionChip); |
| 4614 | + expect(layout.boxDecorationBreak).toBe("clone"); |
| 4615 | + expect(layout.chipLineHeight).toBe(18); |
| 4616 | + expect(layout.fragmentCount).toBe(2); |
| 4617 | + expect(layout.fragmentHeight).toBe(17); |
| 4618 | + expect(layout.fragmentGap).toBeGreaterThanOrEqual(1); |
| 4619 | + expect(layout.fragmentStep).toBe(20); |
| 4620 | + expect(layout.paragraphLineHeight).toBe(20); |
| 4621 | + expect(layout.chipHeight).toBeLessThanOrEqual( |
| 4622 | + layout.fragmentCount * layout.paragraphLineHeight, |
| 4623 | + ); |
| 4624 | + |
| 4625 | + const trigger = mentionChip.locator("xpath=.."); |
| 4626 | + await expect(trigger).toHaveCSS("display", "inline"); |
| 4627 | + await expect(trigger).toHaveAttribute("role", "button"); |
| 4628 | + await trigger.focus(); |
| 4629 | + await expect(trigger).toBeFocused(); |
| 4630 | + await trigger.press("Enter"); |
| 4631 | + await expect(page.getByTestId("user-profile-panel")).toBeVisible(); |
4521 | 4632 | }); |
4522 | 4633 |
|
4523 | 4634 | test("clicking author name opens user profile panel", async ({ page }) => { |
|
0 commit comments