Skip to content

Commit

Permalink
Ran prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanaem committed Feb 16, 2024
1 parent c4a8efb commit e48e087
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 105 deletions.
88 changes: 60 additions & 28 deletions cypress/e2e/APIRequests.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { mixedResponse, nodeOptions, emptyDiagnosisOptions, emptyAssessmentToolOptions } from '../fixtures/mocked-responses';
import {
mixedResponse,
nodeOptions,
emptyDiagnosisOptions,
emptyAssessmentToolOptions,
} from '../fixtures/mocked-responses';

describe('API request', () => {
it('Intercepts the request sent to the API and asserts over the request url', () => {
cy.intercept({
method: 'GET',
url: 'query/?*',
}, mixedResponse).as('call');
cy.intercept({
method: 'GET',
url: '/nodes/',
}, nodeOptions).as('getNodes');
cy.intercept(
{
method: 'GET',
url: 'query/?*',
},
mixedResponse
).as('call');
cy.intercept(
{
method: 'GET',
url: '/nodes/',
},
nodeOptions
).as('getNodes');
cy.visit('/?node=OpenNeuro');
// We need to wait for the fetch to complete and populate the
// dropdown with nodes and selecting OpenNeuro before making the request
Expand All @@ -20,32 +31,53 @@ describe('API request', () => {
cy.wait('@call').its('request.url').should('contains', '&min_age=10&max_age=30');
});
it('Empty responses for diagnosis and Assessment make a toast appear', () => {
cy.intercept({
method: 'GET',
url: '/attributes/nb:Diagnosis',
}, emptyDiagnosisOptions).as('getDiagnosisOptions');
cy.intercept({
method: 'GET',
url: '/attributes/nb:Assessment',
}, emptyAssessmentToolOptions).as('getAssessmentToolOptions');
cy.intercept(
{
method: 'GET',
url: '/attributes/nb:Diagnosis',
},
emptyDiagnosisOptions
).as('getDiagnosisOptions');
cy.intercept(
{
method: 'GET',
url: '/attributes/nb:Assessment',
},
emptyAssessmentToolOptions
).as('getAssessmentToolOptions');
cy.visit('/');
cy.wait('@getDiagnosisOptions');
cy.get('.notistack-SnackbarContainer').should('contain', 'No Diagnosis options were available');
cy.get('.notistack-SnackbarContainer').should('contain', 'No Assessment tool options were available');
cy.get('.notistack-SnackbarContainer').should(
'contain',
'No Assessment tool options were available'
);
});
it('Failed responses for diagnosis and assessment make an error toast appear', () => {
cy.intercept({
method: 'GET',
url: '/attributes/nb:Diagnosis',
}, { statusCode: 500 }).as('getDiagnosisOptions');
cy.intercept({
method: 'GET',
url: '/attributes/nb:Assessment',
}, { statusCode: 500 }).as('getAssessmentToolOptions');
cy.intercept(
{
method: 'GET',
url: '/attributes/nb:Diagnosis',
},
{ statusCode: 500 }
).as('getDiagnosisOptions');
cy.intercept(
{
method: 'GET',
url: '/attributes/nb:Assessment',
},
{ statusCode: 500 }
).as('getAssessmentToolOptions');
cy.visit('/');
cy.wait('@getDiagnosisOptions');
cy.get('.notistack-SnackbarContainer').should('contain', 'Failed to retrieve Diagnosis options');
cy.get('.notistack-SnackbarContainer').should(
'contain',
'Failed to retrieve Diagnosis options'
);
cy.wait('@getAssessmentToolOptions');
cy.get('.notistack-SnackbarContainer').should('contain', 'Failed to retrieve Assessment tool options');
cy.get('.notistack-SnackbarContainer').should(
'contain',
'Failed to retrieve Assessment tool options'
);
});
});
49 changes: 27 additions & 22 deletions cypress/e2e/Alert.cy.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
describe('Alert', () => {
it('Correctly displays and dismisses the alert', () => {
cy.intercept({
method: 'GET',
url: '/nodes/',
}).as('getNodes');
cy.visit('/?node=All');
// We need to wait for the fetch to complete and populate the
// dropdown with nodes before searching for OpenNeuro
cy.wait('@getNodes');
cy.get('[data-cy="openneuro-alert"]').should('be.visible').should('contain', 'The OpenNeuro node is being actively annotated at the participant');
it('Correctly displays and dismisses the alert', () => {
cy.intercept({
method: 'GET',
url: '/nodes/',
}).as('getNodes');
cy.visit('/?node=All');
// We need to wait for the fetch to complete and populate the
// dropdown with nodes before searching for OpenNeuro
cy.wait('@getNodes');
cy.get('[data-cy="openneuro-alert"]')
.should('be.visible')
.should('contain', 'The OpenNeuro node is being actively annotated at the participant');

cy.get('[data-cy="Neurobagel graph-categorical-field"]').type('Quebec Parkinson Network{downarrow}{enter}');
cy.get('[data-cy="openneuro-alert"]').should('not.exist');

cy.get('[data-cy="Neurobagel graph-categorical-field"]').should('not.contain', 'All');
cy.get('[data-cy="Neurobagel graph-categorical-field"]').find('[data-testid="CloseIcon"]').click();
cy.get('[data-cy="Neurobagel graph-categorical-field"]').should('contain', 'All');
cy.get('[data-cy="Neurobagel graph-categorical-field"]').type(
'Quebec Parkinson Network{downarrow}{enter}'
);
cy.get('[data-cy="openneuro-alert"]').should('not.exist');

cy.get('[data-cy="Neurobagel graph-categorical-field"]').type('OpenNeuro{downarrow}{enter}');
cy.get('[data-cy="openneuro-alert"]').should('be.visible');
cy.get('[data-cy="Neurobagel graph-categorical-field"]').should('not.contain', 'All');
cy.get('[data-cy="Neurobagel graph-categorical-field"]')
.find('[data-testid="CloseIcon"]')
.click();
cy.get('[data-cy="Neurobagel graph-categorical-field"]').should('contain', 'All');

cy.get('[data-cy="openneuro-alert"]').find('[data-testid="CloseIcon"]').click();
cy.get('[data-cy="openneuro-alert"]').should('not.exist');
});
cy.get('[data-cy="Neurobagel graph-categorical-field"]').type('OpenNeuro{downarrow}{enter}');
cy.get('[data-cy="openneuro-alert"]').should('be.visible');

cy.get('[data-cy="openneuro-alert"]').find('[data-testid="CloseIcon"]').click();
cy.get('[data-cy="openneuro-alert"]').should('not.exist');
});
});
8 changes: 6 additions & 2 deletions cypress/e2e/Checkbox.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ describe('Dataset result checkbox', () => {
cy.visit('/');
cy.get('[data-cy="submit-query"]').click();
cy.wait('@call');
cy.get('[data-cy="card-http://neurobagel.org/vocab/cool-dataset-checkbox"]').find('input').check();
cy.get('[data-cy="card-http://neurobagel.org/vocab/cool-dataset-checkbox"]')
.find('input')
.check();
cy.get('[data-cy="submit-query"]').click();
cy.wait('@call');
cy.get('[data-cy="card-http://neurobagel.org/vocab/cool-dataset-checkbox"]').should('not.be.checked');
cy.get('[data-cy="card-http://neurobagel.org/vocab/cool-dataset-checkbox"]').should(
'not.be.checked'
);
});
});
31 changes: 15 additions & 16 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ function App() {
`${attributesURL}${dataElementURI}`
);
return response.data[dataElementURI];
}
catch (err) {
} catch (err) {
return null;
}
}

getAttributes('nb:Diagnosis').then(diagnosisResponse => {
getAttributes('nb:Diagnosis').then((diagnosisResponse) => {
if (diagnosisResponse === null) {
enqueueSnackbar('Failed to retrieve Diagnosis options', { variant: 'error' });
} else if (diagnosisResponse.length === 0) {
Expand All @@ -67,7 +66,7 @@ function App() {
}
});

getAttributes('nb:Assessment').then(assessmentResponse => {
getAttributes('nb:Assessment').then((assessmentResponse) => {
if (assessmentResponse === null) {
enqueueSnackbar('Failed to retrieve Assessment tool options', { variant: 'error' });
} else if (assessmentResponse.length === 0) {
Expand All @@ -81,14 +80,13 @@ function App() {
try {
const response: AxiosResponse<NodeOption[]> = await axios.get(fetchURL);
return response.data;
}
catch (err) {
} catch (err) {
return null;
}
}

if (isFederationAPI) {
getNodeOptions(nodesURL).then(nodeResponse => {
getNodeOptions(nodesURL).then((nodeResponse) => {
if (nodeResponse === null) {
enqueueSnackbar('Failed to retrieve Node options', { variant: 'error' });
} else if (nodeResponse.length === 0) {
Expand All @@ -98,30 +96,27 @@ function App() {
}
});
}

}, []);

useEffect(() => {
if (availableNodes.length > 1) {
const searchParamNodes: string[] = searchParams.getAll('node');

if (searchParamNodes) {
const matchedNodeNames: string[] = searchParamNodes
.filter((nodeName) => availableNodes.some((option) => option.NodeName === nodeName));
const matchedNodeNames: string[] = searchParamNodes.filter((nodeName) =>
availableNodes.some((option) => option.NodeName === nodeName)
);

// If there is no node in the search params, set it to All
if (matchedNodeNames.length === 0) {
setSearchParams({ node: ['All'] });
}
// If there is any node besides All selected, remove All from the list
else if (
matchedNodeNames.length > 1 &&
matchedNodeNames.includes('All')
) {
else if (matchedNodeNames.length > 1 && matchedNodeNames.includes('All')) {
const filteredNodeNames = matchedNodeNames.filter((nodeName) => nodeName !== 'All');
setSearchParams({ node: filteredNodeNames });
}
}
}
}
}, [searchParams, setSearchParams, availableNodes]);

Expand Down Expand Up @@ -257,7 +252,11 @@ function App() {

return (
<>
<SnackbarProvider autoHideDuration={6000} anchorOrigin={{ vertical: 'top', horizontal: 'right' }} maxSnack={7} />
<SnackbarProvider
autoHideDuration={6000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
maxSnack={7}
/>
<Navbar />
{showAlert() && (
<>
Expand Down
34 changes: 17 additions & 17 deletions src/components/CategoricalField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ function CategoricalField({
inputValue,
}: CategoricalFieldProps) {
return (
<Autocomplete
data-cy={`${label}-categorical-field`}
options={options.sort((a, b) => a.label.localeCompare(b.label))}
isOptionEqualToValue={(option, value) => option.id === value.id}
value={inputValue}
renderInput={(params) => (
<TextField
// eslint-disable-next-line react/jsx-props-no-spreading
{...params}
label={label}
placeholder="Select an option"
className="w-full"
/>
)}
multiple={multiple}
onChange={(_, value) => onFieldChange(label, value)}
/>
<Autocomplete
data-cy={`${label}-categorical-field`}
options={options.sort((a, b) => a.label.localeCompare(b.label))}
isOptionEqualToValue={(option, value) => option.id === value.id}
value={inputValue}
renderInput={(params) => (
<TextField
// eslint-disable-next-line react/jsx-props-no-spreading
{...params}
label={label}
placeholder="Select an option"
className="w-full"
/>
)}
multiple={multiple}
onChange={(_, value) => onFieldChange(label, value)}
/>
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/DownloadResultButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function DownloadResultButton({
<span>{button}</span>
</Tooltip>
) : (
button
button
);
}

Expand Down
12 changes: 7 additions & 5 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ function Navbar() {
const [latestReleaseTag, setLatestReleaseTag] = useState('');

useEffect(() => {
// TODO: replace with react-query-tool once there is a release
const GHApiURL = 'https://api.github.com/repos/neurobagel/query-tool/releases/latest';
axios.get(GHApiURL)
// TODO: replace with react-query-tool once there is a release
const GHApiURL = 'https://api.github.com/repos/neurobagel/query-tool/releases/latest';
axios
.get(GHApiURL)
.then((response) => {
const {data} = response;
const { data } = response;
setLatestReleaseTag(data.tag_name);
}).catch(() => {
})
.catch(() => {
setLatestReleaseTag('beta');
});
}, []);
Expand Down
8 changes: 5 additions & 3 deletions src/components/QueryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ function QueryForm({
loading: boolean;
onSubmitQuery: () => void;
}) {

function validateContinuousValue (value: number | null) {
function validateContinuousValue(value: number | null) {
if (value === null) {
// Value is default, user has not entered anything yet
return '';
Expand All @@ -69,7 +68,10 @@ function QueryForm({

const minAgeExceedsMaxAge: boolean = minAge && maxAge ? minAge > maxAge : false;
const disableSubmit: boolean =
minAgeExceedsMaxAge || minAgeHelperText !== '' || maxAgeHelperText !== '' || minNumSessionsHelperText !== '';
minAgeExceedsMaxAge ||
minAgeHelperText !== '' ||
maxAgeHelperText !== '' ||
minNumSessionsHelperText !== '';

return (
<div
Expand Down
6 changes: 5 additions & 1 deletion src/components/ResultCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function ResultCard({
<CardContent>
<div className="grid grid-cols-12 items-center gap-2">
<div className="col-end-1">
<Checkbox data-cy={`card-${datasetUUID}-checkbox`} checked={checked} onChange={() => onCheckboxChange(datasetUUID)} />
<Checkbox
data-cy={`card-${datasetUUID}-checkbox`}
checked={checked}
onChange={() => onCheckboxChange(datasetUUID)}
/>
</div>
<div className="col-span-10 col-start-1">
<Typography variant="h5">{datasetName}</Typography>
Expand Down
Loading

0 comments on commit e48e087

Please sign in to comment.