Skip to content

test(measurements): add DOM assertions for measurement annotation text#6129

Open
GhadeerAlbattarni wants to merge 3 commits into
OHIF:masterfrom
GhadeerAlbattarni:test/measurement-annotation-text-assertions
Open

test(measurements): add DOM assertions for measurement annotation text#6129
GhadeerAlbattarni wants to merge 3 commits into
OHIF:masterfrom
GhadeerAlbattarni:test/measurement-annotation-text-assertions

Conversation

@GhadeerAlbattarni

@GhadeerAlbattarni GhadeerAlbattarni commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Context

Adds DOM-based annotation text assertions for measurement tools, following the pattern established in ArrowAnnotate.spec.ts.

Changes & Results

  • Add tests/utils/expectAnnotationText.ts with expectAnnotationStatsText and measurementTextFormatters to assert measurement text from cachedStats in the panel and viewport SVG
  • Update measurement specs: Length, Bidirectional, Angle, CobbAngle, Circle, Ellipse, Rectangle, Probe
  • Refactor ArrowAnnotate.spec.ts
  • Export new helpers from tests/utils/index.ts

Implementation notes

  • Panel and SVG formatting can differ per tool (e.g. area panel line vs Area: SVG prefix; CobbAngle panel uses roundNumber, SVG uses toFixed(2)).
  • assertStats in each spec adds numeric/unit sanity checks on raw cachedStats.
  • roundNumber is copied rather than imported because the root Playwright E2E harness does not resolve @ohif/core workspace imports in Node.

Testing

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • OS: macOS 10.15.4
  • Node version: v22.22.0
  • Browser: Chrome 83.0.4103.116

Summary by CodeRabbit

  • Tests
    • Expanded measurement tool coverage across angle, bidirectional, circle, cobb angle, ellipse, length, probe, rectangle, and arrow annotations.
    • Added stronger assertions for displayed values in the measurements panel and viewport, including units, rounding, and numeric formatting.
    • Introduced shared test helpers for checking annotation labels and statistics consistently across tools.

Add expectAnnotationStatsText and shared measurementTextFormatters so
measurement E2E tests verify displayed text from cachedStats instead of
relying on screenshots alone. Mirrors the multi-surface assertion pattern
from ArrowAnnotate.spec.ts for stats-based tools (Length, Bidirectional,
Angle, CobbAngle, Circle, Ellipse, Rectangle, Probe).

Includes a vendored roundNumber helper (copied from platform/core) because
the Playwright harness cannot import @ohif/core at runtime.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@netlify

netlify Bot commented Jul 8, 2026

Copy link
Copy Markdown

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit 6cc48b9
🔍 Latest deploy log https://app.netlify.com/projects/ohif-dev/deploys/6a4eaf5e7b022d00087e55d3
😎 Deploy Preview https://deploy-preview-6129--ohif-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A shared Playwright utility module (expectAnnotationText.ts) is added, providing expectAnnotationLabelText, expectAnnotationStatsText, and measurementTextFormatters, re-exported via tests/utils/index.ts. Multiple tool spec files (Angle, ArrowAnnotate, Bidirectional, Circle, CobbAngle, Ellipse, Length, Probe, Rectangle) are updated to use these utilities for validating annotation labels and stats text in the measurements panel and SVG.

Changes

Annotation text assertion utilities and tool test integration

Layer / File(s) Summary
Shared annotation text assertion utilities
tests/utils/expectAnnotationText.ts, tests/utils/index.ts
New module exports expectAnnotationLabelText, expectAnnotationStatsText, and measurementTextFormatters, using a vendored roundNumber and annotation resolution by UID or index; re-exported from the utils index.
ArrowAnnotate label assertions refactor
tests/ArrowAnnotate.spec.ts
Replaces the file-local arrow text helper with expectAnnotationLabelText across the initial entry, dialog update, and side-panel rename assertions.
Measurement tool specs adopt annotation stats assertions
tests/Angle.spec.ts, tests/Bidirectional.spec.ts, tests/Circle.spec.ts, tests/CobbAngle.spec.ts, tests/Ellipse.spec.ts, tests/Length.spec.ts, tests/Probe.spec.ts, tests/Rectangle.spec.ts
Reformats ./utils imports, adds rightPanelPageObject to fixtures, selects the measurements panel, and asserts tool-specific stats (units, rounded values) via expectAnnotationStatsText and measurementTextFormatters.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • OHIF/Viewers#6067: Both PRs touch the ArrowAnnotate test's label/stats verification flow, overlapping with the shared assertion utilities introduced here.

Suggested reviewers: jbocce

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, semantic-release compliant, and accurately summarizes the main change to measurement annotation text assertions.
Description check ✅ Passed The PR description covers context, changes, checklist, and testing environment, though the Testing section itself is left empty.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/utils/expectAnnotationText.ts (1)

244-244: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

cobbAngleSvgLine and probeIndexSvgLine throw on undefined stats, unlike other formatters.

Most formatters route through roundNumber, which returns 'NaN' for undefined/null/empty values. These two call .toFixed() and .join() directly on as-cast values, producing a TypeError instead of a readable assertion failure if the stat is missing.

🛡️ Optional guard for consistent error behavior
 cobbAngleSvgLine: (stats: TargetStats) =>
-  `${(stats.angle as number).toFixed(2)} \u00B0`,
+  `${roundNumber(stats.angle as number, 2)} \u00B0`,

Note: roundNumber uses adaptive precision, not fixed 2 d.p., so this would change the output for angles outside the 1–9.9° range. If fixed 2 d.p. is required, add a guard instead:

 cobbAngleSvgLine: (stats: TargetStats) =>
-  `${(stats.angle as number).toFixed(2)} \u00B0`,
+  `${(Number(stats.angle ?? NaN)).toFixed(2)} \u00B0`,
 probeIndexSvgLine: (stats: TargetStats) => `(${(stats.index as number[]).join(', ')})`,
+  probeIndexSvgLine: (stats: TargetStats) => `(${((stats.index as number[] | undefined) ?? []).join(', ')})`,

Also applies to: 276-276

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/utils/expectAnnotationText.ts` at line 244, The `cobbAngleSvgLine` and
`probeIndexSvgLine` formatters are bypassing the shared undefined/null handling
used by the other helpers and can throw TypeError when `stats` is missing.
Update these formatters in `expectAnnotationText` to use the same safe
formatting path as the other svg line helpers, or add an explicit guard before
calling `.toFixed()`/`.join()` so missing values yield a readable assertion
result instead of crashing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/utils/expectAnnotationText.ts`:
- Line 244: The `cobbAngleSvgLine` and `probeIndexSvgLine` formatters are
bypassing the shared undefined/null handling used by the other helpers and can
throw TypeError when `stats` is missing. Update these formatters in
`expectAnnotationText` to use the same safe formatting path as the other svg
line helpers, or add an explicit guard before calling `.toFixed()`/`.join()` so
missing values yield a readable assertion result instead of crashing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a9144a39-5501-4507-9bd9-ec9bc85a9375

📥 Commits

Reviewing files that changed from the base of the PR and between b996070 and 6cc48b9.

📒 Files selected for processing (11)
  • tests/Angle.spec.ts
  • tests/ArrowAnnotate.spec.ts
  • tests/Bidirectional.spec.ts
  • tests/Circle.spec.ts
  • tests/CobbAngle.spec.ts
  • tests/Ellipse.spec.ts
  • tests/Length.spec.ts
  • tests/Probe.spec.ts
  • tests/Rectangle.spec.ts
  • tests/utils/expectAnnotationText.ts
  • tests/utils/index.ts

Comment thread tests/Ellipse.spec.ts
],
assertStats: stats => {
expect(stats.areaUnit).toBe('mm²');
expect(Math.round(stats.area as number)).toBe(16778);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbocce I found the value for this area is different from the value that is in the current screenshot. If this is the right one, then we might need to update the screenshot as well.

@GhadeerAlbattarni
GhadeerAlbattarni requested a review from jbocce July 9, 2026 06:39
assertStats: stats => {
expect(stats.unit).toBe('mm');
expect(Math.round(stats.length as number)).toBe(195);
expect(Math.round(stats.width as number)).toBe(130);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbocce I do think It's good to pass hardcoded numbers to assert the stats as well. If you agree with that I can update the rest of the tests in this PR to do the same.

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