-
Notifications
You must be signed in to change notification settings - Fork 484
test: add wait for render for the ohif-downstream #2672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
653481c
Add rendered/need render checks
wayfarer3130 a557294
Add an example test to use the wait for rendered
wayfarer3130 e324a7e
Merge remote-tracking branch 'origin/main' into fix/downstream-ohif-i…
wayfarer3130 6686532
Merge remote-tracking branch 'origin/main' into fix/downstream-ohif-i…
wayfarer3130 29031e2
PR review comments - adds wait for volume laod
wayfarer3130 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import type { Page } from '@playwright/test'; | ||
|
|
||
| type WaitForViewportsRenderedOptions = { | ||
| timeout?: number; | ||
| /** | ||
| * If true (default), also waits for any volume actors referenced by the | ||
| * viewports to report loaded. | ||
| */ | ||
| waitVolumeLoad?: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Stabilize tests by waiting for a short tick, network idle, then viewport render completion. | ||
| * To use this method safely, you may need to make changes to OHIF and/or CS3D | ||
| * methods handling clicks (SHOULD be commands modules only). These should set the | ||
| * state to needs render synchronously so that this method can safely wait for the render to complete. | ||
| * Examples such as changing the hanging protocol currently don't set such a state | ||
| * and thus can't be rendered without a delay. | ||
| * | ||
| * If options.waitVolumeLoad is not false, then this method will wait for all volumes | ||
| * associated with viewports to be loaded. | ||
| */ | ||
| export const waitForViewportsRendered = async ( | ||
| page: Page, | ||
| options: WaitForViewportsRenderedOptions = {} | ||
| ) => { | ||
| const { timeout = 15000, waitVolumeLoad = true } = options; | ||
|
|
||
| await page.waitForFunction( | ||
| ({ waitVolumeLoad }) => { | ||
| const cornerstone = (window as any).cornerstone; | ||
| if (!cornerstone?.getRenderingEngines) { | ||
| return false; | ||
| } | ||
|
|
||
| const renderingEngines = cornerstone.getRenderingEngines(); | ||
| const viewports = renderingEngines.flatMap((engine) => | ||
| engine.getViewports ? engine.getViewports() : [] | ||
| ); | ||
|
|
||
| if (!viewports.length) { | ||
| return false; | ||
| } | ||
|
|
||
| const allRendered = viewports.every( | ||
| (viewport) => viewport?.viewportStatus === 'rendered' | ||
| ); | ||
|
|
||
| if (!allRendered) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!waitVolumeLoad) { | ||
| return true; | ||
| } | ||
|
|
||
| const cache = cornerstone.cache; | ||
| if (!cache?.getVolume) { | ||
| return true; | ||
| } | ||
|
|
||
| const actorEntries = viewports.flatMap((viewport) => | ||
| viewport?.getActors ? viewport.getActors() : [] | ||
| ); | ||
|
|
||
| for (const actorEntry of actorEntries) { | ||
| const id = actorEntry?.referencedId || actorEntry?.uid; | ||
| if (!id) { | ||
| continue; | ||
| } | ||
|
|
||
| let volume: any; | ||
| try { | ||
| volume = cache.getVolume(id); | ||
| } catch { | ||
| continue; | ||
| } | ||
|
|
||
| const loaded = | ||
| volume?.loadStatus && typeof volume.loadStatus.loaded === 'boolean' | ||
| ? volume.loadStatus.loaded | ||
| : true; | ||
|
|
||
| if (!loaded) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| }, | ||
| { waitVolumeLoad }, | ||
| { timeout } | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.