-
Notifications
You must be signed in to change notification settings - Fork 506
fix(Synchronizer): actually remove event listener on source removal #2772
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
+135
−7
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ecf58ec
fix(synchronizer): actually remove event listener on source removal
cb02862
fix(synchronizer): apply ai review suggestions
2abb886
fix(synchronizer): fix event listener typing
040303b
Merge remote-tracking branch 'origin/main' into pr-2772-sync
sedghi a6684f1
test: update generic volume annotation snapshots
sedghi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import * as cornerstone3D from '@cornerstonejs/core'; | ||
| import * as testUtils from '../../../utils/test/testUtils'; | ||
| import * as csTools3d from '../src/index'; | ||
|
|
||
| const { utilities, Enums } = cornerstone3D; | ||
| const { ViewportType } = Enums; | ||
| const { SynchronizerManager } = csTools3d; | ||
| const renderingEngineId = utilities.uuidv4(); | ||
|
|
||
| const viewportId1 = 'VIEWPORT1'; | ||
| const viewportId2 = 'VIEWPORT2'; | ||
|
|
||
| describe('Synchronizer:', () => { | ||
| let testEnv; | ||
| let renderingEngine; | ||
|
|
||
| beforeEach(function () { | ||
| testEnv = testUtils.setupTestEnvironment({ | ||
| renderingEngineId: renderingEngineId, | ||
| viewportIds: [viewportId1, viewportId2], | ||
| }); | ||
|
|
||
| renderingEngine = testEnv.renderingEngine; | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| testUtils.cleanupTestEnvironment({ | ||
| renderingEngineId: renderingEngineId, | ||
| synchronizerId: 'testSynchronizer', | ||
| }); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it('Should successfully remove event handlers on viewport removal', function () { | ||
| const [element1, _] = testUtils.createViewports(renderingEngine, [ | ||
| { | ||
| viewportType: ViewportType.ORTHOGRAPHIC, | ||
| orientation: Enums.OrientationAxis.AXIAL, | ||
| viewportId: viewportId1, | ||
| }, | ||
| { | ||
| viewportType: ViewportType.ORTHOGRAPHIC, | ||
| orientation: Enums.OrientationAxis.AXIAL, | ||
| viewportId: viewportId2, | ||
| }, | ||
| ]); | ||
| let eventListenerCallCount = 0; | ||
| const eventListener = () => { | ||
| eventListenerCallCount += 1; | ||
| }; | ||
|
|
||
| const synchronizer = SynchronizerManager.createSynchronizer( | ||
| 'testSynchronizer', | ||
| 'testEvent', | ||
| eventListener | ||
| ); | ||
|
|
||
| const viewport1Info = { | ||
| renderingEngineId: renderingEngine.id, | ||
| viewportId: renderingEngine.getViewport(viewportId1).id, | ||
| }; | ||
| const viewport2Info = { | ||
| renderingEngineId: renderingEngine.id, | ||
| viewportId: renderingEngine.getViewport(viewportId2).id, | ||
| }; | ||
| synchronizer.addSource(viewport1Info); | ||
| synchronizer.addTarget(viewport2Info); | ||
| // we need a source so the event is fired, so remove and add the source back. | ||
| // there should be one event listener active after this | ||
| synchronizer.removeSource(viewport1Info); | ||
| synchronizer.addSource(viewport1Info); | ||
|
|
||
| element1.dispatchEvent(new CustomEvent('testEvent', {})); | ||
|
|
||
| expect(eventListenerCallCount).toEqual(1); | ||
| }); | ||
|
|
||
| it('Should successfully remove auxilary event handlers on viewport removal', function () { | ||
| const [element1, _] = testUtils.createViewports(renderingEngine, [ | ||
| { | ||
| viewportType: ViewportType.ORTHOGRAPHIC, | ||
| orientation: Enums.OrientationAxis.AXIAL, | ||
| viewportId: viewportId1, | ||
| }, | ||
| { | ||
| viewportType: ViewportType.ORTHOGRAPHIC, | ||
| orientation: Enums.OrientationAxis.AXIAL, | ||
| viewportId: viewportId2, | ||
| }, | ||
| ]); | ||
| let eventListenerCallCount = 0; | ||
| const eventListener = () => { | ||
| console.log('eventListener called'); | ||
| eventListenerCallCount += 1; | ||
| }; | ||
|
|
||
| const synchronizer = SynchronizerManager.createSynchronizer( | ||
| 'testSynchronizer', | ||
| 'testEvent', | ||
| eventListener, | ||
| { | ||
| auxiliaryEvents: [ | ||
| { | ||
| name: 'auxiliaryEvent', | ||
| }, | ||
| ], | ||
| } | ||
| ); | ||
|
|
||
| const viewport1Info = { | ||
| renderingEngineId: renderingEngine.id, | ||
| viewportId: renderingEngine.getViewport(viewportId1).id, | ||
| }; | ||
| const viewport2Info = { | ||
| renderingEngineId: renderingEngine.id, | ||
| viewportId: renderingEngine.getViewport(viewportId2).id, | ||
| }; | ||
| synchronizer.addSource(viewport1Info); | ||
| synchronizer.addTarget(viewport2Info); | ||
| // we need a source so the event is fired, so remove and add the source back. | ||
| // there should be one event listener active after this | ||
| synchronizer.removeSource(viewport1Info); | ||
| synchronizer.addSource(viewport1Info); | ||
|
|
||
| element1.dispatchEvent(new CustomEvent('auxiliaryEvent', {})); | ||
|
|
||
| expect(eventListenerCallCount).toEqual(1); | ||
| }); | ||
| }); | ||
Binary file modified
BIN
-270 Bytes
(100%)
...ts/chromium/genericViewport/genericVolumeAnnotationTools.spec.ts/cpu-length.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3.25 KB
(98%)
.../chromium/genericViewport/genericVolumeAnnotationTools.spec.ts/cpu-sagittal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-203 Bytes
(100%)
...nshots/chromium/genericViewport/genericVolumeAnnotationTools.spec.ts/length.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-163 Bytes
(100%)
...hots/chromium/genericViewport/genericVolumeAnnotationTools.spec.ts/sagittal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.