From 8881c344d160dcd502e442f4baf492193b133d30 Mon Sep 17 00:00:00 2001 From: Alisha Pham Date: Wed, 31 May 2023 23:07:41 -0400 Subject: [PATCH 01/10] Overview Section --- .../pages/AdminDashboard/AdminDashboard.tsx | 121 +++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index 720ae3ad8..11fdf6110 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -2,12 +2,131 @@ import React from "react"; import Typography from "@material-ui/core/Typography"; import Header from "components/general/Header/Header"; import { hackathonName } from "constants.js"; +import Box from "@material-ui/core/Box"; +import Grid from "@material-ui/core/Grid"; +import Paper from "@material-ui/core/Paper"; +import { styled } from "@material-ui/core/styles"; +import MemoryIcon from "@material-ui/icons/Memory"; +import PeopleIcon from "@material-ui/icons/People"; +import AccountBoxIcon from "@material-ui/icons/AccountBox"; +import LocalMallIcon from "@material-ui/icons/LocalMall"; +import BrokenImageIcon from "@material-ui/icons/BrokenImage"; + +const Item = styled(Paper)(({ theme }) => ({ + backgroundColor: "#fff", + ...theme.typography.body2, + padding: theme.spacing(1), + textAlign: "center", + color: theme.palette.text.secondary, +})); const AdminDashboard = () => { return ( <>
- {hackathonName} Admin Dashboard +
+ + {hackathonName} Admin Dashboard + + + {" "} + Overview{" "} + + + + + + + {" "} + + 123 item's checked out + + + + + + + + {" "} + + 200 participants + + + + + + + + {" "} + + 14 teams + + + + + + + + {" "} + + 123 orders + + + + + + + + {" "} + + 7 broken/lost items + + + + + + +
); }; From b1592ec3bbe3ff54b3969694f7d1b723bc39d291 Mon Sep 17 00:00:00 2001 From: Alisha Pham Date: Sun, 18 Jun 2023 19:50:46 -0400 Subject: [PATCH 02/10] Revert "Overview Section" This reverts commit 8881c344d160dcd502e442f4baf492193b133d30. --- .../pages/AdminDashboard/AdminDashboard.tsx | 121 +----------------- 1 file changed, 1 insertion(+), 120 deletions(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index 11fdf6110..720ae3ad8 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -2,131 +2,12 @@ import React from "react"; import Typography from "@material-ui/core/Typography"; import Header from "components/general/Header/Header"; import { hackathonName } from "constants.js"; -import Box from "@material-ui/core/Box"; -import Grid from "@material-ui/core/Grid"; -import Paper from "@material-ui/core/Paper"; -import { styled } from "@material-ui/core/styles"; -import MemoryIcon from "@material-ui/icons/Memory"; -import PeopleIcon from "@material-ui/icons/People"; -import AccountBoxIcon from "@material-ui/icons/AccountBox"; -import LocalMallIcon from "@material-ui/icons/LocalMall"; -import BrokenImageIcon from "@material-ui/icons/BrokenImage"; - -const Item = styled(Paper)(({ theme }) => ({ - backgroundColor: "#fff", - ...theme.typography.body2, - padding: theme.spacing(1), - textAlign: "center", - color: theme.palette.text.secondary, -})); const AdminDashboard = () => { return ( <>
-
- - {hackathonName} Admin Dashboard - - - {" "} - Overview{" "} - - - - - - - {" "} - - 123 item's checked out - - - - - - - - {" "} - - 200 participants - - - - - - - - {" "} - - 14 teams - - - - - - - - {" "} - - 123 orders - - - - - - - - {" "} - - 7 broken/lost items - - - - - - -
+ {hackathonName} Admin Dashboard ); }; From 666689bc6f527628a648c7a1d2f8fdedcc594abd Mon Sep 17 00:00:00 2001 From: Alisha Pham Date: Sun, 18 Jun 2023 19:54:01 -0400 Subject: [PATCH 03/10] added overview section --- .../pages/AdminDashboard/AdminDashboard.tsx | 121 +++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index 720ae3ad8..e93654650 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -2,12 +2,131 @@ import React from "react"; import Typography from "@material-ui/core/Typography"; import Header from "components/general/Header/Header"; import { hackathonName } from "constants.js"; +import Box from "@material-ui/core/Box"; +import Grid from "@material-ui/core/Grid"; +import Paper from "@material-ui/core/Paper"; +import { styled } from "@material-ui/core/styles"; +import MemoryIcon from "@material-ui/icons/Memory"; +import PeopleIcon from "@material-ui/icons/People"; +import AccountBoxIcon from "@material-ui/icons/AccountBox"; +import LocalMallIcon from "@material-ui/icons/LocalMall"; +import BrokenImageIcon from "@material-ui/icons/BrokenImage"; + +const Item = styled(Paper)(({ theme }) => ({ + backgroundColor: "#fff", + ...theme.typography.body2, + padding: theme.spacing(1), + textAlign: "center", + color: theme.palette.text.secondary, +})); const AdminDashboard = () => { return ( <>
- {hackathonName} Admin Dashboard +
+ + {hackathonName} Admin Dashboard + + + {" "} + Overview{" "} + + + + + + + {" "} + + 122 item's checked out + + + + + + + + {" "} + + 200 participants + + + + + + + + {" "} + + 14 teams + + + + + + + + {" "} + + 123 orders + + + + + + + + {" "} + + 7 broken/lost items + + + + + + +
); }; From 6f3398ee0f47abf100c5b3723df47b041df2ce6c Mon Sep 17 00:00:00 2001 From: Alisha Pham Date: Tue, 8 Aug 2023 15:10:58 -0400 Subject: [PATCH 04/10] overview will show real data --- .../pages/AdminDashboard/AdminDashboard.tsx | 35 ++++++++++++++++--- .../src/slices/event/teamAdminSlice.ts | 11 ++++++ .../src/slices/order/adminOrderSlice.ts | 30 ++++++++++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index e93654650..513b0b88f 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import Typography from "@material-ui/core/Typography"; import Header from "components/general/Header/Header"; import { hackathonName } from "constants.js"; @@ -11,6 +11,18 @@ import PeopleIcon from "@material-ui/icons/People"; import AccountBoxIcon from "@material-ui/icons/AccountBox"; import LocalMallIcon from "@material-ui/icons/LocalMall"; import BrokenImageIcon from "@material-ui/icons/BrokenImage"; +import { useDispatch, useSelector } from "react-redux"; +import { + teamCountSelector, + getTeamsWithSearchThunk, + totalParticipantCountSelector, +} from "slices/event/teamAdminSlice"; +import { clearFilters } from "slices/hardware/hardwareSlice"; +import { + adminOrderNewTotalSelector, + getOrdersWithFilters, + adminCheckedOutOrderTotalSelector, +} from "slices/order/adminOrderSlice"; const Item = styled(Paper)(({ theme }) => ({ backgroundColor: "#fff", @@ -21,6 +33,19 @@ const Item = styled(Paper)(({ theme }) => ({ })); const AdminDashboard = () => { + const dispatch = useDispatch(); + const orderQuantity = useSelector(adminOrderNewTotalSelector); + const count = useSelector(teamCountSelector); + const participants = useSelector(totalParticipantCountSelector); + const checkedOut = useSelector(adminCheckedOutOrderTotalSelector); + + // TODO: Create selector for Broken/Lost Items + + useEffect(() => { + dispatch(clearFilters()); + dispatch(getOrdersWithFilters()); + dispatch(getTeamsWithSearchThunk()); + }, [dispatch]); return ( <>
@@ -47,7 +72,7 @@ const AdminDashboard = () => { color: "black", }} > - 122 item's checked out + {checkedOut} item's checked out @@ -65,7 +90,7 @@ const AdminDashboard = () => { color: "black", }} > - 200 participants + {participants} participants @@ -83,7 +108,7 @@ const AdminDashboard = () => { color: "black", }} > - 14 teams + {count} teams @@ -101,7 +126,7 @@ const AdminDashboard = () => { color: "black", }} > - 123 orders + {orderQuantity} orders diff --git a/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.ts b/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.ts index 05fb3a18b..eac72e19e 100644 --- a/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.ts +++ b/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.ts @@ -171,3 +171,14 @@ export const teamCountSelector = createSelector( [teamAdminSliceSelector], (teamAdminSlice) => teamAdminSlice.count ); + +export const totalParticipantCountSelector = createSelector( + [teamAdminSelectors.selectAll], + (teamsList) => { + let count = 0; + for (let i = 0; i < teamsList.length; i++) { + count += teamsList[i].profiles.length; + } + return count; + } +); diff --git a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts index 82fab7a4c..5c6f35bbd 100644 --- a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts +++ b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts @@ -205,4 +205,34 @@ export const adminOrderTotalSelector = createSelector( (orderItems) => orderItems.reduce((accum) => accum + 1, 0) ); +export const adminOrderNewTotalSelector = createSelector( + [adminOrderSliceSelector], + (adminOrderSlice) => { + const { numStatuses } = adminOrderSlice; + const total = Object.values(numStatuses).reduce( + (acc, value) => acc + (value || 0), + 0 + ); + return total; + } +); + +// export const adminCheckedOutOrderTotalSelector = createSelector( +// [adminOrderSliceSelector], +// (adminOrderSlice) => adminOrderSlice.numStatuses["Picked Up"] +// ); + +export const adminCheckedOutOrderTotalSelector = createSelector( + [adminOrderSelectors.selectAll], + (ordersList) => { + let count = 0; + for (let i = 0; i < ordersList.length; i++) { + if (ordersList[i].status == "Picked Up") { + count += ordersList[i].items.length; + } + } + return count; + } +); + export const { setFilters, clearFilters } = actions; From 3294f38b5affefd6e0443974afbd94b4110a4131 Mon Sep 17 00:00:00 2001 From: Daniel Qiu Date: Tue, 29 Aug 2023 18:10:48 -0400 Subject: [PATCH 05/10] add pendingFilter to dependency array on useEffect --- .../frontend/src/pages/AdminDashboard/AdminDashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index 2b7b5434a..58d9296df 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -60,7 +60,7 @@ const AdminDashboard = () => { dispatch(clearFilters()); dispatch(getOrdersWithFilters()); dispatch(getTeamsWithSearchThunk()); - }, [dispatch]); + }, [dispatch, pendingFilter]); return ( <>
From ff336d01153c1551ffb1e54ce952904e1f69c928 Mon Sep 17 00:00:00 2001 From: Daniel Qiu Date: Tue, 29 Aug 2023 18:16:32 -0400 Subject: [PATCH 06/10] move pending orders into useEffect --- .../src/pages/AdminDashboard/AdminDashboard.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index 58d9296df..dd9327a72 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -47,20 +47,21 @@ const AdminDashboard = () => { const count = useSelector(teamCountSelector); const participants = useSelector(totalParticipantCountSelector); const checkedOut = useSelector(adminCheckedOutOrderTotalSelector); - const pendingFilter: OrderFilters = { - status: ["Submitted", "Ready for Pickup"], - }; + const numOrdersOnPage = 6; const ordersLength = allOrders.length <= numOrdersOnPage ? allOrders.length : numOrdersOnPage; - // TODO: Create selector for Broken/Lost Items + // TODO: Create selector for Broken/Lost Item useEffect(() => { + const pendingFilter: OrderFilters = { + status: ["Submitted", "Ready for Pickup"], + }; dispatch(setFilters(pendingFilter)); dispatch(clearFilters()); dispatch(getOrdersWithFilters()); dispatch(getTeamsWithSearchThunk()); - }, [dispatch, pendingFilter]); + }, [dispatch]); return ( <>
From a258e7d4ddda1f4d04419d7b84c8ffb2b5c7f467 Mon Sep 17 00:00:00 2001 From: Daniel Qiu Date: Tue, 29 Aug 2023 18:24:25 -0400 Subject: [PATCH 07/10] resolve Expected '===' and instead saw '==' eqeqeq --- .../dashboard/frontend/src/slices/order/adminOrderSlice.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts index 5c6f35bbd..20cd65ac8 100644 --- a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts +++ b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts @@ -227,7 +227,7 @@ export const adminCheckedOutOrderTotalSelector = createSelector( (ordersList) => { let count = 0; for (let i = 0; i < ordersList.length; i++) { - if (ordersList[i].status == "Picked Up") { + if (ordersList[i].status === "Picked Up") { count += ordersList[i].items.length; } } From c6e14f670385fe376eecc816eac7c560d269d528 Mon Sep 17 00:00:00 2001 From: Daniel Qiu Date: Fri, 1 Sep 2023 15:11:33 -0400 Subject: [PATCH 08/10] migrate inline styling to scss --- .../AdminDashboard/AdminDashboard.module.scss | 14 ++++++- .../pages/AdminDashboard/AdminDashboard.tsx | 40 ++++--------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.module.scss b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.module.scss index c6c02965f..7ce80a85c 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.module.scss +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.module.scss @@ -6,8 +6,9 @@ } .title { + margin-top: 20px; text-justify: left; - margin-bottom: 10px; + margin-bottom: 5px; font-family: "Roboto"; font-style: normal; font-weight: 500; @@ -22,3 +23,14 @@ .section { margin-bottom: 1rem; } + +.overviewTitle { + padding-bottom: 10px; +} + +.itemContent { + padding-left: 7px; + padding-bottom: 10px; + padding-top: 10px; + color: black; +} diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index dd9327a72..173ee883f 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -47,7 +47,6 @@ const AdminDashboard = () => { const count = useSelector(teamCountSelector); const participants = useSelector(totalParticipantCountSelector); const checkedOut = useSelector(adminCheckedOutOrderTotalSelector); - const numOrdersOnPage = 6; const ordersLength = allOrders.length <= numOrdersOnPage ? allOrders.length : numOrdersOnPage; @@ -67,8 +66,8 @@ const AdminDashboard = () => {
{hackathonName} Admin Dashboard -
- +
+ {" "} Overview{" "} @@ -80,12 +79,7 @@ const AdminDashboard = () => { {" "} {checkedOut} item's checked out @@ -98,12 +92,7 @@ const AdminDashboard = () => { {" "} {participants} participants @@ -116,12 +105,7 @@ const AdminDashboard = () => { {" "} {count} teams @@ -134,12 +118,7 @@ const AdminDashboard = () => { {" "} {orderQuantity} orders @@ -152,12 +131,7 @@ const AdminDashboard = () => { {" "} 7 broken/lost items From e32374c1f8cb669d41c5426ab9977e170508559d Mon Sep 17 00:00:00 2001 From: Daniel Qiu Date: Fri, 1 Sep 2023 15:18:55 -0400 Subject: [PATCH 09/10] remove commentted code and ran prettier --- .../dashboard/frontend/src/slices/order/adminOrderSlice.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts index 20cd65ac8..71dd6d5c7 100644 --- a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts +++ b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts @@ -217,11 +217,6 @@ export const adminOrderNewTotalSelector = createSelector( } ); -// export const adminCheckedOutOrderTotalSelector = createSelector( -// [adminOrderSliceSelector], -// (adminOrderSlice) => adminOrderSlice.numStatuses["Picked Up"] -// ); - export const adminCheckedOutOrderTotalSelector = createSelector( [adminOrderSelectors.selectAll], (ordersList) => { From 092c7990d83deb21de0fc3734a72aa6f8cd646a1 Mon Sep 17 00:00:00 2001 From: Daniel Qiu Date: Sun, 24 Sep 2023 16:03:16 -0400 Subject: [PATCH 10/10] Add tests for selectors, TODO adminOrderTotalSelector, ensure it is not impacted by filters --- .../orders/OrdersCount/OrdersCount.tsx | 4 +-- .../pages/AdminDashboard/AdminDashboard.tsx | 4 +-- .../src/slices/event/teamAdminSlice.test.ts | 18 ++++++++++++- .../src/slices/order/adminOrderSlice.test.ts | 27 ++++++++++++++++--- .../src/slices/order/adminOrderSlice.ts | 16 +++-------- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/hackathon_site/dashboard/frontend/src/components/orders/OrdersCount/OrdersCount.tsx b/hackathon_site/dashboard/frontend/src/components/orders/OrdersCount/OrdersCount.tsx index 8e9ef5ffd..d84bca565 100644 --- a/hackathon_site/dashboard/frontend/src/components/orders/OrdersCount/OrdersCount.tsx +++ b/hackathon_site/dashboard/frontend/src/components/orders/OrdersCount/OrdersCount.tsx @@ -4,7 +4,7 @@ import RefreshIcon from "@material-ui/icons/Refresh"; import { useDispatch, useSelector } from "react-redux"; import styles from "pages/Orders/Orders.module.scss"; import { - adminOrderTotalSelector, + adminOrderTotalWithFiltersSelector, getOrdersWithFilters, } from "slices/order/adminOrderSlice"; @@ -13,7 +13,7 @@ const OrdersCount = () => { const refreshOrders = () => { dispatch(getOrdersWithFilters()); }; - const orderQuantity = useSelector(adminOrderTotalSelector); + const orderQuantity = useSelector(adminOrderTotalWithFiltersSelector); return (
{orderQuantity} results diff --git a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx index 173ee883f..3191a6785 100644 --- a/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx +++ b/hackathon_site/dashboard/frontend/src/pages/AdminDashboard/AdminDashboard.tsx @@ -27,7 +27,7 @@ import { adminOrderSelectors, getOrdersWithFilters, setFilters, - adminOrderNewTotalSelector, + adminOrderTotalSelector, adminCheckedOutOrderTotalSelector, } from "slices/order/adminOrderSlice"; @@ -43,7 +43,7 @@ const AdminDashboard = () => { const dispatch = useDispatch(); const history = useHistory(); const allOrders = useSelector(adminOrderSelectors.selectAll); - const orderQuantity = useSelector(adminOrderNewTotalSelector); + const orderQuantity = useSelector(adminOrderTotalSelector); const count = useSelector(teamCountSelector); const participants = useSelector(totalParticipantCountSelector); const checkedOut = useSelector(adminCheckedOutOrderTotalSelector); diff --git a/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.test.ts b/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.test.ts index 57f34e32b..e2531ae35 100644 --- a/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.test.ts +++ b/hackathon_site/dashboard/frontend/src/slices/event/teamAdminSlice.test.ts @@ -8,14 +8,17 @@ import { teamAdminSelectors, NUM_TEAM_LIMIT, getTeamNextPage, + teamCountSelector, + totalParticipantCountSelector, } from "slices/event/teamAdminSlice"; import { makeMockApiListResponse, makeStoreWithEntities, waitFor } from "testing/utils"; -import { mockTeam, mockTeams } from "testing/mockData"; +import { mockTeam, mockTeamMultiple, mockTeams, mockValidTeam } from "testing/mockData"; import { get, stripHostnameReturnFilters } from "api/api"; import { displaySnackbar } from "slices/ui/uiSlice"; import thunk, { ThunkDispatch } from "redux-thunk"; import { AnyAction } from "redux"; import configureStore from "redux-mock-store"; +import { teamReducerName, teamSizeSelector } from "./teamSlice"; jest.mock("api/api", () => ({ ...jest.requireActual("api/api"), @@ -57,6 +60,18 @@ describe("Selectors", () => { expect(isLoadingSelector(loadingTrueState)).toEqual(true); expect(isLoadingSelector(loadingFalseState)).toEqual(false); }); + test("totalParticipantCountSelector", () => { + const store = makeStoreWithEntities({ teams: mockTeams }); + const totalTeams = totalParticipantCountSelector(store.getState()); + const totalProfiles = mockTeams.reduce((sum, team) => { + if (team.profiles) { + return sum + team.profiles.length; + } else { + return sum; + } + }, 0); + expect(totalTeams).toEqual(totalProfiles); + }); }); describe("getTeamsWithSearch thunk", () => { @@ -92,6 +107,7 @@ describe("getTeamsWithSearch thunk", () => { limit: NUM_TEAM_LIMIT, }); expect(teamAdminSelectors.selectAll(store.getState())).toEqual(mockTeams); + expect(teamCountSelector(store.getState())).toEqual(mockTeams.length); }); }); diff --git a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.test.ts b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.test.ts index f446ac187..c9f78373b 100644 --- a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.test.ts +++ b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.test.ts @@ -8,11 +8,13 @@ import { errorSelector, getOrdersWithFilters, adminOrderSelectors, + adminOrderTotalWithFiltersSelector, adminOrderTotalSelector, + adminCheckedOutOrderTotalSelector, } from "slices/order/adminOrderSlice"; import { get } from "api/api"; import { makeMockApiListResponse, makeStoreWithEntities } from "testing/utils"; -import { mockPendingOrders } from "testing/mockData"; +import { mockCheckedOutOrders, mockOrders, mockPendingOrders } from "testing/mockData"; import { waitFor } from "@testing-library/react"; jest.mock("api/api", () => ({ @@ -52,11 +54,30 @@ describe("adminOrderSlice Selectors", () => { expect(errorSelector(errorExistsState)).toEqual("exists"); expect(errorSelector(errorNullState)).toEqual(null); }); - test("adminOrderTotalSelector", () => { + test("adminOrderTotalWithFiltersSelector", () => { const store = makeStoreWithEntities({ allOrders: mockPendingOrders }); - const total = adminOrderTotalSelector(store.getState()); + const total = adminOrderTotalWithFiltersSelector(store.getState()); expect(total).toEqual(mockPendingOrders.length); }); + // todo not working, doesnt select all orders + test("adminOrderTotalSelector", () => { + const store = makeStoreWithEntities({ allOrders: mockOrders }); + const total = adminOrderTotalSelector(store.getState()); + expect(total).toEqual(mockOrders.length); + }); + test("adminCheckedOutOrderTotalSelector", () => { + const store = makeStoreWithEntities({ allOrders: mockCheckedOutOrders }); + const total = adminCheckedOutOrderTotalSelector(store.getState()); + const totalRequestedQuantity = mockCheckedOutOrders.reduce((sum, order) => { + return ( + sum + + order.request.reduce((orderSum, item) => { + return orderSum + item.requested_quantity; + }, 0) + ); + }, 0); + expect(total).toEqual(totalRequestedQuantity); // total number of orders in mockCheckedOutOrders + }); }); describe("getOrdersWithFilters Thunk", () => { it("Updates the store on API success", async () => { diff --git a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts index 71dd6d5c7..04a254884 100644 --- a/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts +++ b/hackathon_site/dashboard/frontend/src/slices/order/adminOrderSlice.ts @@ -200,22 +200,12 @@ export const adminOrderNumStatusesSelector = createSelector( (adminOrderSlice) => adminOrderSlice.numStatuses ); -export const adminOrderTotalSelector = createSelector( +export const adminOrderTotalWithFiltersSelector = createSelector( [adminOrderSelectors.selectAll], (orderItems) => orderItems.reduce((accum) => accum + 1, 0) ); - -export const adminOrderNewTotalSelector = createSelector( - [adminOrderSliceSelector], - (adminOrderSlice) => { - const { numStatuses } = adminOrderSlice; - const total = Object.values(numStatuses).reduce( - (acc, value) => acc + (value || 0), - 0 - ); - return total; - } -); +//Todo this selector is being affected by filters +export const adminOrderTotalSelector = createSelector(); export const adminCheckedOutOrderTotalSelector = createSelector( [adminOrderSelectors.selectAll],