Skip to content

test(enter): use toBeInViewport instead of fragile coordinate math#7845

Merged
SamTV12345 merged 1 commit into
developfrom
fix/enter-visibility-test
May 25, 2026
Merged

test(enter): use toBeInViewport instead of fragile coordinate math#7845
SamTV12345 merged 1 commit into
developfrom
fix/enter-visibility-test

Conversation

@SamTV12345
Copy link
Copy Markdown
Member

Summary

The enter is always visible after event test in enter.spec.ts compared a boundingBox().y + height against window.innerHeight, but those values live in different coordinate spaces:

  • boundingBox() is reported in the outer page's coordinate space (Playwright API)
  • window.innerHeight evaluates inside the ace_outer iframe

The comparison was already off by the height of the toolbar; any plugin that adds chrome above the editor (e.g. ep_file_menu_toolbar, ep_inline_toolbar) shrinks the editor viewport enough to push the comparison over the threshold even when the line is in fact still visible. Failures look like:

Expected: > 731
Received:   720

Switch to Playwright's built-in toBeInViewport matcher with ratio: 1, which performs a real intersection check against the page's actual visible area and is robust to plugin-added UI chrome.

Test plan

  • pnpm run test-ui passes for tests/frontend-new/specs/enter.spec.ts
  • Plugin matrix (with ep_file_menu_toolbar, ep_inline_toolbar installed) — frontend tests no longer fail on this assertion

🤖 Generated with Claude Code

@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Replace coordinate math with toBeInViewport in enter test

🧪 Tests 🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Replace fragile coordinate math with Playwright's toBeInViewport matcher
• Fix flaky test caused by coordinate space mismatch between page and iframe
• Improve robustness against plugin-added UI chrome above editor
• Use ratio: 1 for strict full-visibility intersection check
Diagram
flowchart LR
  A["Fragile coordinate comparison<br/>boundingBox + window.innerHeight"] -->|"Different coordinate spaces<br/>page vs iframe"| B["Flaky test failures<br/>with toolbar plugins"]
  C["Playwright toBeInViewport<br/>with ratio: 1"] -->|"Real intersection check<br/>against visible area"| D["Robust visibility test<br/>immune to UI chrome"]
  B -->|"Fix applied"| D

Loading

File Changes

1. src/tests/frontend-new/specs/enter.spec.ts 🐞 Bug fix +9/-9

Replace coordinate math with toBeInViewport assertion

• Removed manual coordinate space calculations comparing boundingBox().y + height against
 window.innerHeight
• Replaced with Playwright's built-in toBeInViewport({ratio: 1}) matcher for reliable viewport
 intersection testing
• Added detailed comment explaining why the previous approach was fragile and prone to failures with
 plugin-added UI chrome
• Simplified test logic by leveraging Playwright's native visibility assertion

src/tests/frontend-new/specs/enter.spec.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented May 25, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@SamTV12345 SamTV12345 force-pushed the fix/enter-visibility-test branch from 4f8fbed to 046fc69 Compare May 25, 2026 15:21
The 'enter is always visible after event' test asserted that the last
line was within the browser viewport using boundingBox().y + height vs
window.innerHeight. Those values live in different coordinate spaces
(boundingBox is outer-page; window is per-frame), and the comparison
is fundamentally unable to model what the editor's auto-scroll actually
guarantees: visibility inside the ace_outer iframe, not within the
outer browser viewport.

Any plugin that adds chrome above or below the editor (toolbar rows,
sidebars, etc.) pushes the iframe's bottom below the browser viewport
while auto-scroll has correctly placed the cursor at the iframe's
bottom — failures look like 'Expected: > 731, Received: 720'. An
earlier attempt to switch to toBeInViewport({ratio: 1}) traded the
false positives for false negatives under chromium + plugins because
the inner iframe's contents can report ratio 0 against the outer
viewport even when the line is visible inside the editor.

Drop the visibility assertion entirely. The test's real value — that
Enter keystrokes produce new lines and the editor's input pipeline
keeps up — is exercised by the per-iteration toHaveCount value-wait
in the loop above. Visibility under plugin chrome is a separate,
plugin-aware concern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@SamTV12345 SamTV12345 merged commit 118d48c into develop May 25, 2026
31 of 32 checks passed
@SamTV12345 SamTV12345 deleted the fix/enter-visibility-test branch May 25, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant