Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JacobW scale cow sale price #25

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/src/fixtures/commonsFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const commonsFixtures = {
"milkPrice": 10,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -24,6 +25,7 @@ const commonsFixtures = {
"milkPrice": 10,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": false,
"carryingCapacity": 123,
},
{
Expand All @@ -37,6 +39,7 @@ const commonsFixtures = {
"milkPrice": 10,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": false,
"carryingCapacity": 42,
}
],
Expand All @@ -53,6 +56,7 @@ const commonsFixtures = {
"milkPrice": 10,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 314,
}
],
Expand All @@ -66,6 +70,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -76,6 +81,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -86,6 +92,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -96,6 +103,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -106,6 +114,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -116,6 +125,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
{
Expand All @@ -126,6 +136,7 @@ const commonsFixtures = {
"cowPrice": 15,
"degradationRate": .5,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
}
],
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/fixtures/commonsPlusFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const commonsPlusFixtures = {
"endingDate": null,
"degradationRate": 0.01,
"showLeaderboard": false,
"scaleCowSalePrice": true,
"carryingCapacity": 100,
},
"totalCows": 10,
Expand All @@ -28,6 +29,7 @@ const commonsPlusFixtures = {
"endingDate": null,
"degradationRate": 0.01,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 42,
},
"totalCows": 0,
Expand All @@ -45,6 +47,7 @@ const commonsPlusFixtures = {
"endingDate": null,
"degradationRate": 5.0,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"carryingCapacity": 123,
},
"totalCows": 0,
Expand All @@ -65,6 +68,7 @@ const commonsPlusFixtures = {
"endingDate": null,
"degradationRate": 3.0,
"showLeaderboard": false,
"scaleCowSalePrice": true,
"carryingCapacity": 23,
},
"totalCows": 0,
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/fixtures/userCommonsFixtures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
const userCommonsFixtures = {
// Backend does not include "commons" or "user", so they probably shouldn't be in these fixtures
oneRealUserCommons: {
"id": 1,
"userId": 1,
"commonsId": 1,
"username": "idk if this field is even used",
"totalWealth": 1000,
"numOfCows": 5,
"cowHealth": 98.0
},
oneUserCommons:
[
{
Expand All @@ -16,6 +26,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -40,6 +51,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -61,6 +73,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -82,6 +95,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 100000,
Expand All @@ -106,6 +120,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -127,6 +142,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -148,6 +164,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 100000,
Expand All @@ -169,6 +186,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 50,
Expand All @@ -190,6 +208,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 800,
Expand All @@ -214,6 +233,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -235,6 +255,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -256,6 +277,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 100000,
Expand All @@ -277,6 +299,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 50,
Expand All @@ -298,6 +321,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 800,
Expand All @@ -319,6 +343,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -340,6 +365,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 1000,
Expand All @@ -361,6 +387,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 100000,
Expand All @@ -382,6 +409,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 50,
Expand All @@ -403,6 +431,7 @@ const userCommonsFixtures = {
"totalPlayers": 50,
"cowPrice": 15,
"showLeaderboard": true,
"scaleCowSalePrice": true,
"degradationRate": .5,
},
"totalWealth" : 800,
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/main/components/Commons/CommonsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ function CommonsForm({ initialCommons, submitAction, buttonLabel = "Create" }) {
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3">
<Form.Label htmlFor="scaleCowSalePrice"> Cow Sale Price Decreases with Health?</Form.Label>
<Form.Check
data-testid={`${testid}-scaleCowSalePrice`}
type="checkbox"
id="scaleCowSalePrice"
{...register("scaleCowSalePrice")}
/>
</Form.Group>

<Form.Group className="mb-3">
<Form.Label htmlFor="showLeaderboard">Show Leaderboard?</Form.Label>
<Form.Check
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/main/components/Commons/CommonsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export default function CommonsTable({ commons, currentUser }) {
accessor: row => row.commons.degradationRate,
id: 'commons.degradationRate'
},
{
Header:'Cow Sale Price Decreases with Health?',
id: 'commons.scaleCowSalePrice', // needed for tests
accessor: (row, _rowIndex) => String(row.commons.scaleCowSalePrice) // hack needed for boolean values to show up
},
{
Header:'Show Leaderboard?',
id: 'commons.showLeaderboard', // needed for tests
Expand All @@ -86,16 +91,12 @@ export default function CommonsTable({ commons, currentUser }) {

const columnsIfAdmin = [
...columns,
ButtonColumn("Edit",
"primary", editCallback, testid),
ButtonColumn("Delete",
"danger", deleteCallback, testid),
ButtonColumn("Leaderboard",
"secondary", leaderboardCallback, testid)
ButtonColumn("Edit", "primary", editCallback, testid),
ButtonColumn("Delete", "danger", deleteCallback, testid),
ButtonColumn("Leaderboard", "secondary", leaderboardCallback, testid)
];

const columnsToDisplay = hasRole(currentUser,
"ROLE_ADMIN") ? columnsIfAdmin : columns;
const columnsToDisplay = hasRole(currentUser, "ROLE_ADMIN") ? columnsIfAdmin : columns;

return <OurTable
data={commons}
Expand Down
28 changes: 23 additions & 5 deletions frontend/src/main/components/Commons/ManageCows.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import React from "react";
import { Card, Button, Row, Col } from "react-bootstrap";
import cowHead from "./../../../assets/CowHead.png";

// add parameters
const ManageCows = ({userCommons,commons, onBuy, onSell}) => {

// add parameters
const ManageCows = ({userCommons, commons, onBuy, onSell}) => {
// update cowPrice from fixture
// Stryker disable ArithmeticOperator : line 24: not very important and unsure of how to test this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? This keeps showing up in this team's PRs, and I'm skeptical. I need to be convinced that this is necessary, especially since "line 24" seems to be misleading.

return (
<Card>
<Card.Header as="h5">Manage Cows</Card.Header>
<Card.Body>
{/* change $10 to info from fixture */}
{/* why does removing the optional chaining question mark turn the entire page white? */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this comment keep showing up?

I've called it out in several code reviews. Comments like this are fine while you are developing, but they need to be removed before code is ready to merge to main.

And I've answered this question before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because it is outdated. I was waiting for BuySellMultipleCows to be approved before merging all the changes into other branches.

<Card.Title>Market Cow Price: ${commons?.cowPrice}</Card.Title>
<Card.Title>Number of Cows: {userCommons.numOfCows}</Card.Title>
<Row>
Expand All @@ -19,16 +21,32 @@ const ManageCows = ({userCommons,commons, onBuy, onSell}) => {
</Card.Text>
</Col>
<Col>
<Button variant="outline-danger" onClick={()=>{onBuy(userCommons)}} data-testid={"buy-cow-button"}>Buy cow</Button>
<Button variant="outline-danger" onClick={()=>{onBuy(userCommons, parseInt(userCommons.totalWealth/commons.cowPrice))}} data-testid={"buy-max-cows-button"}>Buy Max Cows</Button>
<br/>
<br/>
<Button variant="outline-danger" onClick={()=>{onBuy(userCommons, 10)}} data-testid={"buy-10-cows-button"}>Buy 10 Cows</Button>
<br/>
<br/>
<Button variant="outline-danger" onClick={()=>{onBuy(userCommons, 1)}} data-testid={"buy-a-cow-button"}>Buy a Cow</Button>
<br/>
<br/>
<Button variant="outline-danger" onClick={()=>{onSell(userCommons, 1)}} data-testid={"sell-a-cow-button"}>Sell a Cow</Button>
<br/>
<br/>
<Button variant="outline-danger" onClick={()=>{onSell(userCommons, 10)}} data-testid={"sell-10-cows-button"}>Sell 10 Cows</Button>
<br/>
<br/>
<Button variant="outline-danger" onClick={()=>{onSell(userCommons)}} data-testid={"sell-cow-button"}>Sell cow</Button>
<Button variant="outline-danger" onClick={()=>{onSell(userCommons, userCommons.numOfCows)}} data-testid={"sell-all-cows-button"}>Sell All Cows</Button>
<br/>
<br/>
</Col>
</Row>
{!!commons?.scaleCowSalePrice &&
<Card.Text>
Note: Buying cows buys at current cow price, but selling cows sells at current cow price
times the average health of cows as a percentage!
</Card.Text>
}
</Card.Body>
</Card>
);
Expand Down
Loading