-
-
Notifications
You must be signed in to change notification settings - Fork 709
fix: add link on commented text removes the comment highlight (2573) #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { expect } from "@playwright/test"; | ||
| import { test } from "../../setup/setupScript.js"; | ||
| import { BASE_URL, LINK_BUTTON_SELECTOR } from "../../utils/const.js"; | ||
| import { focusOnEditor } from "../../utils/editor.js"; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto(BASE_URL); | ||
| }); | ||
|
|
||
| test.describe("Check Link Toolbar functionality", () => { | ||
| test("Should preserve existing marks when editing a link", async ({ | ||
| page, | ||
| }) => { | ||
| await focusOnEditor(page); | ||
|
|
||
| // Type bold text | ||
| await page.keyboard.type("hello"); | ||
| await page.keyboard.press("Shift+Home"); | ||
|
|
||
| // Make it bold via formatting toolbar | ||
| await page.waitForSelector(`[data-test="bold"]`); | ||
| await page.click(`[data-test="bold"]`); | ||
|
|
||
| // Add link | ||
| await page.keyboard.press("Shift+Home"); | ||
| await page.waitForSelector(LINK_BUTTON_SELECTOR); | ||
| await page.click(LINK_BUTTON_SELECTOR); | ||
| await page.keyboard.type("https://example.com"); | ||
| await page.keyboard.press("Enter"); | ||
|
|
||
| // Move cursor back onto the linked text to trigger link toolbar | ||
| await page.keyboard.press("ArrowLeft"); | ||
| await page.waitForTimeout(500); | ||
|
|
||
| // Click Edit link button | ||
| const editButton = page.getByText("Edit link"); | ||
| await editButton.waitFor({ state: "visible" }); | ||
| await editButton.click(); | ||
|
|
||
| await page.keyboard.press("Control+A"); | ||
| await page.keyboard.type("https://example2.com"); | ||
| await page.keyboard.press("Enter"); | ||
|
|
||
| await page.waitForTimeout(300); | ||
|
|
||
| // Verify bold mark is still present on the text | ||
| const boldText = page.locator("strong a, a strong"); | ||
| await expect(boldText).toBeVisible(); | ||
| }); | ||
|
Comment on lines
+11
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regression test does not cover the reported comment-mark bug. Line 11 onward validates Please add a scenario that creates commented text first, then adds/edits a link and verifies the comment highlight/association remains. 🧰 Tools🪛 ESLint[error] 36-36: Avoid destructuring queries from (testing-library/prefer-screen-queries) 🤖 Prompt for AI Agents |
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
For Playwright tests, what are robust selector patterns to assert nested formatted text relationships (e.g., bold + link on the same node) without broad false-positive CSS matches?💡 Result:
Robust selector patterns in Playwright for asserting nested formatted text relationships (e.g., bold + link on the same node) prioritize precise, structure-aware locators over broad CSS to avoid false positives. Key patterns from official docs and best practices: 1. Use CSS :has pseudo-class for parent-child relationships: e.g., page.locator('p:has(strong):has(a)') selects paragraphs containing both bold () and link () children. Combine with :has-text for content: 'p:has-text("Important"):has(strong a)'. 2. Chain locators with filter: Start with a container, filter by nested elements. e.g.: const container = page.getByRole('paragraph'); const formatted = container.filter({ has: page.locator('strong:has(a)') }); await expect(formatted).toBeVisible; 3. Locator chaining with >> : e.g., 'article >> strong >> a' for bold containing link, or '*article >> strong >> a' to keep the article. Use :text or :text-is for precise text matching within: 'article :text("Click"):has(a)'. 4. Assertions for formatting: Use expect(locator).toHaveCSS('font-weight', 'bold') on links or text nodes to verify styles without class dependencies. For structure, expect(locator).toContainText or .toHaveText with regex, combined with .locator('strong').toBeVisible. 5. Best practices to avoid false positives: - Prefer role/text locators over pure CSS: page.getByRole('link', { name: /regex/ }).locator('..').locator('strong'). - Add data-testid to formatted containers: '[data-testid="bold-link"]'. - Use :visible and nth-match for specificity: 'strong:visible:nth-match(1):has(a)'. - Avoid deep CSS chains or brittle classes; test user-visible structure. These ensure assertions pass only when exact nested formatting exists, resilient to style/CSS changes.
Citations:
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 119
🏁 Script executed:
sed -n '1,70p' tests/src/end-to-end/linktoolbar/linktoolbar.test.tsRepository: TypeCellOS/BlockNote
Length of output: 1691
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 46
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 431
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 5820
🏁 Script executed:
rg 'page\.locator\([^,]+,\s*{' tests/src/end-to-end/ -A 3Repository: TypeCellOS/BlockNote
Length of output: 177
🏁 Script executed:
rg 'page\.locator.*hasText' tests/src/end-to-end/ -A 2Repository: TypeCellOS/BlockNote
Length of output: 46
🏁 Script executed:
Repository: TypeCellOS/BlockNote
Length of output: 304
Tighten the assertion to verify both the updated URL and preserved formatting.
The selector
strong a, a strongis too broad and could match unrelated bold links on the page. It should verify that the edited link has the new URL (https://example2.com) and the text remains bold+linked.✅ More specific assertion
📝 Committable suggestion
🤖 Prompt for AI Agents