diff --git a/src/pages/ExamsPage/components/AttemptList.jsx b/src/pages/ExamsPage/components/AttemptList.jsx index 395ff2e..8b5ad39 100644 --- a/src/pages/ExamsPage/components/AttemptList.jsx +++ b/src/pages/ExamsPage/components/AttemptList.jsx @@ -145,23 +145,26 @@ const AttemptList = ({ attempts }) => { }, { Header: formatMessage(messages.examAttemptsTableHeaderStartedAt), - Cell: ({ row }) => (formatDate(row.original.started_at, { + // The ternary operator here sets the value of the started/completed at datetime to + // "-" if the value is null, as otherwise the DataTable will default to the + // UNIX epoch (i.e. 1/1/1970) for some reason. + Cell: ({ row }) => (row.original.started_at ? formatDate(row.original.started_at, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', - })), + }) : '-'), }, { Header: formatMessage(messages.examAttemptsTableHeaderCompletedAt), - Cell: ({ row }) => (formatDate(row.original.completed_at, { + Cell: ({ row }) => (row.original.completed_at ? formatDate(row.original.completed_at, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', - })), + }) : '-'), }, { Header: formatMessage(messages.examAttemptsTableHeaderStatus), diff --git a/src/pages/ExamsPage/components/AttemptList.test.jsx b/src/pages/ExamsPage/components/AttemptList.test.jsx index 964292b..3a20a58 100644 --- a/src/pages/ExamsPage/components/AttemptList.test.jsx +++ b/src/pages/ExamsPage/components/AttemptList.test.jsx @@ -57,6 +57,23 @@ describe('AttemptList', () => { } }); }); + it('attempt null start and end time makes "-" appear in UI', () => { + render(); + // Expect a two cells with '-' to be present (index 1 is for the second entry) + expect(screen.getAllByText('-')[1]).toBeInTheDocument(); + }); it('filtering by status displays the correct entry', () => { render(); // Get the 2nd row of data which has the values of defaultAttemptsData[1]