Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 68a69d1
Merge: f9408ad 7f4d157
Author: Chuck McAndrew <[email protected]>
Date:   Thu Feb 25 11:39:32 2021 -0500

    Merge pull request #196 from adhocteam/cm-310-update-file-statuses

    simplify file upload statuses

commit 7f4d157
Author: Chuck McAndrew <[email protected]>
Date:   Thu Feb 25 10:43:33 2021 -0500

    fmt

commit b7724ce
Author: Chuck McAndrew <[email protected]>
Date:   Thu Feb 25 10:39:19 2021 -0500

    add tests for getStatus()

commit cc12546
Author: Chuck McAndrew <[email protected]>
Date:   Thu Feb 25 10:04:59 2021 -0500

    simplify file upload statuses
  • Loading branch information
dcmcand committed Feb 25, 2021
1 parent af148bc commit c165a41
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
26 changes: 25 additions & 1 deletion frontend/src/components/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ Dropzone.propTypes = {
id: PropTypes.string.isRequired,
};

export const getStatus = (status) => {
switch (status) {
case 'UPLOADING':
return 'Uploading';
case 'UPLOADED':
return 'Uploaded';
case 'UPLOAD_FAILED':
return 'Upload Failed';
case 'SCANNING_QUEUED':
return 'Scanning';
case 'QUEUEING_FAILED':
return 'Upload Failed';
case 'SCANNING':
return 'Scanning';
case 'APPROVED':
return 'Approved';
case 'REJECTED':
return 'Rejected';
default:
break;
}
return 'Upload Failed';
};

const deleteFileModal = ({
onFileRemoved, files, index, closeModal,
}) => {
Expand Down Expand Up @@ -160,7 +184,7 @@ const FileTable = ({ onFileRemoved, files }) => {
{`${(file.fileSize / 1000).toFixed(1)} KB`}
</td>
<td>
{file.status}
{getStatus(file.status)}
</td>
<td>
<Button
Expand Down
24 changes: 22 additions & 2 deletions frontend/src/components/__tests__/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
render, fireEvent, waitFor, act, screen,
} from '@testing-library/react';
import * as fileFetcher from '../../fetchers/File';

import FileUploader from '../FileUploader';
import FileUploader, { getStatus } from '../FileUploader';

describe('FileUploader', () => {
jest.spyOn(fileFetcher, 'default').mockImplementation(() => Promise.resolve());
Expand Down Expand Up @@ -83,4 +82,25 @@ describe('FileUploader', () => {
fireEvent.click(cancelButton);
expect(mockOnChange).not.toHaveBeenCalled();
});
describe('getStatus tests', () => {
it('returns the correct statuses', () => {
let got;
got = getStatus('UPLOADING');
expect(got).toBe('Uploading');
got = getStatus('UPLOADED');
expect(got).toBe('Uploaded');
got = getStatus('UPLOAD_FAILED');
expect(got).toBe('Upload Failed');
got = getStatus('QUEUING_FAILED');
expect(got).toBe('Upload Failed');
got = getStatus('SCANNING_QUEUED');
expect(got).toBe('Scanning');
got = getStatus('SCANNING');
expect(got).toBe('Scanning');
got = getStatus('APPROVED');
expect(got).toBe('Approved');
got = getStatus('REJECTED');
expect(got).toBe('Rejected');
});
});
});

0 comments on commit c165a41

Please sign in to comment.