Skip to content

Commit

Permalink
Merge pull request #48 from ucsb-cs156-s23/JessicaH-DayNum
Browse files Browse the repository at this point in the history
JessicaH- Add day number on CommonsOverview
  • Loading branch information
pconrad authored Jun 6, 2023
2 parents 8c6b4ad + fca2ac4 commit 51a60da
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
6 changes: 3 additions & 3 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ body {
}

.card-text.bigger-text {
font-size: 60px;
font-size: 50px;
}

.icon.small {
width: 30px;
height: 30px;
width: 50px;
height: 50px;
}

5 changes: 5 additions & 0 deletions frontend/src/main/components/Commons/CommonsOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ 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 { calculateDays } from "main/utils/dateUtils";

export default function CommonsOverview({ commons, currentUser }) {

let navigate = useNavigate();
// Stryker disable next-line all
const leaderboardButtonClick = () => { navigate("/leaderboard/" + commons.id) };
const showLeaderboard = (hasRole(currentUser, "ROLE_ADMIN") || commons.showLeaderboard );

const today = new Date();
commons.day = calculateDays(commons.startingDate,today);

return (
<Card data-testid="CommonsOverview">
<Card.Header as="h5">Announcements</Card.Header>
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/main/utils/dateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ const timestampToDate = (timestamp) => {
return (date.getFullYear() + "-" + (padWithZero(date.getMonth()+1)) + "-" + padWithZero(date.getDate()));
}

export {timestampToDate, padWithZero};

const calculateDays = (startingDate,currentDate) => {
const start = new Date(startingDate);
const today = new Date(currentDate);
const timeDifference = today.getTime() - start.getTime();
const days = Math.floor(timeDifference / (1000 * 3600 * 24))+1;
return days;
}

export {timestampToDate, padWithZero, calculateDays};
16 changes: 15 additions & 1 deletion frontend/src/tests/components/Commons/CommonsOverview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,24 @@ describe("CommonsOverview tests", () => {
});

test("contains the correct content", async () => {

// arrange

jest.useFakeTimers().setSystemTime(new Date('2020-01-05'));

const commons = {
...commonsFixtures.oneCommons[0],
startingDate: new Date('2020-01-01'),
};

// act

render(
<CommonsOverview commons = {commonsFixtures.oneCommons[0]} />
<CommonsOverview commons = {commons} />
);

// assert

await waitFor (() => {
expect(screen.getByText(/Today is day 5!/)).toBeInTheDocument();
});
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/tests/utils/dateUtils.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { padWithZero, timestampToDate } from "main/utils/dateUtils";
import { padWithZero, timestampToDate, calculateDays} from "main/utils/dateUtils";


describe("dateUtils tests", () => {
Expand All @@ -25,4 +25,13 @@ describe("dateUtils tests", () => {
});
});

describe("calculateDays tests", () => {
test("with mock current date 2023-06-01T00:00:00", () => {
const startingDate = "2023-05-01T00:00:00";
const currentDate = "2023-06-01T00:00:00";
expect(calculateDays(startingDate,currentDate)).toBe(32);

});
});

});

0 comments on commit 51a60da

Please sign in to comment.