-
Notifications
You must be signed in to change notification settings - Fork 11
First JEST unit test suits #111
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
Draft
tangy5
wants to merge
2
commits into
main
Choose a base branch
from
JEST_setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,3 @@ | ||
| module.exports = { | ||
| testEnvironment: 'jest-environment-jsdom' | ||
| }; | ||
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 |
|---|---|---|
| @@ -1,64 +1,5 @@ | ||
| { | ||
| "name": "@ohif/extension-monai-service", | ||
| "version": "0.0.1", | ||
| "description": "OHIFv3 extension for MONAI Service", | ||
| "author": "OHIF,NVIDIA", | ||
| "license": "MIT", | ||
| "main": "dist/umd/extension-monai-service/index.umd.js", | ||
| "files": [ | ||
| "dist/**", | ||
| "public/**", | ||
| "README.md" | ||
| ], | ||
| "repository": "OHIF/Viewers", | ||
| "keywords": [ | ||
| "ohif-extension" | ||
| ], | ||
| "module": "src/index.tsx", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "engines": { | ||
| "node": ">=14", | ||
| "npm": ">=6", | ||
| "yarn": ">=1.18.0" | ||
| }, | ||
| "scripts": { | ||
| "dev": "cross-env NODE_ENV=development webpack --config .webpack/webpack.dev.js --watch --output-pathinfo", | ||
| "dev:my-extension": "yarn run dev", | ||
| "build": "cross-env NODE_ENV=production webpack --config .webpack/webpack.prod.js", | ||
| "build:package": "yarn run build", | ||
| "start": "yarn run dev" | ||
| }, | ||
| "peerDependencies": { | ||
| "@ohif/core": "^3.7.0-beta.80", | ||
| "@ohif/extension-default": "^3.7.0-beta.80", | ||
| "@ohif/extension-cornerstone": "^3.7.0-beta.80", | ||
| "@ohif/i18n": "^3.7.0-beta.80", | ||
| "prop-types": "^15.6.2", | ||
| "react": "^17.0.2", | ||
| "react-dom": "^17.0.2", | ||
| "react-i18next": "^12.2.2", | ||
| "react-router": "^6.8.1", | ||
| "react-router-dom": "^6.8.1" | ||
| }, | ||
| "dependencies": { | ||
| "@babel/runtime": "^7.20.13", | ||
| "md5.js": "^1.3.5", | ||
| "axios": "^0.21.1", | ||
| "arraybuffer-concat": "^0.0.1", | ||
| "ndarray": "^1.0.19", | ||
| "nrrd-js": "^0.2.1", | ||
| "pako": "^2.0.3", | ||
| "react-color": "^2.19.3", | ||
| "bootstrap": "^5.0.2", | ||
| "react-select": "^4.3.1", | ||
| "chroma-js": "^2.1.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@cornerstonejs/tools": "^1.16.0", | ||
| "@babel/runtime": "^7.20.13", | ||
| "@cornerstonejs/tools": "^1.16.4", | ||
| "react-color": "^2.19.3" | ||
| } | ||
| "devDependencies": { | ||
| "svgo": "^1.3.2" | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
plugins/ohif/extensions/monai-service/src/__tests__/inference.test.js
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,73 @@ | ||
| import React from 'react'; | ||
| import { render, fireEvent, waitFor } from '@testing-library/react'; | ||
| import AutoSegmentation from './AutoSegmentation'; | ||
| import ModelSelector from '../ModelSelector'; | ||
|
|
||
| jest.mock('../ModelSelector', () => (props) => ( | ||
| <button onClick={props.onSelectModel}>Select Model</button> | ||
| )); | ||
| jest.mock('../../utils/GenericUtils', () => ({ | ||
| hideNotification: jest.fn(), | ||
| })); | ||
|
|
||
| describe('AutoSegmentation', () => { | ||
| let props; | ||
|
|
||
| beforeEach(() => { | ||
| props = { | ||
| client: () => ({ | ||
| inference: jest.fn().mockResolvedValue({ status: 201 }), | ||
| }), | ||
| updateView: jest.fn(), | ||
| notification: { | ||
| show: jest.fn(), | ||
| hide: jest.fn(), | ||
| }, | ||
| servicesManager: { | ||
| services: { | ||
| displaySetService: { | ||
| activeDisplaySets: [{ Modality: 'CT', SeriesInstanceUID: '123' }], | ||
| } | ||
| } | ||
| }, | ||
| info: { | ||
| models: [{ id: 'model1', network_arch: 'monai_vista3d' }], | ||
| modelLabelNames: { 'model1': ['Label1', 'Label2'] }, | ||
| modelLabelIndices: { 'model1': [1, 2] }, | ||
| modelLabelToIdxMap: { | ||
| 'model1': { 'kidney': 1, 'lung': 2, 'bone': 3 } | ||
| } | ||
| }, | ||
| viewConstants: { | ||
| SeriesInstanceUID: 'defaultSeriesInstanceUID' | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| it('renders correctly', () => { | ||
| const { getByText } = render(<AutoSegmentation {...props} />); | ||
| expect(getByText('Auto-Segmentation')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls onSelectModel when model is selected', () => { | ||
| const { getByText } = render(<AutoSegmentation {...props} />); | ||
| const selectButton = getByText('Select Model'); | ||
| fireEvent.click(selectButton); | ||
| expect(props.info.models.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('calls onSegmentation when model is run', async () => { | ||
| const { getByText } = render(<AutoSegmentation {...props} />); | ||
| const selectButton = getByText('Select Model'); | ||
| fireEvent.click(selectButton); | ||
| await waitFor(() => { | ||
| expect(props.client().inference).toHaveBeenCalled(); | ||
| }); | ||
| expect(props.notification.show).toHaveBeenCalledWith(expect.objectContaining({ | ||
| title: 'MONAI Service', | ||
| message: 'Run Segmentation - Successful', | ||
| type: 'success', | ||
| })); | ||
| }); | ||
| }); | ||
|
|
63 changes: 63 additions & 0 deletions
63
plugins/ohif/extensions/monai-service/src/__tests__/monaiServicePanel.test.js
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,63 @@ | ||
| import React from 'react'; | ||
| import { MonaiServicePanel } from './MonaiServicePanel'; | ||
| import { render, waitFor } from '@testing-library/react'; | ||
|
|
||
| jest.mock('../services/MonaiServiceClient', () => { | ||
| return { | ||
| MonaiServiceClient: jest.fn().mockImplementation(() => ({ | ||
| getAuthorizationHeader: () => ({ Authorization: 'Bearer fake_token' }), | ||
| list_models: jest.fn().mockResolvedValue({ | ||
| status: 200, | ||
| data: [] | ||
| }), | ||
| cache_image: jest.fn().mockResolvedValue({}) | ||
| })) | ||
| }; | ||
| }); | ||
|
|
||
| const mockNotificationService = { | ||
| show: jest.fn(), | ||
| hide: jest.fn() | ||
| }; | ||
|
|
||
| const mockDisplaySetService = { | ||
| activeDisplaySets: [{ | ||
| SeriesInstanceUID: '123', | ||
| StudyInstanceUID: '456', | ||
| instances: [{ | ||
| FrameOfReferenceUID: '789' | ||
| }], | ||
| displaySetInstanceUID: '101112' | ||
| }] | ||
| }; | ||
|
|
||
| // Test suite | ||
| describe('MonaiServicePanel', () => { | ||
| it('handles model and dataset information on successful connection', async () => { | ||
| const props = { | ||
| servicesManager: { | ||
| services: { | ||
| uiNotificationService: mockNotificationService, | ||
| displaySetService: mockDisplaySetService | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const { container } = render(<MonaiServicePanel {...props} />); | ||
|
|
||
| const instance = container.querySelector('MonaiServicePanel'); | ||
| await instance.onInfo(); | ||
|
|
||
| expect(mockNotificationService.show).toHaveBeenCalledWith(expect.objectContaining({ | ||
| type: 'info', | ||
| message: 'Connecting to MONAI Service' | ||
| })); | ||
| await waitFor(() => { | ||
| expect(mockNotificationService.show).toHaveBeenCalledWith(expect.objectContaining({ | ||
| type: 'success', | ||
| message: 'Connected to MONAI Service Server - Successful' | ||
| })); | ||
| }); | ||
| expect(instance.state.info.models.length).toBeGreaterThan(0); | ||
| }); | ||
| }); |
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,3 @@ | ||
| module.exports = { | ||
| testEnvironment: 'jest-environment-jsdom' | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing new line |
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing new line