Skip to content

Commit

Permalink
Merge pull request #325 from adhocteam/main
Browse files Browse the repository at this point in the history
Simplify file statuses
  • Loading branch information
rahearn authored Feb 25, 2021
2 parents 4386da7 + 68a69d1 commit ee38770
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 @@ -78,6 +78,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 FileTable = ({ onFileRemoved, files }) => (
<div className="files-table--container margin-top-2">
<table className="files-table">
Expand Down Expand Up @@ -106,7 +130,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 @@ -73,4 +72,25 @@ describe('FileUploader', () => {

expect(mockOnChange).toHaveBeenCalledWith([file('fileOne')]);
});
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 ee38770

Please sign in to comment.