All files / pages StudentProfilePage.js

100% Statements 9/9
100% Branches 2/2
100% Functions 2/2
100% Lines 9/9

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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83                    1x 6x 6x           6x                 6x 3x     3x   3x                                                         1x                                        
import { Row, Col, Button } from "react-bootstrap";
import RoleBadge from "main/components/Profile/RoleBadge";
import { useCurrentUser } from "main/utils/currentUser";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { hasRole } from "main/utils/currentUser";
import { useBackend } from "main/utils/useBackend";
import { Inspector } from "react-inspector";
import { useNavigate } from "react-router-dom";
import RecommendationRequestTable from "main/components/RecommendationRequest/RecommendationRequestTable";
 
const StudentProfilePage = () => {
  const { data: currentUser } = useCurrentUser();
  const navigate = useNavigate();
 
  const {
    data: requests,
    error: _error,
    status: _status,
  } = useBackend(
    // Stryker disable next-line all : don't test internal caching of React Query
    ["/api/recommendationrequest/requester/all"],
    // Stryker disable next-line all
    { method: "GET", url: "/api/recommendationrequest/requester/all" },
    // Stryker disable next-line all
    [],
  );
 
  if (!hasRole(currentUser, "ROLE_STUDENT")) {
    return <p>Students only.</p>;
  }
 
  const { email, pictureUrl, fullName } = currentUser.root.user;
 
  return (
    <BasicLayout>
      <Row className="align-items-center profile-header mb-5 text-center text-md-left">
        <Col md={2}>
          <img
            src={pictureUrl}
            alt="Profile"
            className="rounded-circle img-fluid profile-picture mb-3 mb-md-0"
            data-testid="profile-picture"
          />
        </Col>
        <Col md>
          <h2 data-testid="profile-name">{fullName}</h2>
          <p className="lead text-muted" data-testid="profile-email">
            {email}
          </p>
          <RoleBadge role={"ROLE_STUDENT"} currentUser={currentUser} />
        </Col>
      </Row>
 
      <Row className="text-left mb-4">
        <Inspector data={currentUser.root} />
      </Row>
 
      <div className="d-flex justify-content-between align-items-center mb-3">
        <h1 data-testid="requests-header">My Recommendation Requests</h1>
        <Button
          variant="primary"
          // Stryker disable next-line all
          onClick={() => navigate("/recommendationrequest/post")}
          data-testid="create-request-button"
        >
          Create New Request
        </Button>
      </div>
 
      <div data-testid="RecommendationRequestTable">
        <RecommendationRequestTable
          requests={requests}
          currentUser={currentUser}
          // Stryker disable next-line all
          showActions={true}
        />
      </div>
    </BasicLayout>
  );
};
 
export default StudentProfilePage;