Skip to content

Commit 4bdb2bd

Browse files
committed
test(e2e): assert ultrasound spacing via ruler tool
The Data panel only renders Spacing for non-DICOM images (ImageDataBrowser filters via isRegularImage), so a US DICOM never produces a "Spacing: (...)" caption — earlier attempts to assert against that surface failed on a clean CI run. Drop a ruler at a known canvas-pixel offset and read the measurement from the Annotations panel. With the spacing fix the ruler reports ~49 mm at the shared 1200×800 viewport; without the fix the 1 mm/px fallback would yield ~97 mm. A wide ±8 mm tolerance absorbs runner-to-runner canvas jitter while still excluding the fallback.
1 parent 06bb548 commit 4bdb2bd

1 file changed

Lines changed: 18 additions & 40 deletions

File tree

tests/specs/ultrasound-spacing.e2e.ts

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,37 @@ import { US_MULTIFRAME_DICOM } from './configTestUtils';
22
import { openUrls } from './utils';
33
import { volViewPage } from '../pageobjects/volview.page';
44

5-
const clickAt = async (x: number, y: number) => {
6-
await browser
7-
.action('pointer')
8-
.move({ x: Math.round(x), y: Math.round(y) })
9-
.down()
10-
.up()
11-
.perform();
12-
};
13-
14-
// Offset between the two ruler clicks (in canvas pixels).
15-
// The measured ruler length in mm depends on this offset, the canvas size,
16-
// and the image spacing. With the US spacing fix the VTK spacing comes from
17-
// SequenceOfUltrasoundRegions (~0.5105 mm); without the fix it falls back to
18-
// 1.0 mm, which makes the measured length ~1.96x larger.
19-
const CLICK_DX = 0;
5+
// Vertical ruler in canvas pixels. The reported length in mm depends on
6+
// canvas size, image-fit zoom, and the applied spacing. With the fix the
7+
// VTK spacing comes from SequenceOfUltrasoundRegions (~0.5105 mm/image-px);
8+
// without the fix it falls back to 1 mm/image-px and the ruler reports
9+
// roughly 1.96× the with-fix value.
2010
const CLICK_DY = 100;
2111

22-
// Calibrated length (mm) that the ruler reports when the US spacing fix is
23-
// active. Obtained by running this test once with the fix enabled.
24-
// Without the fix the VTK spacing falls back to 1.0 mm/pixel, which makes
25-
// the measured length grow to ~97 mm (~1.96x) and this assertion fails.
26-
const EXPECTED_LENGTH_MM = 49.35;
27-
const LENGTH_TOLERANCE_MM = 1.5;
12+
// At the shared viewport (1200×800), with the fix active the ruler reports
13+
// about 49 mm. Without the fix the same ruler reports about 97 mm. A wide
14+
// tolerance lets the assertion absorb minor canvas-size jitter between
15+
// runners while still excluding the 1 mm fallback.
16+
const EXPECTED_LENGTH_MM = 49;
17+
const LENGTH_TOLERANCE_MM = 8;
2818

2919
describe('Ultrasound image spacing', () => {
3020
it('ruler length reflects physical spacing from SequenceOfUltrasoundRegions', async () => {
3121
await openUrls([US_MULTIFRAME_DICOM]);
22+
await volViewPage.waitForViews();
3223

33-
// Activate the ruler tool
3424
const rulerBtn = await $('button span i[class~=mdi-ruler]');
3525
await rulerBtn.waitForClickable();
3626
await rulerBtn.click();
3727

38-
// Place the ruler on the first view's canvas
28+
// element.click({ x, y }) offsets are measured from the element's center,
29+
// so x:0 / y:0 is the canvas center.
3930
const views = await volViewPage.views;
4031
const canvas = views[0];
41-
const loc = await canvas.getLocation();
42-
const size = await canvas.getSize();
43-
const cx = loc.x + size.width / 2;
44-
const cy = loc.y + size.height / 2;
4532

46-
await clickAt(cx - CLICK_DX / 2, cy - CLICK_DY / 2);
47-
await clickAt(cx + CLICK_DX / 2, cy + CLICK_DY / 2);
33+
await canvas.click({ x: 0, y: -CLICK_DY / 2 });
34+
await canvas.click({ x: 0, y: CLICK_DY / 2 });
4835

49-
// Open Annotations > Measurements to read the ruler length
5036
const annotationsTab = await $(
5137
'button[data-testid="module-tab-Annotations"]'
5238
);
@@ -56,7 +42,6 @@ describe('Ultrasound image spacing', () => {
5642
await measurementsTab.waitForClickable();
5743
await measurementsTab.click();
5844

59-
// The ruler details panel renders `{value}mm`; read the first length.
6045
let lengthMm = 0;
6146
await browser.waitUntil(
6247
async () => {
@@ -79,14 +64,7 @@ describe('Ultrasound image spacing', () => {
7964

8065
console.log(`[ultrasound-spacing] measured ruler length: ${lengthMm} mm`);
8166

82-
if (EXPECTED_LENGTH_MM > 0) {
83-
expect(lengthMm).toBeGreaterThan(
84-
EXPECTED_LENGTH_MM - LENGTH_TOLERANCE_MM
85-
);
86-
expect(lengthMm).toBeLessThan(EXPECTED_LENGTH_MM + LENGTH_TOLERANCE_MM);
87-
} else {
88-
// Calibration mode: any positive value passes, actual number is logged.
89-
expect(lengthMm).toBeGreaterThan(0);
90-
}
67+
expect(lengthMm).toBeGreaterThan(EXPECTED_LENGTH_MM - LENGTH_TOLERANCE_MM);
68+
expect(lengthMm).toBeLessThan(EXPECTED_LENGTH_MM + LENGTH_TOLERANCE_MM);
9169
});
9270
});

0 commit comments

Comments
 (0)