|
1 | 1 | import { Key } from 'webdriverio'; |
2 | 2 | import { volViewPage } from '../pageobjects/volview.page'; |
3 | | -import { CINE_US_DATASET } from './configTestUtils'; |
| 3 | +import { |
| 4 | + CINE_US_DATASET, |
| 5 | + COLOR3D_JPEG_BASELINE_DICOM, |
| 6 | +} from './configTestUtils'; |
4 | 7 | import { openUrls } from './utils'; |
5 | 8 |
|
6 | 9 | const PLAY_CONTROLS = '.play-controls'; |
7 | 10 | const FRAME_LABEL = '.view-annotations .frame-label'; |
| 11 | +const VIEW_SELECTOR = 'div[data-testid="vtk-view vtk-two-view"]'; |
| 12 | + |
| 13 | +async function getFirstCineCanvasStats() { |
| 14 | + return browser.execute((selector: string) => { |
| 15 | + const views = Array.from(document.querySelectorAll(selector)).filter( |
| 16 | + (view) => { |
| 17 | + const rect = view.getBoundingClientRect(); |
| 18 | + return rect.width > 10 && rect.height > 10; |
| 19 | + } |
| 20 | + ); |
| 21 | + const canvas = views[0]?.querySelector( |
| 22 | + 'canvas' |
| 23 | + ) as HTMLCanvasElement | null; |
| 24 | + if (!canvas) return null; |
| 25 | + |
| 26 | + const context = canvas.getContext('2d'); |
| 27 | + if (!context) return null; |
| 28 | + |
| 29 | + const { width, height } = canvas; |
| 30 | + if (width < 2 || height < 2) return { width, height, nonBlack: 0 }; |
| 31 | + |
| 32 | + const pixels = context.getImageData(0, 0, width, height).data; |
| 33 | + let nonBlack = 0; |
| 34 | + const stride = Math.max(4, Math.floor(pixels.length / 4000 / 4) * 4); |
| 35 | + |
| 36 | + for (let i = 0; i < pixels.length; i += stride) { |
| 37 | + if (pixels[i] > 5 || pixels[i + 1] > 5 || pixels[i + 2] > 5) { |
| 38 | + nonBlack++; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + return { width, height, nonBlack }; |
| 43 | + }, VIEW_SELECTOR); |
| 44 | +} |
| 45 | + |
| 46 | +async function waitForFirstCineCanvasToRender(timeout = 5000) { |
| 47 | + await browser.waitUntil( |
| 48 | + async () => { |
| 49 | + const stats = await getFirstCineCanvasStats(); |
| 50 | + return ( |
| 51 | + !!stats && stats.width > 10 && stats.height > 10 && stats.nonBlack > 0 |
| 52 | + ); |
| 53 | + }, |
| 54 | + { |
| 55 | + timeout, |
| 56 | + interval: 50, |
| 57 | + timeoutMsg: 'Expected cine canvas to stay non-black', |
| 58 | + } |
| 59 | + ); |
| 60 | +} |
8 | 61 |
|
9 | 62 | describe('VolView cine playback', () => { |
10 | 63 | it('loads a multi-frame ultrasound and scrubs frames', async () => { |
@@ -35,4 +88,25 @@ describe('VolView cine playback', () => { |
35 | 88 | expect(after).toMatch(/^Frame: [1-8] \/ 8$/); |
36 | 89 | expect(after).not.toBe(initialText); |
37 | 90 | }); |
| 91 | + |
| 92 | + it('keeps rendering after repeated maximize toggles during playback', async () => { |
| 93 | + await openUrls([COLOR3D_JPEG_BASELINE_DICOM]); |
| 94 | + |
| 95 | + const playButton = $(`${PLAY_CONTROLS} .play-btn`); |
| 96 | + await playButton.waitForDisplayed({ timeout: 10000 }); |
| 97 | + await playButton.click(); |
| 98 | + |
| 99 | + await $(VIEW_SELECTOR).waitForDisplayed({ |
| 100 | + timeout: 10000, |
| 101 | + }); |
| 102 | + await waitForFirstCineCanvasToRender(); |
| 103 | + |
| 104 | + for (let i = 0; i < 12; i++) { |
| 105 | + const firstView = $(VIEW_SELECTOR); |
| 106 | + await firstView.waitForDisplayed({ timeout: 5000 }); |
| 107 | + await firstView.doubleClick(); |
| 108 | + await browser.pause(50); |
| 109 | + await waitForFirstCineCanvasToRender(1500); |
| 110 | + } |
| 111 | + }); |
38 | 112 | }); |
0 commit comments