Skip to content

Commit

Permalink
fix: removed isRefetching (#828)
Browse files Browse the repository at this point in the history
* fix: removed isRefetching

* feat: add integration tests for specification wizard

* fix: unit tests
  • Loading branch information
nicoalee authored Oct 1, 2024
1 parent ade19f1 commit 47dbf03
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('CreateSpecificationDialog', () => {
fixture: 'projects/projectCanCreateSpecification',
}).as('projectFixture');
cy.intercept('GET', `**/api/studysets/*`, { fixture: 'studyset' }).as('studysetFixture');
cy.intercept('GET', '**/api/annotations/*', { fixture: 'annotation' }).as(
'annotationFixture'
);
});

it('should show the dialog', () => {
Expand All @@ -23,5 +26,51 @@ describe('CreateSpecificationDialog', () => {
cy.contains('button', 'Meta-Analyses').click();
cy.contains('button', 'Meta-Analysis Specification').click();
cy.get('.MuiDialog-container').should('be.visible');
cy.contains('button', 'Back').should('be.disabled');
});

it('should set the default specification values', () => {
cy.login('mocked', { sub: 'github|26612023' })
.visit('/projects/abc123')
.wait('@projectFixture');
cy.contains('button', 'Meta-Analyses').click();
cy.contains('button', 'Meta-Analysis Specification').click();
cy.get('.MuiDialog-container').should('be.visible');
cy.contains('MKDADensity').should('exist');
cy.contains('FDRCorrector').should('exist');
});

it.only('should step through the wizard', () => {
cy.intercept('POST', '**/api/specifications', {
id: 'mockedSpecificationId',
}).as('createSpecificationFixture');
cy.intercept('POST', '**/api/studysets', {
id: 'mockedStudySetId',
});
cy.intercept('POST', '**/api/annotations', {
id: 'mockedAnnotationId',
});
cy.intercept('POST', '**/api/meta-analyses', {
id: 'mockedMetaAnalysisId',
specification: {},
});
cy.intercept('GET', '**/api/specifications/*', {
fixture: 'specification',
});

cy.intercept('GET', '**/api/meta-analyses/mockedMetaAnalysisId*', {
fixture: 'metaAnalysis',
}).as('metaAnalysesFixture');

cy.login('mocked', { sub: 'github|26612023' })
.visit('/projects/abc123')
.wait('@projectFixture');
cy.contains('button', 'Meta-Analyses').click();
cy.contains('button', 'Meta-Analysis Specification').click();
cy.contains('Next').click();
cy.contains('included').should('exist');
cy.contains('button', 'Next').click();
cy.contains('button', 'Next').click();
cy.contains('button', 'Create Meta-Analysis Specification').click();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ const CreateMetaAnalysisSpecificationAlgorithmStep: React.FC<{
algorithm={algorithmSpec}
onSelectSpecification={(update) => setAlgorithmSpec(update)}
/>
<Box sx={{ width: '100$%', marginTop: '1rem' }}>
<Box sx={{ marginTop: '1rem' }}>
<NavigationButtons
nextButtonDisabled={!algorithmSpec.estimator}
nextButtonStyle="contained"
onButtonClick={handleNavigate}
prevButtonDisabled
/>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import CreateMetaAnalysisSpecificationReview from 'pages/MetaAnalysis/components
import CreateMetaAnalysisSpecificationSelectionStep from 'pages/MetaAnalysis/components/CreateMetaAnalysisSpecificationSelectionStep';
import {
getDefaultValuesForTypeAndParameter,
correctorOpt,
algorithmOpt,
correctorDefaultOption,
algorithmDefaultOption,
} from './CreateMetaAnalysisSpecificationDialogConstants';

const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) => {
Expand All @@ -35,10 +35,16 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
referenceDataset: undefined,
});
const [algorithm, setAlgorithm] = useState<IAlgorithmSelection>({
estimator: algorithmOpt,
estimatorArgs: getDefaultValuesForTypeAndParameter(EAnalysisType.CBMA, algorithmOpt?.label),
corrector: correctorOpt,
correctorArgs: getDefaultValuesForTypeAndParameter('CORRECTOR', correctorOpt?.label),
estimator: algorithmDefaultOption,
estimatorArgs: getDefaultValuesForTypeAndParameter(
EAnalysisType.CBMA,
algorithmDefaultOption?.label
),
corrector: correctorDefaultOption,
correctorArgs: getDefaultValuesForTypeAndParameter(
'CORRECTOR',
correctorDefaultOption?.label
),
});

useEffect(() => {
Expand All @@ -52,13 +58,16 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
props.onCloseDialog();
setActiveStep(0);
setAlgorithm({
estimator: algorithmOpt,
estimator: algorithmDefaultOption,
estimatorArgs: getDefaultValuesForTypeAndParameter(
EAnalysisType.CBMA,
algorithmOpt?.label
algorithmDefaultOption?.label
),
corrector: correctorDefaultOption,
correctorArgs: getDefaultValuesForTypeAndParameter(
'CORRECTOR',
correctorDefaultOption?.label
),
corrector: correctorOpt,
correctorArgs: getDefaultValuesForTypeAndParameter('CORRECTOR', correctorOpt?.label),
});
setSelection({
selectionKey: undefined,
Expand All @@ -71,10 +80,10 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
const handleNavigate = (button: ENavigationButton) => {
setActiveStep((prev) => {
if (button === ENavigationButton.NEXT) {
if (activeStep < 3) return prev + 1;
if (prev < 3) return prev + 1;
return prev;
} else {
if (activeStep > 0) return prev - 1;
if (prev > 0) return prev - 1;
return prev;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ const correctorOptions: IAutocompleteObject[] = Object.keys(
description: metaAnalysisSpecification.CORRECTOR[corrector]?.summary,
}));

const correctorOpt =
const correctorDefaultOption =
correctorOptions.find((corrector) => corrector.label === 'FDRCorrector') || null;
const algorithmOpt = metaAnalyticAlgorithms.find((algo) => algo.label === 'MKDADensity') || null;
const algorithmDefaultOption =
metaAnalyticAlgorithms.find((algo) => algo.label === 'MKDADensity') || null;

export {
getDefaultValuesForTypeAndParameter,
metaAnalysisSpecification,
metaAnalyticAlgorithms,
correctorOptions,
correctorOpt,
algorithmOpt,
correctorDefaultOption,
algorithmDefaultOption,
};
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('CreateMetaAnalysisSpecificationSelectionStep', () => {
/>
);

const backButton = screen.getByRole('button', { name: 'back' });
const backButton = screen.getByRole('button', { name: 'Back' });
userEvent.click(backButton);

expect(mockOnNavigate).toHaveBeenCalledWith(ENavigationButton.PREV);
Expand All @@ -134,7 +134,7 @@ describe('CreateMetaAnalysisSpecificationSelectionStep', () => {
/>
);

const nextButton = screen.getByRole('button', { name: 'next' });
const nextButton = screen.getByRole('button', { name: 'Next' });
userEvent.click(nextButton);

expect(mockOnNavigate).toHaveBeenCalledWith(ENavigationButton.NEXT);
Expand All @@ -156,7 +156,7 @@ describe('CreateMetaAnalysisSpecificationSelectionStep', () => {
/>
);

const nextButton = screen.getByRole('button', { name: 'next' });
const nextButton = screen.getByRole('button', { name: 'Next' });
expect(nextButton).toBeDisabled();
});

Expand All @@ -176,7 +176,7 @@ describe('CreateMetaAnalysisSpecificationSelectionStep', () => {
/>
);

const nextButton = screen.getByRole('button', { name: 'next' });
const nextButton = screen.getByRole('button', { name: 'Next' });
expect(nextButton).toBeDisabled();
});

Expand Down Expand Up @@ -207,7 +207,7 @@ describe('CreateMetaAnalysisSpecificationSelectionStep', () => {
/>
);

const nextButton = screen.getByRole('button', { name: 'next' });
const nextButton = screen.getByRole('button', { name: 'Next' });
expect(nextButton).toBeDisabled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ const CreateMetaAnalysisSpecificationSelectionStep: React.FC<{
const [selectedValue, setSelectedValue] = useState<IAnalysesSelection>(props.selection);

const handleNavigate = (button: ENavigationButton) => {
if (selectedValue?.selectionKey && selectedValue?.type !== EPropertyType.NONE)
if (selectedValue?.selectionKey && selectedValue?.type !== EPropertyType.NONE) {
props.onChooseSelection({
...selectedValue,
});
}
props.onNavigate(button);
};

Expand Down Expand Up @@ -97,7 +98,7 @@ const CreateMetaAnalysisSpecificationSelectionStep: React.FC<{
onClick={() => handleNavigate(ENavigationButton.PREV)}
variant="outlined"
>
back
Back
</Button>
<SelectAnalysesSummaryComponent
annotationdId={annotationId || ''}
Expand All @@ -113,7 +114,7 @@ const CreateMetaAnalysisSpecificationSelectionStep: React.FC<{
}
onClick={() => handleNavigate(ENavigationButton.NEXT)}
>
next
Next
</Button>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const ProjectPage: React.FC = (props) => {
borderTopRightRadius: '6px',
borderColor: 'lightgray',
borderBottom: '0px',
marginBottom: '-1px',
marginBottom: '-2px',
},
'.MuibuttonBase-root': {},
transition: 'none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ const ProjectViewMetaAnalyses: React.FC = () => {
.filter((id): id is string => id !== undefined);
}
}
const {
data = [],
isLoading,
isError,
isRefetching,
} = useGetMetaAnalysesByIds(metaAnalysisIds);
const { data = [], isLoading, isError } = useGetMetaAnalysesByIds(metaAnalysisIds);
const canEditMetaAnalyses = useProjectMetaAnalysisCanEdit();
const projectIdFromProject = useProjectId();
const [createMetaAnalysisDialogIsOpen, setCreateMetaAnalysisDialogIsOpen] = useState(false);
Expand All @@ -49,7 +44,7 @@ const ProjectViewMetaAnalyses: React.FC = () => {
);

return (
<StateHandlerComponent isLoading={isLoading || isRefetching} isError={isError}>
<StateHandlerComponent isLoading={isLoading} isError={isError}>
<CreateMetaAnalysisSpecificationDialogBase
isOpen={createMetaAnalysisDialogIsOpen}
onCloseDialog={() => setCreateMetaAnalysisDialogIsOpen(false)}
Expand Down

0 comments on commit 47dbf03

Please sign in to comment.