All files / pages AdminViewPlayPage.jsx

100% Statements 18/18
100% Branches 13/13
100% Functions 3/3
100% Lines 17/17

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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                          1x 30x   30x     30x                       30x                   30x                     30x                       30x   30x 4x     30x                     30x             30x           30x 30x   30x     30x                                                                                                      
import React, { useState } from "react";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useParams } from "react-router";
import { Card, Container, CardGroup, Button } from "react-bootstrap";
import GameOverview from "main/components/Game/GameOverview";
import GamePlay from "main/components/Game/GamePlay";
import FarmStats from "main/components/Game/FarmStats";
import ManageCows from "main/components/Game/ManageCows";
import Profits from "main/components/Game/Profits";
import { useBackend } from "main/utils/useBackend";
import { useCurrentUser } from "main/utils/currentUser";
import ChatPanel from "main/components/Chat/ChatPanel";
 
const AdminViewPlayPage = () => {
  const { userId, gameId } = useParams();
 
  const { data: currentUser } = useCurrentUser();
 
  // Stryker disable all
  const { data: farmer } = useBackend("/api/farmer", {
    method: "GET",
    url: "/api/farmer",
    params: {
      userId: userId,
      gameId: gameId,
    },
  });
 
  // Stryker restore all
 
  // Stryker disable all
  const { data: gamePlus } = useBackend([`/api/game/plus?id=${gameId}`], {
    method: "GET",
    url: "/api/game/plus",
    params: {
      id: gameId,
    },
  });
  // Stryker restore all
 
  // Stryker disable all
  const { data: farmerProfits } = useBackend([`/api/profits/all`], {
    method: "GET",
    url: "/api/profits/all",
    params: {
      userId: userId,
      gameId: gameId,
    },
  });
  // Stryker restore all
 
  // Stryker disable all
  const { data: currentAnnouncements } = useBackend(
    [`/api/announcements/current?gameId=${gameId}`],
    {
      method: "GET",
      url: "/api/announcements/current",
      params: {
        gameId: gameId,
      },
    },
  );
  // Stryker restore all
 
  const [isChatOpen, setIsChatOpen] = useState(false);
 
  const toggleChatWindow = () => {
    setIsChatOpen((prevState) => !prevState);
  };
 
  const chatButtonStyle = {
    width: "40px",
    height: "40px",
    borderRadius: "50%",
    backgroundColor: "lightblue",
    color: "black",
    position: "fixed",
    bottom: "20px",
    right: "20px",
  };
 
  const chatContainerStyle = {
    width: "550px",
    position: "fixed",
    bottom: "100px",
    right: "20px",
  };
 
  const bannerStyle = {
    background: "#f0f0f0",
    padding: "10px",
    textAlign: "center",
  };
 
  const visiting_user = farmer?.username;
  const visiting_game = gamePlus?.game.name;
  // Stryker disable all
  const admin_name = currentUser?.root ? currentUser?.root?.user?.fullName : "";
  // Stryker restore all
 
  return (
    <div>
      <BasicLayout>
        <Card
          style={bannerStyle}
          data-testid="adminviewplaypage-read-only-banner"
        >
          <Card.Body>
            <Card.Title>
              This is a Admin Feature for <strong>{admin_name}</strong>
              <br />
              Visiting Farmer <strong>{visiting_user}</strong>'s Play Page for
              game <strong>{visiting_game}</strong> in Read Only Mode.
            </Card.Title>
          </Card.Body>
        </Card>
        <Container>
          {!!currentUser && <GamePlay currentUser={currentUser} />}
          {!!gamePlus && (
            <GameOverview
              gamePlus={gamePlus}
              currentUser={currentUser}
              currentAnnouncements={currentAnnouncements}
              emulatingStudentView={true}
            />
          )}
          <br />
          {!!farmer && !!gamePlus && (
            <CardGroup data-testid="adminviewplaypage-card-group">
              <ManageCows farmer={farmer} game={gamePlus.game} />
              <FarmStats farmer={farmer} />
              <Profits farmer={farmer} profits={farmerProfits} />
            </CardGroup>
          )}
        </Container>
      </BasicLayout>
      <div style={chatContainerStyle} data-testid="adminviewplaypage-chat-div">
        {!!isChatOpen && <ChatPanel gameId={gameId} />}
        <Button
          style={chatButtonStyle}
          onClick={toggleChatWindow}
          data-testid="adminviewplaypage-chat-toggle"
        >
          {isChatOpen ? "▼" : "▲"}
        </Button>
      </div>
    </div>
  );
};
 
export default AdminViewPlayPage;