Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify file upload statuses #196

Merged
merged 3 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put these statuses in a constant somewhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was wondering about that. certainly could, I did on the backend.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with leaving these here if it's the only place they're referenced. This function basically becomes the constant.

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');
});
});
});