-
-
Notifications
You must be signed in to change notification settings - Fork 4k
test(CornerstoneUtils): Adding unit tests for most of Cornerstone Extension utilities #5454
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
jbocce
merged 39 commits into
OHIF:master
from
ViniciusResende:test/cornerstone-extension-utils
Oct 7, 2025
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
cd19093
fix: 🐛 updateSegmentationStats segmentation clone strategy
ViniciusResende 9709652
test: 💍 added unit tests for the updateSegmentationStats util
ViniciusResende a41ac45
test: 💍 added unit tests for segmentUtils file
ViniciusResende 5566da7
fix: 🐛 typescript errors at toggleVOISliceSync file
ViniciusResende 0f1855e
test: 💍 added unit test for toggleVOISliceSync at cs extension
ViniciusResende 1d8de06
test: 💍 add unit test for setUpSegmentationEventHandlers
ViniciusResende bddda95
fix: 🐛 removing unreachable code from setupSegmentationModified
ViniciusResende 07f470f
test: 💍 added unit tests for segmentationHandlers utility
ViniciusResende b697aea
test: 💍 added unit tests for removeViewportSegmentationRepresen
ViniciusResende 4d07800
fix: 🐛 getDialogId was handling an unexistent HydrationType
ViniciusResende a619b16
test: 💍 added unit tests for promptHydrationDialog
ViniciusResende e79c1ae
test: 💍 added unit tests for nthLoader util
ViniciusResende c2e415e
test: 💍 added unit tests for getCenterExtent util
ViniciusResende 3f598df
test: 💍 added unit tests for isMeasurementWithinViewport util
ViniciusResende c0c1723
test: 💍 add unit test for isReferenceViewable cornerstone util
ViniciusResende 7a420c1
fix: 🐛 removed unused logic at interleaveTopToBottom
ViniciusResende fc5efc6
test: 💍 added unit tests for interleaveTopToBottom function
ViniciusResende fcaa079
chore: 🤖 moved interleave js file to ts
ViniciusResende 2d44cfb
test: 💍 added unit tests for interleaveCenterLoader
ViniciusResende ec04bc5
fix: 🐛 interleave algorithm iterator skipping issue
ViniciusResende bf05cb1
test: 💍 added unit tests for the interleave algorithm
ViniciusResende 4fb380c
test: 💍 added unit tests for initWebWorkerProgressHandler
ViniciusResende 2bcd340
test: 💍 added unit tests for initViewTiming
ViniciusResende 4d2c2f8
test: 💍 added hydrationUtils unit tests at cornerstone ext
ViniciusResende 2debcb4
test: 💍 add unit test for getViewportOrientationFromImageOrient
ViniciusResende 353c844
test: 💍 added unit tests for getViewportEnabledElement.test
ViniciusResende c81e2d5
feat: 🎸 converting getNthFrames utility to typescript
ViniciusResende 7d89dae
test: 💍 added unit tests for getNthFrames util function
ViniciusResende e5ae00e
fix: 🐛 added typing and edge case handling for getInterleavedFr
ViniciusResende 25874b3
test: 💍 added unit tests for getInterleavedFrames
ViniciusResende 58ad4ff
test: 💍 added unit tests for getCornerstoneViewportType
ViniciusResende 12891c5
test: 💍 added unit tests for getCornerstoneOrientation
ViniciusResende 4fa6af1
test: 💍 added unit tests for getCornerstoneBlendMode utility
ViniciusResende 03ed3fe
test: 💍 added unit tests for getActiveViewportEnabledElement
ViniciusResende 3ab6e2a
test: 💍 added unit tests for findNearbyToolData util
ViniciusResende 8fb8eb9
test: 💍 added unit tests for generateSegmentationCSVReport util
ViniciusResende f12b20b
test: 💍 fix consistency on result assrtion
ViniciusResende feda2fc
test: 💍 remove unecessary result variable that wasn't asserted
ViniciusResende 67912ab
Merge branch 'master' of https://github.com/OHIF/Viewers into test/co…
ViniciusResende 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
125 changes: 125 additions & 0 deletions
125
extensions/cornerstone/src/utils/findNearbyToolData.test.ts
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,125 @@ | ||
import { findNearbyToolData } from './findNearbyToolData'; | ||
|
||
describe('findNearbyToolData', () => { | ||
const mockCommandsManager = { | ||
runCommand: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return undefined when event is null', () => { | ||
const result = findNearbyToolData(mockCommandsManager, null); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return undefined when event is undefined', () => { | ||
const result = findNearbyToolData(mockCommandsManager, undefined); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return undefined when event has no detail', () => { | ||
const event = {}; | ||
const result = findNearbyToolData(mockCommandsManager, event); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return undefined when event detail is null', () => { | ||
const event = { detail: null }; | ||
const result = findNearbyToolData(mockCommandsManager, event); | ||
|
||
expect(result).toBeUndefined(); | ||
expect(mockCommandsManager.runCommand).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call runCommand with correct parameters when event has valid detail', () => { | ||
const mockElement = document.createElement('div'); | ||
const mockCurrentPoints = { canvas: { x: 100, y: 200 } }; | ||
const mockToolData = { id: 'annotation-1' }; | ||
const event = { | ||
detail: { | ||
element: mockElement, | ||
currentPoints: mockCurrentPoints, | ||
}, | ||
}; | ||
|
||
mockCommandsManager.runCommand.mockReturnValue(mockToolData); | ||
|
||
const result = findNearbyToolData(mockCommandsManager, event); | ||
|
||
expect(mockCommandsManager.runCommand).toHaveBeenCalledWith( | ||
'getNearbyAnnotation', | ||
{ | ||
element: mockElement, | ||
canvasCoordinates: mockCurrentPoints.canvas, | ||
}, | ||
'CORNERSTONE' | ||
); | ||
expect(result).toBe(mockToolData); | ||
}); | ||
|
||
it('should handle event with element but no currentPoints', () => { | ||
const mockElement = document.createElement('div'); | ||
const event = { | ||
detail: { | ||
element: mockElement, | ||
}, | ||
}; | ||
|
||
findNearbyToolData(mockCommandsManager, event); | ||
|
||
expect(mockCommandsManager.runCommand).toHaveBeenCalledWith( | ||
'getNearbyAnnotation', | ||
{ | ||
element: mockElement, | ||
canvasCoordinates: undefined, | ||
}, | ||
'CORNERSTONE' | ||
); | ||
}); | ||
|
||
it('should handle event with currentPoints but no canvas coordinates', () => { | ||
const mockElement = document.createElement('div'); | ||
const mockCurrentPoints = {}; | ||
const event = { | ||
detail: { | ||
element: mockElement, | ||
currentPoints: mockCurrentPoints, | ||
}, | ||
}; | ||
|
||
findNearbyToolData(mockCommandsManager, event); | ||
|
||
expect(mockCommandsManager.runCommand).toHaveBeenCalledWith( | ||
'getNearbyAnnotation', | ||
{ | ||
element: mockElement, | ||
canvasCoordinates: undefined, | ||
}, | ||
'CORNERSTONE' | ||
); | ||
}); | ||
|
||
it('should return result from runCommand', () => { | ||
const mockToolData = { id: 'test-annotation', data: 'test-data' }; | ||
const event = { | ||
detail: { | ||
element: document.createElement('div'), | ||
currentPoints: { canvas: { x: 50, y: 75 } }, | ||
}, | ||
}; | ||
|
||
mockCommandsManager.runCommand.mockReturnValue(mockToolData); | ||
|
||
const result = findNearbyToolData(mockCommandsManager, event); | ||
|
||
expect(result).toBe(mockToolData); | ||
}); | ||
}); |
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.