Skip to content

Commit

Permalink
Ensure last_activity renders as empty string when it's null (#6348)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya authored Jun 12, 2024
1 parent f1f51a0 commit c822857
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ export default function AssignmentActivity() {
renderItem={(stats, field) => {
if (['annotations', 'replies'].includes(field)) {
return <div className="text-right">{stats[field]}</div>;
} 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)}`;
}}
/>
</CardContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down

0 comments on commit c822857

Please sign in to comment.