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 statuses #325

Merged
merged 4 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':
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');
});
});
});