All files / components/Game FarmStats.jsx

100% Statements 15/15
100% Branches 10/10
100% Functions 2/2
100% Lines 15/15

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                        3x 140x 1x   139x 2x   137x 3x   134x 2x   132x 2x   130x     3x 140x   140x                                                                                  
import React from "react";
import { Card, ProgressBar } from "react-bootstrap";
 
import happyCow from "../../../assets/happy_cow.png";
import neutralCow from "../../../assets/neutral_cow.png";
import confusedCow from "../../../assets/confused_cow.png";
import sadCow from "../../../assets/sad_cow.png";
import angryCow from "../../../assets/angry_cow.png";
import deadCow from "../../../assets/dead_cow.png";
 
import "./FarmStats.css";
 
const getCowSprite = (health) => {
  if (health <= 0) {
    return { image: deadCow, label: "Dead cow" };
  }
  if (health <= 20) {
    return { image: angryCow, label: "Angry cow" };
  }
  if (health <= 40) {
    return { image: sadCow, label: "Sad cow" };
  }
  if (health <= 60) {
    return { image: confusedCow, label: "Confused cow" };
  }
  if (health <= 80) {
    return { image: neutralCow, label: "Neutral cow" };
  }
  return { image: happyCow, label: "Happy cow" };
};
 
const FarmStats = ({ farmer }) => {
  const cowSprite = getCowSprite(farmer.cowHealth);
 
  return (
    <Card>
      <Card.Header as="h5" className="woodenboardtable">
        Your Farm Stats
      </Card.Header>
      <Card.Body
        style={
          // Stryker disable next-line all: don't test CSS params
          { backgroundColor: "rgb(245, 210, 140)" }
        }
      >
        {/* update total wealth and cow health with data from fixture */}
        <Card.Title className="text-center">
          💰 Total Wealth: ${farmer.totalWealth.toFixed(2)}
        </Card.Title>
        <Card.Text>Total Cows Bought: {farmer.cowsBought}</Card.Text>
        <Card.Text>Total Cows Sold: {farmer.cowsSold}</Card.Text>
        <Card.Title className="text-center">
          ❤️ Cow Health: {Math.round(farmer.cowHealth * 100) / 100}%
        </Card.Title>
        <ProgressBar
          now={farmer.cowHealth}
          min={0}
          max={100}
          variant="danger"
        />
        <div className="text-center my-3">
          <img
            src={cowSprite.image}
            alt={cowSprite.label}
            data-testid="cow-health-sprite"
            className="cow-health-sprite"
          />
        </div>
        <Card.Text>💀 Cow Deaths: {farmer.cowDeaths}</Card.Text>
      </Card.Body>
    </Card>
  );
};
 
export default FarmStats;