Skip to content

Commit

Permalink
fix: Type error and incorrect filename formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Mar 28, 2024
1 parent d8d6c77 commit b09141f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/components/DataSubmissions/ExportValidationButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('ExportValidationButton cases', () => {
conciergeName: '',
conciergeEmail: '',
createdAt: '',
updatedAt: ''
updatedAt: '',
intention: 'New'
};

const baseQCResult: Omit<QCResult, "submissionID"> = {
Expand Down Expand Up @@ -121,13 +122,15 @@ describe('ExportValidationButton cases', () => {
});

it.each<{ original: string, expected: string }>([
{ original: "A B C 1 2 3", expected: "ABC123" },
{ original: "long name".repeat(100), expected: "longname".repeat(100) },
{ original: "A B C 1 2 3", expected: "A-B-C-1-2-3" },
{ original: "long name".repeat(100), expected: "long-name".repeat(100) },
{ original: "", expected: "" },
{ original: `non $alpha name $@!819`, expected: "nonalphaname819" },
{ original: `non $alpha name $@!819`, expected: "non-alpha-name-819" },
{ original: " ", expected: "" },
{ original: `_-"a-b+c=d`, expected: "abcd" },
])("should safely name the CSV export file dynamically using submission name and export date", async ({ original, expected }) => {
{ original: `_-"a-b+c=d`, expected: "-a-bcd" },
{ original: "CRDCDH-1234", expected: "CRDCDH-1234" },
{ original: "SPACE-AT-END ", expected: "SPACE-AT-END" },
])("should safely create the CSV filename using submission name and export date", async ({ original, expected }) => {
jest.useFakeTimers().setSystemTime(new Date('2021-01-19T14:54:01Z'));

const mocks: MockedResponse<SubmissionQCResultsResp>[] = [{
Expand Down
3 changes: 2 additions & 1 deletion src/components/DataSubmissions/ExportValidationButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export const ExportValidationButton: React.FC<Props> = ({ submission, fields, di
}

try {
const filename = `${filterAlphaNumeric(submission.name)}-${dayjs().format("YYYY-MM-DDTHHmmss")}.csv`;
const filteredName = filterAlphaNumeric(submission.name?.trim()?.replaceAll(" ", "-"), "-");
const filename = `${filteredName}-${dayjs().format("YYYY-MM-DDTHHmmss")}.csv`;
const unpacked = unpackQCResultSeverities(d.submissionQCResults.results);
const fieldset = Object.entries(fields);
const csvArray = [];
Expand Down

0 comments on commit b09141f

Please sign in to comment.