-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fixed issues with incorrect specification for multi group estim… (
#636) * feat: fixed issues with incorrect specification for multi group estimators, added unit tests * chore: remove unused import
- Loading branch information
Showing
10 changed files
with
255 additions
and
14 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...reateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview.helper.spec.ts
This file contains 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,112 @@ | ||
import { IAnalysesSelection } from 'components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationDialogBase.types'; | ||
import { getWeightAndConditionsForSpecification } from 'components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview.helpers'; | ||
import { EPropertyType } from 'components/EditMetadata'; | ||
import { IAutocompleteObject } from 'components/NeurosynthAutocomplete/NeurosynthAutocomplete'; | ||
|
||
describe('CreateMetaAnalysisSpecificationReviewHelpers', () => { | ||
describe('getWeightAndConditionsForSpecification', () => { | ||
it('should set multiple weights and multiple conditions if the reference database is not default', () => { | ||
const mockEstimator: IAutocompleteObject = { | ||
label: 'ALESubtraction', | ||
description: '', | ||
}; | ||
|
||
const mockSelection: IAnalysesSelection = { | ||
selectionKey: 'key', | ||
selectionValue: 'val-selected', | ||
referenceDataset: 'val-reference', | ||
type: EPropertyType.STRING, | ||
}; | ||
|
||
const result = getWeightAndConditionsForSpecification(mockEstimator, mockSelection); | ||
|
||
expect(result.weights).toEqual([1, -1]); | ||
expect(result.conditions).toEqual(['val-selected', 'val-reference']); | ||
expect(result.databaseStudyset).toBeUndefined(); | ||
}); | ||
|
||
it('should return empty lists if the estimator is not defined', () => { | ||
const mockSelection: IAnalysesSelection = { | ||
selectionKey: 'key', | ||
selectionValue: 'val', | ||
referenceDataset: 'neuroquery', | ||
type: EPropertyType.STRING, | ||
}; | ||
|
||
const result = getWeightAndConditionsForSpecification(undefined, mockSelection); | ||
|
||
expect(result.conditions.length).toEqual(0); | ||
expect(result.weights.length).toEqual(0); | ||
expect(result.databaseStudyset).toBeUndefined(); | ||
}); | ||
|
||
it('should set a single weight and a single condition if the reference database is default', () => { | ||
const mockEstimator: IAutocompleteObject = { | ||
label: 'ALESubtraction', | ||
description: '', | ||
}; | ||
|
||
const mockSelection: IAnalysesSelection = { | ||
selectionKey: 'key', | ||
selectionValue: 'val', | ||
referenceDataset: 'neuroquery', | ||
type: EPropertyType.STRING, | ||
}; | ||
|
||
const result = getWeightAndConditionsForSpecification(mockEstimator, mockSelection); | ||
|
||
expect(result.conditions.length).toEqual(1); | ||
expect(result.weights).toEqual([1]); | ||
expect(result.databaseStudyset).toEqual('neuroquery'); | ||
}); | ||
|
||
it('should parse the array into correct boolean types', () => { | ||
let mockEstimator: IAutocompleteObject = { | ||
label: 'ALESubtraction', | ||
description: '', | ||
}; | ||
|
||
let mockSelection: IAnalysesSelection = { | ||
selectionKey: 'key', | ||
selectionValue: 'true', | ||
referenceDataset: 'false', | ||
type: EPropertyType.BOOLEAN, | ||
}; | ||
|
||
let result = getWeightAndConditionsForSpecification(mockEstimator, mockSelection); | ||
expect(result.conditions).toEqual([true, false]); | ||
|
||
mockEstimator = { | ||
label: 'ALESubtraction', | ||
description: '', | ||
}; | ||
|
||
mockSelection = { | ||
selectionKey: 'key', | ||
selectionValue: true, | ||
referenceDataset: 'false', | ||
type: EPropertyType.BOOLEAN, | ||
}; | ||
|
||
result = getWeightAndConditionsForSpecification(mockEstimator, mockSelection); | ||
expect(result.conditions).toEqual([true, false]); | ||
}); | ||
|
||
it('should parse the array into correct string types', () => { | ||
let mockEstimator: IAutocompleteObject = { | ||
label: 'ALESubtraction', | ||
description: '', | ||
}; | ||
|
||
let mockSelection: IAnalysesSelection = { | ||
selectionKey: 'key', | ||
selectionValue: 'true', | ||
referenceDataset: 'false', | ||
type: EPropertyType.STRING, | ||
}; | ||
|
||
let result = getWeightAndConditionsForSpecification(mockEstimator, mockSelection); | ||
expect(result.conditions).toEqual(['true', 'false']); | ||
}); | ||
}); | ||
}); |
This file contains 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 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
51 changes: 51 additions & 0 deletions
51
...pecificationSelectionStep/SelectAnalysesComponent/SelectAnalysesComponent.helpers.spec.ts
This file contains 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,51 @@ | ||
import { | ||
isMultiGroupAlgorithm, | ||
selectedReferenceDatasetIsDefaultDataset, | ||
} from 'components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationSelectionStep/SelectAnalysesComponent/SelectAnalysesComponent.helpers'; | ||
import { | ||
DEFAULT_REFERENCE_DATASETS, | ||
MULTIGROUP_ALGORITHMS, | ||
} from 'components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationSelectionStep/SelectAnalysesComponent/SelectAnalysesComponent.types'; | ||
|
||
describe('SelectAnalysesComponentHelpers', () => { | ||
describe('selectedReferenceDatasetIsDefaultDataset', () => { | ||
it('should be truthy for default datasets', () => { | ||
DEFAULT_REFERENCE_DATASETS.forEach((dataset) => { | ||
const result = selectedReferenceDatasetIsDefaultDataset(dataset.id); | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('should return false for non reference datasets', () => { | ||
const result = selectedReferenceDatasetIsDefaultDataset('random dataset'); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it('should return false for undefined', () => { | ||
const result = selectedReferenceDatasetIsDefaultDataset(undefined); | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('isMultiGroupAlgorithm', () => { | ||
it('should be truthy for multigroup algorithms', () => { | ||
MULTIGROUP_ALGORITHMS.forEach((multigroupAlgorithm) => { | ||
const result = isMultiGroupAlgorithm({ | ||
label: multigroupAlgorithm, | ||
description: '', | ||
}); | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('should return false for non reference datasets', () => { | ||
const result = isMultiGroupAlgorithm({ label: 'random', description: '' }); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it('should return false for undefined', () => { | ||
const result = isMultiGroupAlgorithm(undefined); | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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
24 changes: 24 additions & 0 deletions
24
compose/neurosynth-frontend/src/hooks/metaAnalyses/useDeleteMetaAnalysis.tsx
This file contains 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,24 @@ | ||
import { AxiosError, AxiosResponse } from 'axios'; | ||
import { useSnackbar } from 'notistack'; | ||
import { useMutation, useQueryClient } from 'react-query'; | ||
import API from 'utils/api'; | ||
|
||
const useDeleteMetaAnalysis = () => { | ||
const queryClient = useQueryClient(); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
return useMutation<AxiosResponse, AxiosError, string, unknown>( | ||
(id) => API.NeurosynthServices.NeurosynthDefaultApi.metaAnalysesIdDelete(id), | ||
{ | ||
onSuccess: () => { | ||
queryClient.invalidateQueries('meta-analyses'); | ||
}, | ||
onError: () => { | ||
enqueueSnackbar('There was an error deleting the meta-analysis', { | ||
variant: 'error', | ||
}); | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
export default useDeleteMetaAnalysis; |
This file contains 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 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