All files / components/Game GameOverview.jsx

100% Statements 5/5
100% Branches 6/6
100% Functions 2/2
100% Lines 5/5

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                          143x     143x 1x                 143x     143x                                                                        
import React from "react";
import { Row, Card, Col, Button } from "react-bootstrap";
import { useNavigate } from "react-router";
import { hasRole } from "main/utils/currentUser";
import { daysSinceTimestamp } from "main/utils/dateUtils";
import CurrentAnnouncements from "main/components/Announcement/CurrentAnnouncements";
 
export default function GameOverview({
  gamePlus,
  currentUser,
  currentAnnouncements,
  emulatingStudentView = false,
}) {
  let navigate = useNavigate();
 
  // Stryker disable all
  const dashboardButtonClick = () => {
    navigate("/dashboard/" + gamePlus.game.id);
  };
  // Stryker restore all
 
  // Admins always see the Dashboard button on their own play page,
  // regardless of the game's showLeaderboard setting - but when an admin is
  // emulating a student's read-only view, the button should only show up if
  // a real student would actually see it.
  const showDashboard =
    (!emulatingStudentView && hasRole(currentUser, "ROLE_ADMIN")) ||
    gamePlus.game.showLeaderboard;
 
  return (
    <Card data-testid="GameOverview">
      <Card.Header as="h5" className="woodenboardtable">
        Announcements
      </Card.Header>
      <Card.Body
        style={
          // Stryker disable next-line all: don't test CSS params
          { backgroundColor: "rgb(245, 210, 140)" }
        }
      >
        <CurrentAnnouncements announcements={currentAnnouncements} />
 
        <Row>
          <Col>
            <Card.Title>
              Today is day {daysSinceTimestamp(gamePlus.game.startingDate)}!
            </Card.Title>
            <Card.Text>Total Players: {gamePlus.totalUsers}</Card.Text>
          </Col>
          <Col>
            {showDashboard && (
              <Button
                variant="outline-success"
                data-testid="user-leaderboard-button"
                onClick={dashboardButtonClick}
              >
                Dashboard
              </Button>
            )}
          </Col>
        </Row>
      </Card.Body>
    </Card>
  );
}