From c8228574abdd80b2cf80900d9f71a19ddc410af9 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 12 Jun 2024 11:03:18 +0200 Subject: [PATCH] Ensure last_activity renders as empty string when it's null (#6348) --- .../dashboard/AssignmentActivity.tsx | 8 ++-- .../dashboard/test/AssignmentActivity-test.js | 41 ++++++++----------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lms/static/scripts/frontend_apps/components/dashboard/AssignmentActivity.tsx b/lms/static/scripts/frontend_apps/components/dashboard/AssignmentActivity.tsx index 3d7c15776c..c24d5082dc 100644 --- a/lms/static/scripts/frontend_apps/components/dashboard/AssignmentActivity.tsx +++ b/lms/static/scripts/frontend_apps/components/dashboard/AssignmentActivity.tsx @@ -96,11 +96,13 @@ export default function AssignmentActivity() { renderItem={(stats, field) => { if (['annotations', 'replies'].includes(field)) { return
{stats[field]}
; + } else if (field === 'last_activity') { + return stats.last_activity + ? formatDateTime(new Date(stats.last_activity)) + : ''; } - return field === 'last_activity' && stats.last_activity - ? formatDateTime(new Date(stats.last_activity)) - : stats[field] ?? `Student ${stats.id.substring(0, 10)}`; + return stats[field] ?? `Student ${stats.id.substring(0, 10)}`; }} /> diff --git a/lms/static/scripts/frontend_apps/components/dashboard/test/AssignmentActivity-test.js b/lms/static/scripts/frontend_apps/components/dashboard/test/AssignmentActivity-test.js index 65df0d2440..a9d5df6ff2 100644 --- a/lms/static/scripts/frontend_apps/components/dashboard/test/AssignmentActivity-test.js +++ b/lms/static/scripts/frontend_apps/components/dashboard/test/AssignmentActivity-test.js @@ -128,9 +128,24 @@ describe('AssignmentActivity', () => { fieldName: 'last_activity', expectedValue: formatDateTime(new Date('2024-01-01T10:35:18')), }, - ].forEach(({ fieldName, expectedValue }) => { + // Render last_activity when it's null + { + fieldName: 'last_activity', + expectedValue: '', + studentStats: { last_activity: null }, + }, + // Render display_name when it's null + { + fieldName: 'display_name', + expectedValue: 'Student e4ca30ee27', + studentStats: { + id: 'e4ca30ee27eda1169d00b83f2a86e3494ffd9b12', + display_name: null, + }, + }, + ].forEach(({ fieldName, expectedValue, studentStats }) => { it('renders every field as expected', () => { - const studentStats = { + const fallbackStudentStats = { display_name: 'Jane Doe', last_activity: '2024-01-01T10:35:18', annotations: 37, @@ -141,33 +156,13 @@ describe('AssignmentActivity', () => { const item = wrapper .find('OrderableActivityTable') .props() - .renderItem(studentStats, fieldName); + .renderItem(studentStats ?? fallbackStudentStats, fieldName); const value = typeof item === 'string' ? item : mount(item).text(); assert.equal(value, expectedValue); }); }); - it('renders fallback for students without display_name', () => { - const student = { - id: 'e4ca30ee27eda1169d00b83f2a86e3494ffd9b12', - display_name: null, - annotation_metrics: { - last_activity: null, - annotations: 0, - replies: 0, - }, - }; - const wrapper = createComponent(); - - const item = wrapper - .find('OrderableActivityTable') - .props() - .renderItem(student, 'display_name'); - - assert.equal(item, 'Student e4ca30ee27'); - }); - it( 'should pass a11y checks', checkAccessibility({