From 6f6d5d620f61dd12a7be6b9b30bc12924faa7a1b Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Fri, 12 Jan 2024 11:28:01 -0800 Subject: [PATCH 1/6] set publicationYear to dateRevised if it exists, otherwise use datePublished --- src/utils/recordToDataCite.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/recordToDataCite.js b/src/utils/recordToDataCite.js index 3360b03c..61005526 100644 --- a/src/utils/recordToDataCite.js +++ b/src/utils/recordToDataCite.js @@ -59,11 +59,14 @@ function recordToDataCite(metadata, language, region) { contact.role.includes("publisher") ); - // Get the publication year from the datePublished field + // Get the publication year from the datePublished field, if dateRevised contains value use dateRevised as publication year let publicationYear; - if (metadata.datePublished) { - const year = parseInt(metadata.datePublished.slice(0, 4), 10) - publicationYear = Number.isNaN(year) ? undefined : year; + if (metadata.dateRevised) { + const revisedYear = parseInt(metadata.dateRevised.slice(0, 4), 10); + publicationYear = Number.isNaN(revisedYear) ? undefined : revisedYear; + } else if (metadata.datePublished) { + const publishedYear = parseInt(metadata.datePublished.slice(0, 4), 10) + publicationYear = Number.isNaN(publishedYear) ? undefined : publishedYear; } else { publicationYear = undefined; } From d62b343be62ee504f445d028525ce5573782517f Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Fri, 12 Jan 2024 15:03:43 -0800 Subject: [PATCH 2/6] update citation to first take revised date if exists. --- src/components/FormComponents/ApaPreview.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/FormComponents/ApaPreview.jsx b/src/components/FormComponents/ApaPreview.jsx index b7267e05..c1d38c64 100644 --- a/src/components/FormComponents/ApaPreview.jsx +++ b/src/components/FormComponents/ApaPreview.jsx @@ -9,6 +9,7 @@ export function generateCitation(record, language, format) { created, contacts = [], datePublished, + dateRevised, } = record; const publishers = contacts @@ -46,7 +47,7 @@ export function generateCitation(record, language, format) { // seems that only individuals gets cited? Wasnt sure how to get organization name in there return { family: contact.orgName }; }), - issued: { "date-parts": [[datePublished || created]] }, + issued: { "date-parts": [[dateRevised || datePublished || created]] }, publisher: publishers.join(", "), DOI: datasetIdentifier.replace(/https?:\/\/doi\.org\//, ""), version: `v${record.edition}`, From 6c0047f632f164136bd9ae7703873b3ee7b345f8 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Wed, 17 Jan 2024 16:12:23 -0800 Subject: [PATCH 3/6] format date picker date as ISO string instead of Date object --- src/components/FormComponents/DateInput.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/FormComponents/DateInput.jsx b/src/components/FormComponents/DateInput.jsx index 603e1129..d1b6f745 100644 --- a/src/components/FormComponents/DateInput.jsx +++ b/src/components/FormComponents/DateInput.jsx @@ -14,11 +14,12 @@ function formatDate(date) { const m = date.getMonth(); const y = date.getFullYear(); // This is to get around the issue of timezones and dates - return new Date(y, m, d, 12, 0, 0, 0); + return (new Date(y, m, d, 12, 0, 0, 0)).toISOString(); } catch (e) { return null; } } + const DateInput = ({ onChange, value, name, disabled, dateStart, dateEnd }) => { return ( From 7d7e73d1ce18b51fabd4f68e037f3b2090a48dd5 Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Wed, 17 Jan 2024 16:26:48 -0800 Subject: [PATCH 4/6] update test to store mock date as ISO string --- src/components/__tests__/DateInput.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/DateInput.test.jsx b/src/components/__tests__/DateInput.test.jsx index 88a78f5a..143b942c 100644 --- a/src/components/__tests__/DateInput.test.jsx +++ b/src/components/__tests__/DateInput.test.jsx @@ -12,7 +12,7 @@ jest.spyOn(global, "Date").mockImplementation(() => mockedData); Date.now = () => 1606348800; configure({ adapter: new Adapter() }); -const mockEventValue = new Date("2021-09-08T22:23:52.468Z"); +const mockEventValue = new Date("2021-09-08T22:23:52.468Z").toISOString(); const mockComponentName = "date"; const mockOnChange = jest.fn(); From f9fa1efdee7f7f6169382732b56e010b7cacf04a Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Wed, 17 Jan 2024 16:30:11 -0800 Subject: [PATCH 5/6] update mockedData to ISO string --- src/components/__tests__/DateInput.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/DateInput.test.jsx b/src/components/__tests__/DateInput.test.jsx index 143b942c..34af998a 100644 --- a/src/components/__tests__/DateInput.test.jsx +++ b/src/components/__tests__/DateInput.test.jsx @@ -7,7 +7,7 @@ import { KeyboardDatePicker } from "@material-ui/pickers"; import DateInput from "../FormComponents/DateInput"; // this helps mock the a date -const mockedData = new Date("2020-11-26T00:00:00.000Z"); +const mockedData = new Date("2020-11-26T00:00:00.000Z").toISOString(); jest.spyOn(global, "Date").mockImplementation(() => mockedData); Date.now = () => 1606348800; From c0407e94c1523e94f89f205655b1e4ec2962f0ca Mon Sep 17 00:00:00 2001 From: Austen Sorochak Date: Wed, 17 Jan 2024 17:05:47 -0800 Subject: [PATCH 6/6] update DateInput.test to expect date as ISO string instead of object --- src/components/__tests__/DateInput.test.jsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/__tests__/DateInput.test.jsx b/src/components/__tests__/DateInput.test.jsx index 34af998a..58e26747 100644 --- a/src/components/__tests__/DateInput.test.jsx +++ b/src/components/__tests__/DateInput.test.jsx @@ -7,12 +7,14 @@ import { KeyboardDatePicker } from "@material-ui/pickers"; import DateInput from "../FormComponents/DateInput"; // this helps mock the a date -const mockedData = new Date("2020-11-26T00:00:00.000Z").toISOString(); +const mockedData = new Date("2020-11-26T00:00:00.000Z"); jest.spyOn(global, "Date").mockImplementation(() => mockedData); Date.now = () => 1606348800; configure({ adapter: new Adapter() }); -const mockEventValue = new Date("2021-09-08T22:23:52.468Z").toISOString(); + +// Use an ISO string for the mock event value +const mockEventValue = "2021-09-08T22:23:52.468Z"; const mockComponentName = "date"; const mockOnChange = jest.fn(); @@ -33,9 +35,16 @@ describe("", () => { /> ); - wrapper.find(KeyboardDatePicker).props().onChange(mockEventValue); + // Simulate selecting a new date as a Date object + const newDate = new Date("2021-10-08T22:23:52.468Z"); + wrapper.find(KeyboardDatePicker).props().onChange(newDate); + + // The expected value should be an ISO string after being processed by your component + const expectedValue = newDate.toISOString(); + + // Assert that onChange was called with the correct value expect(mockOnChange).toHaveBeenCalledWith({ - target: { value: mockEventValue, name: mockComponentName }, + target: { value: expectedValue, name: mockComponentName }, }); }); });