All files / pages UserProfilePage.tsx

100% Statements 7/7
100% Branches 4/4
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48      1x       5x       6x   6x 3x     3x   3x                                                        
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useCurrentUser } from "main/utils/currentUser";
 
const testIdPrefix = "UserProfilePage";
 
// Roles come back from the backend as e.g. "ROLE_ADMIN"; display them as "admin".
function friendlyRoleName(role: string): string {
  return role.replace(/^ROLE_/, "").toLowerCase();
}
 
export default function UserProfilePage(): React.JSX.Element {
  const currentUser = useCurrentUser();
 
  if (!currentUser.loggedIn) {
    return <BasicLayout>Loading...</BasicLayout>;
  }
 
  const { user, rolesList } = currentUser.root;
 
  return (
    <BasicLayout>
      <div className="pt-2">
        <h1 data-testid={`${testIdPrefix}-title`}>User Profile</h1>
        <table className="table table-striped" style={{ maxWidth: "600px" }}>
          <tbody>
            <tr>
              <th>Name</th>
              <td data-testid={`${testIdPrefix}-name`}>
                {user.fullName ?? "Not specified"}
              </td>
            </tr>
            <tr>
              <th>Email</th>
              <td data-testid={`${testIdPrefix}-email`}>{user.email}</td>
            </tr>
            <tr>
              <th>Roles</th>
              <td data-testid={`${testIdPrefix}-roles`}>
                {rolesList.map(friendlyRoleName).join(", ")}
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </BasicLayout>
  );
}