Skip to content

Commit 3045551

Browse files
authored
[FIX] Handle unknown imageing modalities gracefully (#644)
* Fixed the runtime error that broke the app when unknown imaging modalities are present in the result * Fixed component test * Updated test comment
1 parent 91adfae commit 3045551

3 files changed

Lines changed: 57 additions & 17 deletions

File tree

cypress/component/ResultContainer.cy.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ResultContainer from '../../src/components/ResultContainer';
2-
import { protectedResponse2 } from '../fixtures/mocked-responses';
2+
import { protectedResponse2, responseWithUnknownModality } from '../fixtures/mocked-responses';
33

44
describe('ResultContainer', () => {
55
it('Displays a set of Result Cards, select all checkbox, a disabled download result button, summary stats, and how to get data dialog button', () => {
@@ -58,4 +58,19 @@ describe('ResultContainer', () => {
5858
.should('be.visible')
5959
.should('contain', "Click 'Submit Query' for results");
6060
});
61+
it('Handles unknown modalities gracefully without breaking', () => {
62+
cy.mount(
63+
<ResultContainer
64+
response={responseWithUnknownModality}
65+
assessmentOptions={[]}
66+
diagnosisOptions={[]}
67+
/>
68+
);
69+
cy.get('[data-cy="card-https://someportal.org/datasets/ds0003"]').should('be.visible');
70+
cy.get('[data-cy="modality-buttons"]').within(() => {
71+
// Should show only one button (T1) button, and not the unknown modality
72+
cy.contains('button', 'T1').should('be.visible');
73+
cy.get('button').should('have.length', 1);
74+
});
75+
});
6176
});

cypress/fixtures/mocked-responses.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,25 @@ export const failedPipelineVersionOptions = {
346346
},
347347
],
348348
};
349+
350+
export const datasetWithUnknownModality = {
351+
records_protected: false,
352+
node_name: 'some-node-name',
353+
dataset_uuid: 'https://someportal.org/datasets/ds0003',
354+
dataset_name: 'dataset with unknown modality',
355+
dataset_portal_uri: 'https://example.com/dataset',
356+
dataset_total_subjects: 50,
357+
num_matching_subjects: 5,
358+
subject_data: 'protected',
359+
image_modals: [
360+
'http://purl.org/nidash/nidm#T1Weighted',
361+
'http://purl.org/nidash/nidm#UnknownModality',
362+
],
363+
available_pipelines: {},
364+
};
365+
366+
export const responseWithUnknownModality = {
367+
errors: [],
368+
responses: [datasetWithUnknownModality],
369+
nodes_response_status: 'success',
370+
};

src/components/ResultCard.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,27 @@ const ResultCard = memo(
125125
</Tooltip>
126126
)}
127127
</div>
128-
<div className="justify-self-end">
128+
<div className="justify-self-end" data-cy="modality-buttons">
129129
<ButtonGroup>
130-
{imageModals.sort().map((modal) => (
131-
<Button
132-
key={modal}
133-
variant="contained"
134-
disableElevation
135-
sx={{
136-
backgroundColor: modalities[modal].bgColor,
137-
'&:hover': {
130+
{imageModals
131+
.sort()
132+
.filter((modal) => Object.keys(modalities).includes(modal))
133+
.map((modal) => (
134+
<Button
135+
key={modal}
136+
variant="contained"
137+
disableElevation
138+
sx={{
138139
backgroundColor: modalities[modal].bgColor,
139-
cursor: 'default',
140-
},
141-
}}
142-
>
143-
{modalities[modal].name}
144-
</Button>
145-
))}
140+
'&:hover': {
141+
backgroundColor: modalities[modal].bgColor,
142+
cursor: 'default',
143+
},
144+
}}
145+
>
146+
{modalities[modal].name}
147+
</Button>
148+
))}
146149
</ButtonGroup>
147150
</div>
148151
</div>

0 commit comments

Comments
 (0)