Skip to content

test(contour): Livewire contour draw coverage - #6206

Open
diattamo wants to merge 9 commits into
OHIF:masterfrom
diattamo:test/livewire-contour-completed-draw
Open

test(contour): Livewire contour draw coverage#6206
diattamo wants to merge 9 commits into
OHIF:masterfrom
diattamo:test/livewire-contour-completed-draw

Conversation

@diattamo

@diattamo diattamo commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Context

LivewireContourSegmentation.spec.ts currently covers only one path — cancelling an
in-progress contour with Escape. Nothing verified that a Livewire contour can actually be
completed, or how completed contours behave once they land in a segment.

This PR expands the spec to cover the completed-draw behaviors: persistence across slice and
segment navigation, tool enablement, segment ownership, and the three boolean outcomes of
drawing a second contour into the same segment (disjoint, overlapping, and hole-cutting with
Shift).

Changes & Results

Test-only change — no production code touched.

  • tests/LivewireContourSegmentation.spec.ts — 6 new tests, plus the existing Escape
    test retuned to a shared 4-point contourClicks polygon (large enough to leave room for a
    hole inside it, and clear of neighbouring outlines):
    • persists after navigating away and back — draws a contour, closes it by
      double-clicking the last vertex, captures the SVG path d attribute, navigates to the
      last slice, then reselects Segment 1 and asserts the re-rendered geometry is byte-identical.
    • tool enablement — Livewire is disabled with no contour segmentation and becomes
      enabled once one is created.
    • draws into the active segment — contour drawn while Segment 2 is active survives
      hiding Segment 1 and disappears/reappears with Segment 2's visibility toggle.
    • disjoint contours stay separate — two non-touching contours in one segment render as
      two paths.
    • overlapping contours merge — a second contour crossing the first collapses to a
      single path.
    • Shift cuts a hole — an inner contour drawn with Shift held is subtracted into the
      same path rather than added as a new one.
  • tests/pages/RightPanelPageObject.ts — expose livewireContour.livewireToolButton.
    The data-cy element is a span wrapper (so its tooltip still fires while the tool is
    unavailable); the inner -btn element is what carries the disabled state, so enablement is
    asserted against that.
  • tests/utils/keyboardUtils.ts — add keyDown/keyUp so a modifier can be held across
    mouse interactions (needed for the Shift hole-cutting flow).
  • tests/utils/screenShotPaths.ts + 3 baselines — the boolean outcomes (merge, hole) are
    canvas-only, so those three tests back the SVG path-count assertion with a
    viewport-scoped screenshot compare.
  • .agents/skills/ohif-test-agent/SKILL.md — the "never substitute a state read for a
    render assertion" rule now names cornerstone state (window.cornerstone,
    window.cornerstoneTools) alongside window.services, and points at a viewport-scoped
    screenshot as the default when no DOM/SVG signal captures the result (contour geometry,
    merges, holes).

Testing

cross-env TEST_ENV=true pnpm exec playwright test tests/LivewireContourSegmentation.spec.ts

All 7 tests pass locally (Chromium).

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 26.5.1
  • Node version: 25.4.0
  • Browser: Chromium (Playwright)

Summary by CodeRabbit

  • Tests
    • Expanded Livewire contour segmentation coverage for cancellation, redraw, navigation persistence, visibility, segment assignment, and tool prerequisites.
    • Added tests for disjoint contours, same-segment overlap merging, cross-segment separation, and Shift-based hole creation.
    • Added visual verification for overlapping contours, holes, and separate segment contours.
    • Improved keyboard interaction testing, including held modifier keys.
    • Added coverage for disabled and enabled tool states.

@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 Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit 0fcd7fe
🔍 Latest deploy log https://app.netlify.com/projects/ohif-dev/deploys/6a7f1b21d82fcc0008b9eeaf
😎 Deploy Preview https://deploy-preview-6206--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.

@diattamo
diattamo temporarily deployed to fork-pr-approval August 5, 2026 19:18 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c5e9dc7-00ea-4b72-9f05-ef135f063b7c

📥 Commits

Reviewing files that changed from the base of the PR and between 2631e12 and 0fcd7fe.

⛔ Files ignored due to path filters (1)
  • tests/screenshots/chromium/LivewireContourSegmentation.spec.ts/differentSegmentsContoursSeparate.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • tests/LivewireContourSegmentation.spec.ts
  • tests/utils/keyboardUtils.ts
  • tests/utils/screenShotPaths.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/utils/screenShotPaths.ts
  • tests/utils/keyboardUtils.ts

📝 Walkthrough

Walkthrough

Expanded Livewire contour segmentation tests cover lifecycle, slice persistence, segment visibility, disjoint and overlapping contours, and Shift-based holes. Added keyboard, locator, utility export, and screenshot path support.

Changes

Livewire contour testing

Layer / File(s) Summary
Livewire test foundations
tests/LivewireContourSegmentation.spec.ts, tests/utils/keyboardUtils.ts, tests/pages/RightPanelPageObject.ts, tests/utils/index.ts, tests/utils/screenShotPaths.ts
Added shared contour coordinates, safe held-key handling, direct tool-button state access, utility exports, and screenshot paths.
Livewire lifecycle and segment state
tests/LivewireContourSegmentation.spec.ts
Added coverage for cancellation, redraw, slice navigation, tool prerequisites, active-segment assignment, and segment visibility.
Livewire contour geometry
tests/LivewireContourSegmentation.spec.ts
Added coverage for disjoint contours, overlapping contours, and Shift-created holes with SVG and screenshot assertions.

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

Merge Risk: ⚪ Minimal · up to 0fcd7

This PR adds localized Livewire contour coverage without changing production behavior, and no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the test-focused Livewire contour drawing coverage and follows the repository's semantic-release format.
Description check ✅ Passed The description includes context, detailed changes, testing instructions, results, and completed checklist items.
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.

@diattamo diattamo changed the title Test/livewire contour completed draw test(contour): Livewire contour draw coverage Aug 5, 2026
@diattamo
diattamo temporarily deployed to fork-pr-approval August 5, 2026 19:24 — with GitHub Actions Inactive
@diattamo
diattamo temporarily deployed to fork-pr-approval August 5, 2026 20:03 — with GitHub Actions Inactive
@diattamo
diattamo temporarily deployed to fork-pr-approval August 5, 2026 20:18 — with GitHub Actions Inactive
@diattamo
diattamo deployed to fork-pr-approval August 12, 2026 13:13 — with GitHub Actions Active
@diattamo
diattamo deployed to fork-pr-approval August 14, 2026 13:41 — with GitHub Actions Active
// The data-cy element above is a span wrapper, so its tooltip still
// fires while the tool is unavailable. The inner button is what
// carries the disabled state, so assert enablement against this.
toolButton: page.getByTestId('LivewireContourSegmentationTool-btn'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a bit confusing to have "two buttons" for the same page object. Can we consolidate to one? I suspect 'LivewireContourSegmentationTool-btn' could be used for clicking too, but I might be wrong. Thanks.

await contourPanel.select();

await expect(
contourPanel.tools.livewireContour.toolButton,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With regards to my earlier comment regarding "two buttons". I suppose we have to watch for things like this too (i.e. checking for disabled). However we could get around this by adding a page object method like isEnab led or whatever.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This and the other screenshots have text in them. This is now a no-no. Do we need to update the agent skills to reflect this?

'Expected the second contour vertex handles to clear on completion'
).toHaveCount(0);

await checkForScreenshot({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we want to check for viewport screenshot here, but shouldn't we also check for a single path too (i.e. path count is exactly one)?

viewportPageObject,
}) => {
// Same overlap geometry as the same-segment merge test; across segments it must not merge.
const overlappingContourClicks = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is declared twice. Is it worth refactoring to a constant?

).toHaveCount(0);

// The overlap that merges within one segment must stay two outlines across segments.
await checkForViewportScreenshot({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we also check for two paths?

'Expected the hole vertex handles to clear on completion'
).toHaveCount(0);

await checkForScreenshot({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe also check for one path?

* throws. A held modifier (e.g. 'Shift') applies to the mouse events the action
* performs, which is how modifier-dependent tools are driven from a test.
*/
export const withKeyHeld = async (params: WithKeyHeldParams) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please do a quick check if this could be useful elsewhere (i.e. is there some place else we are doing something similar in the tests already)?

@jbocce jbocce left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See my suggestions and comments. Thanks so much.

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.

2 participants