All files / components/Commons CommonsOverview.js

100% Statements 8/8
100% Branches 8/8
100% Functions 3/3
100% Lines 6/6

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                  138x   138x 138x 138x 138x 138x                                                                  
import React from "react";
import { Row, Card, Col, Button } from "react-bootstrap";
import { useNavigate } from "react-router-dom";
import { hasRole } from "main/utils/currentUser";
import { daysSinceTimestamp } from "main/utils/dateUtils";
import PagedAnnouncementTable from "main/components/Commons/PagedAnnouncementTable";
 
export default function CommonsOverview({ commonsPlus, currentUser }) {
 
    let navigate = useNavigate();
    // Stryker disable next-line all
    const [isTableVisible, setIsTableVisible] = React.useState(true);
    const changeTableVisibility = () => { setIsTableVisible(!isTableVisible); };
    const leaderboardButtonClick = () => { navigate("/leaderboard/" + commonsPlus.commons.id) };
    const showLeaderboard = (hasRole(currentUser, "ROLE_ADMIN") || commonsPlus.commons.showLeaderboard );
    return (
        <Card data-testid="CommonsOverview">
            <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)"}}>
                <Row>
                    <Col>
                        <Card.Title>Today is Day {daysSinceTimestamp(commonsPlus.commons.startingDate)}!</Card.Title>
                        <Card.Text>Total Players: {commonsPlus.totalUsers}</Card.Text>
                    </Col>
                    <Col>
                        {showLeaderboard &&
                        (<Button variant="outline-success" data-testid="user-leaderboard-button" onClick={leaderboardButtonClick}>
                            Leaderboard
                        </Button>)}
                    </Col>
                    <Col>
                        <Button variant="outline-primary" onClick={changeTableVisibility} className="mt-3">
                            {isTableVisible ? "Hide Announcements" : "Show Announcements"}
                        </Button>
                    </Col>
                </Row>
                {isTableVisible && (
                    <Row className="mt-3">
                        <Col>
                            <PagedAnnouncementTable />
                        </Col>
                    </Row>
                )}
            </Card.Body>
        </Card>
    );
};