Skip to content

Commit

Permalink
Merge pull request #809 from classtranscribe/hd/improve-admin-instruc…
Browse files Browse the repository at this point in the history
…tor-list-name-formatting

Improve Instructor List Admin Page formatting to check lastName before outputting unknown (Closes #808)
  • Loading branch information
angrave committed Jun 2, 2024
2 parents ec8c00a + d8ba902 commit 6e3ffcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/screens/Admin/Instructors/InstructorList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export default function InstructorList({ instructors, loading, currUni, onInacti
setSearchText('');
};

const formatInstructorName = (instructor) => {
if (!(instructor.firstName || instructor.lastName)) {
return "Unknown";
}

return `${instructor.firstName || ''} ${instructor.lastName || ''}`.trim();;
}

return (
<>
<div className="filter">
Expand All @@ -48,7 +56,7 @@ export default function InstructorList({ instructors, loading, currUni, onInacti
</div>
{result.map((inst) => (
<AdminListItem
header={`${inst.firstName || 'Unknown'} ${inst.lastName || ''}`}
header={formatInstructorName(inst)}
path="instructor"
inactive={() => onInactive(inst.email)}
loading={loading}
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Admin/Instructors/InstructorList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Instructor List', () => {

expect(screen.getByText("Harsh Deep")).toBeVisible();
expect(screen.getByText("Alan")).toBeVisible();
expect(screen.getByText("Unknown Turing")).toBeVisible();
expect(screen.getByText("Turing")).toBeVisible();

expect(screen.getByText("Email: [email protected]")).toBeVisible();
expect(screen.getByText("Email: [email protected]")).toBeVisible();
Expand All @@ -61,7 +61,7 @@ describe('Instructor List', () => {
await userEvent.click(searchButton);

expect(numberOfInstructors()).toBe(1);
expect(screen.getByText("Unknown Turing")).toBeVisible();
expect(screen.getByText("Turing")).toBeVisible();

// Email
await userEvent.clear(searchField);
Expand Down

0 comments on commit 6e3ffcb

Please sign in to comment.