Skip to content

Commit

Permalink
feat(dataDownloadListActions): Ran Eslint to format code, removed unn…
Browse files Browse the repository at this point in the history
…eeded var from ActionButtons component
  • Loading branch information
jarvisraymond-uchicago committed Nov 9, 2023
1 parent c748668 commit f5e8476
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import DownloadJsonFile from './DownloadUtils/DownloadJsonFile';
const ActionButtons = ({
discoveryConfig,
resourceInfo,
data,
}): JSX.Element => {
const [downloadStatus, setDownloadStatus] = useState({
inProgress: false,
Expand All @@ -32,13 +31,15 @@ const ActionButtons = ({
</Button>
</Col>
*/}
{discoveryConfig?.features.exportToWorkspace.studyMetadataFieldName &&
discoveryConfig?.features.exportToWorkspace.enableDownloadStudyMetadata &&
resourceInfo?.study_metadata &&
(
{discoveryConfig?.features.exportToWorkspace.studyMetadataFieldName
&& discoveryConfig?.features.exportToWorkspace.enableDownloadStudyMetadata
&& resourceInfo?.study_metadata
&& (
<Col flex='1 0 auto'>
<Button className='discovery-action-bar-button'
onClick={()=> DownloadJsonFile("study-level-metadata", resourceInfo.study_metadata)}>
<Button
className='discovery-action-bar-button'
onClick={() => DownloadJsonFile('study-level-metadata', resourceInfo.study_metadata)}
>
Download <br />
Study-Level Metadata
</Button>
Expand All @@ -52,7 +53,7 @@ const ActionButtons = ({
HandleDownloadManifestClick(
discoveryConfig,
[resourceInfo],
false
false,
);
}}
>
Expand All @@ -64,9 +65,7 @@ const ActionButtons = ({
<Col flex='1 0 auto'>
<Button
className='discovery-action-bar-button'
onClick={() =>
DownloadAllFiles(studyIDs, downloadStatus, setDownloadStatus)
}
onClick={() => DownloadAllFiles(studyIDs, downloadStatus, setDownloadStatus)}
>
Download All Files
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, rerender } from '@testing-library/react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import ActionButtons from './ActionButtons';

Expand Down Expand Up @@ -27,18 +27,19 @@ describe('ActionButtons', () => {
discoveryConfig={mockDiscoveryConfig}
resourceInfo={null}
data={mockData}
/>
/>,
);
// Check that the button is no longer rendered
expect(queryByText(buttonText)).toBeNull();
}
};

const checkExportToWorkspaceConditional = (buttonText:string,condition: string )=>{
const checkExportToWorkspaceConditional = (buttonText:string, condition: string) => {
const { getByText, queryByText, rerender } = render(
<ActionButtons
discoveryConfig={mockDiscoveryConfig}
resourceInfo={mockResourceInfo}
data={mockData} />
data={mockData}
/>,
);
const targetButton = getByText(buttonText);
expect(targetButton).toBeInTheDocument();
Expand All @@ -50,29 +51,23 @@ describe('ActionButtons', () => {
discoveryConfig={changedConfig}
resourceInfo={mockResourceInfo}
data={mockData}
/>
/>,
);
// Check that the button is no longer rendered
expect(queryByText(buttonText)).toBeNull();
}
};

/* TESTS */
test('renders Download Study-Level Metadata button based on conditionals', () => {
const buttonText = 'Study-Level Metadata';
checkExportToWorkspaceConditional(buttonText, 'enableDownloadStudyMetadata');
checkExportToWorkspaceConditional(buttonText,'studyMetadataFieldName');
checkResourceInfoConditional(buttonText);

const buttonText = 'Study-Level Metadata';
checkExportToWorkspaceConditional(buttonText, 'enableDownloadStudyMetadata');
checkExportToWorkspaceConditional(buttonText, 'studyMetadataFieldName');
checkResourceInfoConditional(buttonText);
});

test('renders Download File Manifest button based on conditionals', () => {
checkExportToWorkspaceConditional('Download File Manifest','enableDownloadManifest' );
checkExportToWorkspaceConditional('Download File Manifest', 'enableDownloadManifest');
});
test('renders Download All Files button based on conditionals', () => {
checkExportToWorkspaceConditional('Download All Files','enableDownloadZip' );
checkExportToWorkspaceConditional('Download All Files', 'enableDownloadZip');
});




});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import DownloadAllModal from './DownloadAllModal';
import DownloadStatus from '../../Interfaces/DownloadStatus';
Expand All @@ -22,7 +22,7 @@ test('DownloadAllModal renders correctly and closes on button click', () => {
<DownloadAllModal
downloadStatus={mockDownloadStatus}
setDownloadStatus={mockSetDownloadStatus}
/>
/>,
);

// Check if the modal renders with the provided title and content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { jobAPIPath } from '../../../../../localconf';
import DownloadStatus from '../../Interfaces/DownloadStatus';

const JOB_POLLING_INTERVAL = 5000;
const DOWNLOAD_SUCCEEDED_MESSAGE =
"Your download has been prepared. If your download doesn't start automatically, please follow this direct link:";
const DOWNLOAD_SUCCEEDED_MESSAGE = 'Your download has been prepared. If your download doesn\'t start automatically, please follow this direct link:';

const DOWNLOAD_FAIL_STATUS: DownloadStatus = {
inProgress: false,
Expand All @@ -24,7 +23,7 @@ const DOWNLOAD_FAIL_STATUS: DownloadStatus = {
const checkDownloadStatus = (
uid: string,
downloadStatus: DownloadStatus,
setDownloadStatus: (arg0: DownloadStatus) => void
setDownloadStatus: (arg0: DownloadStatus) => void,
) => {
fetchWithCreds({ path: `${jobAPIPath}status?UID=${uid}` }).then(
(statusResponse) => {
Expand All @@ -43,7 +42,7 @@ const checkDownloadStatus = (
inProgress: false,
message: {
title: 'Download failed',
content: <p>{ output }</p> ,
content: <p>{ output }</p>,
active: true,
},
});
Expand Down Expand Up @@ -98,17 +97,17 @@ const checkDownloadStatus = (
JOB_POLLING_INTERVAL,
uid,
downloadStatus,
setDownloadStatus
setDownloadStatus,
);
}
}
},
);
};

const DownloadAllFiles = (
studyIDs: any[],
downloadStatus: DownloadStatus,
setDownloadStatus: (arg0: DownloadStatus) => void
setDownloadStatus: (arg0: DownloadStatus) => void,
) => {
fetchWithCreds({
path: `${jobAPIPath}dispatch`,
Expand Down Expand Up @@ -155,7 +154,7 @@ const DownloadAllFiles = (
JOB_POLLING_INTERVAL,
uid,
downloadStatus,
setDownloadStatus
setDownloadStatus,
);
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import FileSaver from 'file-saver';

const DownloadJsonFile = (fileName: string, data: object) => {
const blob = new Blob([JSON.stringify(data, null, 2)], {
type: 'text/json',
});
FileSaver.saveAs(blob, fileName +'.json');
}
const blob = new Blob([JSON.stringify(data, null, 2)], {
type: 'text/json',
});
FileSaver.saveAs(blob, `${fileName}.json`);
};

export default DownloadJsonFile;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const HandleDownloadManifestClick = (
}
}
});
DownloadJsonFile('manifest', manifest)
DownloadJsonFile('manifest', manifest);
};

export default HandleDownloadManifestClick;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const DataDownloadList = ({
<ActionButtons
discoveryConfig={discoveryConfig}
resourceInfo={resourceInfo}
data={data}
/>
<List
itemLayout='horizontal'
Expand Down

0 comments on commit f5e8476

Please sign in to comment.