From 66706b9c3ca8902c220a514bb4294b3a1a8ee34a Mon Sep 17 00:00:00 2001 From: pauladamseniii Date: Fri, 13 Oct 2023 17:18:36 -0400 Subject: [PATCH 1/8] CEC-3796 - UI for creating and managing RxSWIN --- .../App/__snapshots__/App.test.js.snap | 6 +- src/components/Contexts/CarUpdatesContext.jsx | 20 ++++ .../Contexts/__mocks__/CarUpdatesContext.jsx | 14 +++ .../Controls/CarUpdatesTable/index.jsx | 4 +- src/components/Manifest/List/index.jsx | 6 +- src/components/Routes/SiteRoutes.jsx | 10 ++ src/components/SUMS/index.jsx | 102 ++++++++++++++++++ src/services/updatesAPI.js | 12 +++ 8 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 src/components/SUMS/index.jsx diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index ebdfb75..68feacd 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -6887,7 +6887,11 @@ exports[`App Route /packages authenticated 1`] = ` /> + > + + diff --git a/src/components/Contexts/CarUpdatesContext.jsx b/src/components/Contexts/CarUpdatesContext.jsx index f07427b..3acffec 100644 --- a/src/components/Contexts/CarUpdatesContext.jsx +++ b/src/components/Contexts/CarUpdatesContext.jsx @@ -36,6 +36,7 @@ export const CarUpdatesProvider = ({ children }) => { const [busy, setBusy] = useState(false); const [carUpdates, setCarUpdates] = useState([]); const [versions, setVersions] = useState([SELECT_VERSION_OBJ]); + const [versionRxSwins, setVersionRxSwins] = useState([]); const [totalCarUpdates, setTotalCarUpdates] = useState(0); const [delayCount, setDelayCount] = useState(0); let progressTimer = 0; @@ -307,6 +308,24 @@ export const CarUpdatesProvider = ({ children }) => { return result; }; + const getSUMSVersionRxSwins = async (sums_version, token) => { + let result; + + try { + setBusy(true); + + result = await api.getSUMSVersionRxSwins(sums_version, token); + if (result.error) + throw new Error(`Get software version rxswins error. ${result.message}`); + + setVersionRxSwins(result.data); + } finally { + setBusy(false); + } + + return result; + }; + return ( { startMonitor, stopMonitor, updateSUMSVersion, + getSUMSVersionRxSwins, }} > {children} diff --git a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx index 4ba1ce9..a0c3825 100644 --- a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx +++ b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx @@ -122,6 +122,19 @@ let sumsVersions = { "data": ["2023.02.01.0.0.A", "2023.02.01.0.0.B"] } +let sumsVersionRxSwins = { + data: [ + { + version: "2023.02.01.0.0.A", + rxswin: "testrxswin1", + }, + { + version: "2023.02.01.0.0.A", + rxswin: "testrxswin2", + }, + ] +} + export const CarUpdatesProvider = ({ children }) => { return
{children}
; }; @@ -140,5 +153,6 @@ export const useCarUpdatesContext = () => ({ stopMonitor: jest.fn(), approveUpdate: jest.fn(), getSUMSVersions: jest.fn(() => sumsVersions), + getSUMSVersionRxSwins: jest.fn(() => sumsVersionRxSwins), updateSUMSVersion: jest.fn(), }); \ No newline at end of file diff --git a/src/components/Controls/CarUpdatesTable/index.jsx b/src/components/Controls/CarUpdatesTable/index.jsx index 7da1829..d3cc482 100644 --- a/src/components/Controls/CarUpdatesTable/index.jsx +++ b/src/components/Controls/CarUpdatesTable/index.jsx @@ -177,7 +177,9 @@ const MainForm = ({ vin, token }) => { - {row.updatemanifest?.sums} + + {row.updatemanifest?.sums} + {row.username} diff --git a/src/components/Manifest/List/index.jsx b/src/components/Manifest/List/index.jsx index d1864d2..74d1871 100644 --- a/src/components/Manifest/List/index.jsx +++ b/src/components/Manifest/List/index.jsx @@ -447,7 +447,11 @@ const MainForm = () => { {formatManifestType(row.manifest_type)} - {row.sums} + + + {row.sums} + + {formatType(row.type)} diff --git a/src/components/Routes/SiteRoutes.jsx b/src/components/Routes/SiteRoutes.jsx index 29052c2..5849252 100644 --- a/src/components/Routes/SiteRoutes.jsx +++ b/src/components/Routes/SiteRoutes.jsx @@ -41,6 +41,7 @@ const SMSSend = React.lazy(() => import("../SMS/Send")); const SuppliersList = React.lazy(() => import("../Suppliers/List")); const SupplierDetails = React.lazy(() => import("../Suppliers/Details")); const Datascope = React.lazy(() => import("../Dashboard")); +const SumsRxSwin = React.lazy(() => import("../SUMS")); const DashboardCustom = React.lazy(() => import("../DashboardCustom")); const SiteRoutes = () => { @@ -305,6 +306,15 @@ const SiteRoutes = () => { rolesPerGroup={Permissions.FiskerMagnaRead} providers={providers} /> + } + type={TYPES.PROTECTED} + token={token} + groups={groups} + rolesPerGroup={Permissions.FiskerMagnaCreate} + providers={providers} + /> diff --git a/src/components/SUMS/index.jsx b/src/components/SUMS/index.jsx new file mode 100644 index 0000000..2380a38 --- /dev/null +++ b/src/components/SUMS/index.jsx @@ -0,0 +1,102 @@ +import { + Table, + TableBody, + TableCell, + TableFooter, + TablePagination, + TableRow, +} from "@material-ui/core"; +import { logger } from "../../services/monitoring"; +import React, { useEffect, useState } from "react"; +import { useParams } from "react-router"; +import { + CarUpdatesProvider, + useCarUpdatesContext +} from "../Contexts/CarUpdatesContext"; +import { useUserContext } from "../Contexts/UserContext"; +import TableHeaderSortable from "../Table/HeaderSortable"; +import useStyles from "../useStyles"; + +const tableColumns = [ + { + id: "sums_version", + label: "SUMS Version", + }, + { + id: "sums_rxswin", + label: "RXSwin Version", + }, +]; + +const MainForm = () => { + const { sums_version } = useParams(); + const classes = useStyles(); + const [orderBy, setOrderBy] = useState("id"); + const [order, setOrder] = useState("desc"); + const { + getSUMSVersionRxSwins, + stopMonitor, + } = useCarUpdatesContext(); + const [versionRxSwins, setVersionRxSwins] = useState([]); + const { + token: { + idToken: { jwtToken: token }, + }, + } = useUserContext(); + + useEffect(() => { + (async () => { + try { + if (!sums_version || !token) return; + stopMonitor(); + await getSUMSVersionRxSwins( + sums_version, + token + ); + } catch (e) { + setVersionRxSwins(e.message); + logger.warn(e.stack); + } + })(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [sums_version, token]); + + const handleSort = (event, property) => { + try { + if (property === orderBy) { + if (order === "asc") { + setOrder("desc"); + } else { + setOrder("asc"); + } + } else { + setOrderBy(property); + setOrder("asc"); + } + } catch (e) { + logger.warn(e.stack); + } + }; + + return ( + + + + +
+ ); +}; + +const SumsRxSwin = () => ( + + + +); + +export default SumsRxSwin; \ No newline at end of file diff --git a/src/services/updatesAPI.js b/src/services/updatesAPI.js index 83f0736..65cf0c9 100644 --- a/src/services/updatesAPI.js +++ b/src/services/updatesAPI.js @@ -122,6 +122,18 @@ const updatesAPI = { }) .then(fetchRespHandler) .catch(errorHandler); + }, + + getSUMSVersionRxSwins: async (sums_version, token) => { + return fetch(`${API_ENDPOINT}/manifest/sums/${sums_version}/rxswins`, { + method: "GET", + headers: Object.assign( + { "Content-Type": "application/json" }, + getAuthHeaderOptions(token) + ), + }) + .then(fetchRespHandler) + .catch(errorHandler); } }; From 2fa9feb963eac8e4732eeb8091ca60f43c1fc18a Mon Sep 17 00:00:00 2001 From: pauladamseniii Date: Tue, 17 Oct 2023 12:11:53 -0400 Subject: [PATCH 2/8] progress; delete and list --- src/components/Contexts/CarUpdatesContext.jsx | 18 +++ .../Contexts/__mocks__/CarUpdatesContext.jsx | 1 + src/components/SUMS/index.jsx | 120 ++++++++++++++++-- src/services/updatesAPI.js | 12 ++ src/utils/roles.js | 2 +- src/utils/roles.test.js | 2 +- 6 files changed, 141 insertions(+), 14 deletions(-) diff --git a/src/components/Contexts/CarUpdatesContext.jsx b/src/components/Contexts/CarUpdatesContext.jsx index cad4a8b..2227dc5 100644 --- a/src/components/Contexts/CarUpdatesContext.jsx +++ b/src/components/Contexts/CarUpdatesContext.jsx @@ -326,12 +326,29 @@ export const CarUpdatesProvider = ({ children }) => { return result; }; + const deleteSUMSVersionRxSwins = async (sums_version, rxswin, token) => { + let result; + + try { + setBusy(true); + + result = await api.deleteSUMSVersionRxSwins(sums_version, rxswin, token); + if (result.error) + throw new Error(`Delete software version rxswin error. ${result.message}`); + } finally { + setBusy(false); + } + + return result; + }; + return ( { stopMonitor, updateSUMSVersion, getSUMSVersionRxSwins, + deleteSUMSVersionRxSwins, }} > {children} diff --git a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx index a0c3825..0477b75 100644 --- a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx +++ b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx @@ -154,5 +154,6 @@ export const useCarUpdatesContext = () => ({ approveUpdate: jest.fn(), getSUMSVersions: jest.fn(() => sumsVersions), getSUMSVersionRxSwins: jest.fn(() => sumsVersionRxSwins), + deleteSUMSVersionRxSwins: jest.fn(), updateSUMSVersion: jest.fn(), }); \ No newline at end of file diff --git a/src/components/SUMS/index.jsx b/src/components/SUMS/index.jsx index 2380a38..ff7e4cf 100644 --- a/src/components/SUMS/index.jsx +++ b/src/components/SUMS/index.jsx @@ -1,4 +1,5 @@ import { + IconButton, Table, TableBody, TableCell, @@ -6,6 +7,7 @@ import { TablePagination, TableRow, } from "@material-ui/core"; +import DeleteIcon from "@material-ui/icons/Delete"; import { logger } from "../../services/monitoring"; import React, { useEffect, useState } from "react"; import { useParams } from "react-router"; @@ -13,9 +15,14 @@ import { CarUpdatesProvider, useCarUpdatesContext } from "../Contexts/CarUpdatesContext"; +import { useStatusContext } from "../Contexts/StatusContext"; import { useUserContext } from "../Contexts/UserContext"; import TableHeaderSortable from "../Table/HeaderSortable"; +import { useLocalStorage } from "../useLocalStorage"; +import DeleteConfirmation from "../DeleteConfirmation"; import useStyles from "../useStyles"; +import { Permissions } from "../../utils/roles"; +import { RoleWrap } from "../Controls/RoleWrap"; const tableColumns = [ { @@ -28,21 +35,31 @@ const tableColumns = [ }, ]; +const PAGE_SIZE = "SUMS_RXSWIN_TABLE_PAGE_SIZE"; + const MainForm = () => { const { sums_version } = useParams(); const classes = useStyles(); + const [pageSize, setPageSize] = useLocalStorage(PAGE_SIZE, 10); + const [pageIndex, setPageIndex] = useState(0); const [orderBy, setOrderBy] = useState("id"); const [order, setOrder] = useState("desc"); + const [showDeleteModal, setShowDeleteModal] = useState(false); + const [rowToDelete, setRowToDelete] = useState({}); const { + deleteSUMSVersionRxSwins, getSUMSVersionRxSwins, + versionRxSwins, stopMonitor, } = useCarUpdatesContext(); - const [versionRxSwins, setVersionRxSwins] = useState([]); const { token: { idToken: { jwtToken: token }, }, + groups, + providers, } = useUserContext(); + const { setMessage } = useStatusContext(); useEffect(() => { (async () => { @@ -54,13 +71,22 @@ const MainForm = () => { token ); } catch (e) { - setVersionRxSwins(e.message); + setMessage(e.message); logger.warn(e.stack); } })(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [sums_version, token]); + const handleChangePageIndex = (event, newIndex) => { + setPageIndex(newIndex); + }; + + const handleChangePageSize = (event) => { + setPageSize(parseInt(event.target.value, 10)); + setPageIndex(0); + }; + const handleSort = (event, property) => { try { if (property === orderBy) { @@ -78,18 +104,88 @@ const MainForm = () => { } }; + const onDeleteClick = (row) => { + setRowToDelete(row); + setShowDeleteModal(true); + } + + const sendDelete = async () => { + if (rowToDelete) { + try { + await deleteSUMSVersionRxSwins(rowToDelete.version, rowToDelete.rxswin, token); + setMessage(`Sent delete for ${rowToDelete.rxswin}`); + } catch (e) { + setMessage(e.message); + } + } + }; + return ( - - +
+ + + {versionRxSwins.map((row, index) => ( + + + {row.version} + + + {row.rxswin} + + + + onDeleteClick(row)} + aria-label={`Send delete for ${row.rxswin}`} + size="small" + color="primary" + > + + + + + + ))} + + + + {versionRxSwins.length === 0 ? ( + No RX Identification Numbers + ) : ( + )} + + +
+ setShowDeleteModal(false)} + deleteFunction={sendDelete} /> - - - + ); }; diff --git a/src/services/updatesAPI.js b/src/services/updatesAPI.js index 65cf0c9..694afce 100644 --- a/src/services/updatesAPI.js +++ b/src/services/updatesAPI.js @@ -134,6 +134,18 @@ const updatesAPI = { }) .then(fetchRespHandler) .catch(errorHandler); + }, + + deleteSUMSVersionRxSwins: async (sums_version, rxswin, token) => { + return fetch(`${API_ENDPOINT}/manifest/sums/${sums_version}/rxswins/${rxswin}`, { + method: "DELETE", + headers: Object.assign( + { "Content-Type": "application/json" }, + getAuthHeaderOptions(token) + ), + }) + .then(fetchRespHandler) + .catch(errorHandler); } }; diff --git a/src/utils/roles.js b/src/utils/roles.js index fb8b43c..4c12370 100644 --- a/src/utils/roles.js +++ b/src/utils/roles.js @@ -96,7 +96,7 @@ export const Permissions = { [Providers.MAGNA]: [Roles.MAGNAGROUP], }, FiskerMagnaCreate: { - [Providers.FISKER]: [Roles.CREATE], + [Providers.FISKER]: [Roles.CREATE, Roles.DELETE], [Providers.FISKER_QA]: [Roles.MANUFACTURE], [Providers.MAGNA]: [Roles.MAGNAGROUP], }, diff --git a/src/utils/roles.test.js b/src/utils/roles.test.js index 9b40e97..5cfd512 100644 --- a/src/utils/roles.test.js +++ b/src/utils/roles.test.js @@ -103,7 +103,7 @@ describe("Roles Helper", () => { it("Check FiskerMagnaCreate permission", () => { expect( - hasRole([Roles.CREATE], Permissions.FiskerMagnaCreate, [Providers.FISKER]) + hasRole([Roles.CREATE, Roles.DELETE], Permissions.FiskerMagnaCreate, [Providers.FISKER]) ).toEqual(true); expect( hasRole([Roles.MAGNAGROUP], Permissions.FiskerMagnaCreate, [Providers.MAGNA]) From d0e6a43a01031eb3f2d18a998bdb431b58ed2a7f Mon Sep 17 00:00:00 2001 From: pauladamseniii Date: Tue, 17 Oct 2023 23:34:33 -0400 Subject: [PATCH 3/8] Finish UI --- src/components/Contexts/CarUpdatesContext.jsx | 13 ++ .../Contexts/__mocks__/CarUpdatesContext.jsx | 1 + src/components/Routes/SiteRoutes.jsx | 10 ++ src/components/SUMS/Add/index.jsx | 120 ++++++++++++++++++ src/components/SUMS/index.jsx | 37 +++++- src/services/updatesAPI.js | 14 +- 6 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 src/components/SUMS/Add/index.jsx diff --git a/src/components/Contexts/CarUpdatesContext.jsx b/src/components/Contexts/CarUpdatesContext.jsx index 2227dc5..fb720f3 100644 --- a/src/components/Contexts/CarUpdatesContext.jsx +++ b/src/components/Contexts/CarUpdatesContext.jsx @@ -342,6 +342,18 @@ export const CarUpdatesProvider = ({ children }) => { return result; }; + const addSUMSVersionRxSwins = async (sums_version, data, token) => { + try { + setBusy(true); + const result = await api.addSUMSVersionRxSwins(sums_version, data, token); + if (result.error) + throw new Error(`Add software version rxswin error. ${result.message}`); + return result; + } finally { + setBusy(false); + } + }; + return ( { updateSUMSVersion, getSUMSVersionRxSwins, deleteSUMSVersionRxSwins, + addSUMSVersionRxSwins, }} > {children} diff --git a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx index 0477b75..c83c7c2 100644 --- a/src/components/Contexts/__mocks__/CarUpdatesContext.jsx +++ b/src/components/Contexts/__mocks__/CarUpdatesContext.jsx @@ -155,5 +155,6 @@ export const useCarUpdatesContext = () => ({ getSUMSVersions: jest.fn(() => sumsVersions), getSUMSVersionRxSwins: jest.fn(() => sumsVersionRxSwins), deleteSUMSVersionRxSwins: jest.fn(), + addSUMSVersionRxSwins: jest.fn(), updateSUMSVersion: jest.fn(), }); \ No newline at end of file diff --git a/src/components/Routes/SiteRoutes.jsx b/src/components/Routes/SiteRoutes.jsx index 5849252..ed31bb0 100644 --- a/src/components/Routes/SiteRoutes.jsx +++ b/src/components/Routes/SiteRoutes.jsx @@ -42,6 +42,7 @@ const SuppliersList = React.lazy(() => import("../Suppliers/List")); const SupplierDetails = React.lazy(() => import("../Suppliers/Details")); const Datascope = React.lazy(() => import("../Dashboard")); const SumsRxSwin = React.lazy(() => import("../SUMS")); +const SumsRxSwinAdd = React.lazy(() => import("../SUMS/Add")); const DashboardCustom = React.lazy(() => import("../DashboardCustom")); const SiteRoutes = () => { @@ -315,6 +316,15 @@ const SiteRoutes = () => { rolesPerGroup={Permissions.FiskerMagnaCreate} providers={providers} /> + } + type={TYPES.PROTECTED} + token={token} + groups={groups} + rolesPerGroup={Permissions.FiskerMagnaCreate} + providers={providers} + /> diff --git a/src/components/SUMS/Add/index.jsx b/src/components/SUMS/Add/index.jsx new file mode 100644 index 0000000..2ea14b9 --- /dev/null +++ b/src/components/SUMS/Add/index.jsx @@ -0,0 +1,120 @@ +import { + Button, + TextField +} from "@material-ui/core"; +import { useParams } from "react-router"; +import React, { useEffect, useState } from "react"; +import { Redirect } from "react-router"; +import { logger } from "../../../services/monitoring"; +import { useStatusContext } from "../../Contexts/StatusContext"; +import { + CarUpdatesProvider, + useCarUpdatesContext +} from "../../Contexts/CarUpdatesContext"; +import { useUserContext } from "../../Contexts/UserContext"; +import useStyles from "../../useStyles"; + +const MainForm = () => { + const { addSUMSVersionRxSwins, busy } = useCarUpdatesContext(); + const { + token: { + idToken: { jwtToken: token }, + }, + } = useUserContext(); + const classes = useStyles(); + const [redirect, setRedirect] = useState(null); + const { sums_version } = useParams(); + const { setMessage, setTitle, setSitePath } = useStatusContext(); + const [rxswin, setRxswin] = useState(""); + + useEffect(() => { + setTitle(`Add RXSWIN to SUMS Version ${sums_version}`); + setSitePath([ + { + label: `SUMS Version ${sums_version}`, + link: `/sums/${sums_version}`, + }, + { + label: `SUMS Version ${sums_version}`, + link: `/sums-rxswin-add/${sums_version}`, + }, + { + label: `Add RXSWIN`, + }, + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + const onRxswinChange = (event) => { + setRxswin(event.target.value); + } + + const onSubmit = async (event) => { + try { + event.preventDefault(); + + const data = { + "swversion_rxswins": [ + { + "version": sums_version, + "rxswin": rxswin, + }, + ], + }; + + const result = await addSUMSVersionRxSwins(sums_version, data, token); + if (!result || result.error) return; + + setMessage(`Added ${rxswin}`); + setRedirect(`/sums/${sums_version}`); + } catch (e) { + setMessage(e.message); + logger.warn(e.stack); + } + }; + + if (redirect && redirect.length > 0) { + return ; + } + + return ( +
+
+ + + +
+ ); +}; + +const SumsRxSwinAdd = () => ( + + + +); + +export default SumsRxSwinAdd; \ No newline at end of file diff --git a/src/components/SUMS/index.jsx b/src/components/SUMS/index.jsx index ff7e4cf..b8efb42 100644 --- a/src/components/SUMS/index.jsx +++ b/src/components/SUMS/index.jsx @@ -1,4 +1,5 @@ import { + Grid, IconButton, Table, TableBody, @@ -7,7 +8,10 @@ import { TablePagination, TableRow, } from "@material-ui/core"; +import AddCircleIcon from "@material-ui/icons/AddCircle"; import DeleteIcon from "@material-ui/icons/Delete"; +import clsx from "clsx"; +import { LocalDateTimeString } from "../../utils/dates"; import { logger } from "../../services/monitoring"; import React, { useEffect, useState } from "react"; import { useParams } from "react-router"; @@ -17,6 +21,7 @@ import { } from "../Contexts/CarUpdatesContext"; import { useStatusContext } from "../Contexts/StatusContext"; import { useUserContext } from "../Contexts/UserContext"; +import { Link } from "react-router-dom"; import TableHeaderSortable from "../Table/HeaderSortable"; import { useLocalStorage } from "../useLocalStorage"; import DeleteConfirmation from "../DeleteConfirmation"; @@ -26,12 +31,12 @@ import { RoleWrap } from "../Controls/RoleWrap"; const tableColumns = [ { - id: "sums_version", - label: "SUMS Version", + id: "sums_rxswin", + label: "RXSWIN (RX Software Identification Number)", }, { - id: "sums_rxswin", - label: "RXSwin Version", + id: "created_at", + label: "Created", }, ]; @@ -59,7 +64,18 @@ const MainForm = () => { groups, providers, } = useUserContext(); - const { setMessage } = useStatusContext(); + const { setMessage, setTitle, setSitePath } = useStatusContext(); + + useEffect(() => { + setTitle(`SUMS Version ${sums_version}`); + setSitePath([ + { + label: `SUMS Version ${sums_version}`, + link: `/sums/${sums_version}`, + }, + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); useEffect(() => { (async () => { @@ -122,6 +138,13 @@ const MainForm = () => { return (
+ + + + + + + { {versionRxSwins.map((row, index) => ( - {row.version} + {row.rxswin} - {row.rxswin} + {LocalDateTimeString(row.created)} + fetch(`${API_ENDPOINT}/manifest/sums/${sums_version}/rxswins`, { + method: "POST", + headers: Object.assign( + { "Content-Type": "application/json" }, + getAuthHeaderOptions(token) + ), + body: JSON.stringify(data), + }) + .then(fetchRespHandler) + .catch(errorHandler), }; export default updatesAPI; \ No newline at end of file From dd0bce2f5d1573c19547089b00f15f5f673d8fd3 Mon Sep 17 00:00:00 2001 From: pauladamseniii Date: Wed, 18 Oct 2023 00:04:53 -0400 Subject: [PATCH 4/8] tests --- .../Add/__snapshots__/index.test.jsx.snap | 92 +++++++++++++ src/components/SUMS/Add/index.test.jsx | 46 +++++++ .../SUMS/__snapshots__/index.test.jsx.snap | 123 ++++++++++++++++++ src/components/SUMS/index.jsx | 4 +- src/components/SUMS/index.test.jsx | 46 +++++++ 5 files changed, 309 insertions(+), 2 deletions(-) create mode 100644 src/components/SUMS/Add/__snapshots__/index.test.jsx.snap create mode 100644 src/components/SUMS/Add/index.test.jsx create mode 100644 src/components/SUMS/__snapshots__/index.test.jsx.snap create mode 100644 src/components/SUMS/index.test.jsx diff --git a/src/components/SUMS/Add/__snapshots__/index.test.jsx.snap b/src/components/SUMS/Add/__snapshots__/index.test.jsx.snap new file mode 100644 index 0000000..1a38a9d --- /dev/null +++ b/src/components/SUMS/Add/__snapshots__/index.test.jsx.snap @@ -0,0 +1,92 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SUMSAdd Render 1`] = ` +
+
+
+
+
+
+
+
+ +
+ + +
+
+ + +
+
+
+
+
+
+`; diff --git a/src/components/SUMS/Add/index.test.jsx b/src/components/SUMS/Add/index.test.jsx new file mode 100644 index 0000000..dd85da0 --- /dev/null +++ b/src/components/SUMS/Add/index.test.jsx @@ -0,0 +1,46 @@ +jest.mock("../../Contexts/CarUpdatesContext"); +jest.mock("../../Contexts/StatusContext"); +jest.mock("../../Contexts/UserContext"); +jest.mock("@material-ui/core/utils/unstable_useId", () => + jest.fn().mockReturnValue("mui-test-id") +); + +import { render, waitFor } from "@testing-library/react"; +import { BrowserRouter } from "react-router-dom"; + +import { CarUpdatesProvider } from "../../Contexts/CarUpdatesContext"; +import { StatusProvider } from "../../Contexts/StatusContext"; +import { UserProvider, setToken } from "../../Contexts/UserContext"; +import { TEST_AUTH_OBJECT_FISKER } from "../../../utils/testing"; +import MainForm from "./index"; +import addSnapshotSerializer from "../../../utils/snapshot"; + +const renderSUMSAdd = async () => { + const { container } = render( + + + + + + + + + + ); + await waitFor(() => { + /* render */ + }); + return container; +}; + +describe("SUMSAdd", () => { + beforeAll(() => { + addSnapshotSerializer(expect); + }); + + it("Render", async () => { + setToken(TEST_AUTH_OBJECT_FISKER); + const container = await renderSUMSAdd(); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/src/components/SUMS/__snapshots__/index.test.jsx.snap b/src/components/SUMS/__snapshots__/index.test.jsx.snap new file mode 100644 index 0000000..8d02277 --- /dev/null +++ b/src/components/SUMS/__snapshots__/index.test.jsx.snap @@ -0,0 +1,123 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SUMS Render 1`] = ` +
+
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + +
+ + RXSWIN (RX Software Identification Number) + + + + + Created + + +
+
+
+
+ + + + +`; diff --git a/src/components/SUMS/index.jsx b/src/components/SUMS/index.jsx index b8efb42..3b757b3 100644 --- a/src/components/SUMS/index.jsx +++ b/src/components/SUMS/index.jsx @@ -154,7 +154,7 @@ const MainForm = () => { onSortRequest={handleSort} /> - {versionRxSwins.map((row, index) => ( + {versionRxSwins && versionRxSwins.map((row, index) => ( {row.rxswin} @@ -183,7 +183,7 @@ const MainForm = () => { - {versionRxSwins.length === 0 ? ( + {!versionRxSwins || versionRxSwins.length === 0 ? ( No RX Identification Numbers ) : ( + jest.fn().mockReturnValue("mui-test-id") +); + +import { render, waitFor } from "@testing-library/react"; +import { BrowserRouter } from "react-router-dom"; + +import { CarUpdatesProvider } from "../Contexts/CarUpdatesContext"; +import { StatusProvider } from "../Contexts/StatusContext"; +import { UserProvider, setToken } from "../Contexts/UserContext"; +import { TEST_AUTH_OBJECT_FISKER } from "../../utils/testing"; +import MainForm from "./index"; +import addSnapshotSerializer from "../../utils/snapshot"; + +const renderSUMS = async () => { + const { container } = render( + + + + + + + + + + ); + await waitFor(() => { + /* render */ + }); + return container; +}; + +describe("SUMS", () => { + beforeAll(() => { + addSnapshotSerializer(expect); + }); + + it("Render", async () => { + setToken(TEST_AUTH_OBJECT_FISKER); + const container = await renderSUMS(); + expect(container).toMatchSnapshot(); + }); +}); From 8aa80ec207b85d8abb2de5fc141423742223326c Mon Sep 17 00:00:00 2001 From: pauladamseniii Date: Wed, 18 Oct 2023 14:51:05 -0400 Subject: [PATCH 5/8] issues fixed --- src/components/Contexts/CarUpdatesContext.jsx | 9 +++- .../SUMS/__snapshots__/index.test.jsx.snap | 10 +++- src/components/SUMS/index.jsx | 54 +++++++++++-------- src/services/updatesAPI.js | 4 +- src/utils/roles.js | 7 ++- src/utils/roles.test.js | 14 ++++- 6 files changed, 69 insertions(+), 29 deletions(-) diff --git a/src/components/Contexts/CarUpdatesContext.jsx b/src/components/Contexts/CarUpdatesContext.jsx index fb720f3..746dfbe 100644 --- a/src/components/Contexts/CarUpdatesContext.jsx +++ b/src/components/Contexts/CarUpdatesContext.jsx @@ -57,6 +57,7 @@ export const CarUpdatesProvider = ({ children }) => { const [carUpdates, setCarUpdates] = useState([]); const [versions, setVersions] = useState([SELECT_VERSION_OBJ]); const [versionRxSwins, setVersionRxSwins] = useState([]); + const [totalVersionRxSwins, setTotalVersionRxSwins] = useState(0); const [totalCarUpdates, setTotalCarUpdates] = useState(0); const [delayCount, setDelayCount] = useState(0); let progressTimer = 0; @@ -308,17 +309,20 @@ export const CarUpdatesProvider = ({ children }) => { return result; }; - const getSUMSVersionRxSwins = async (sums_version, token) => { + const getSUMSVersionRxSwins = async (sums_version, options, token) => { let result; try { setBusy(true); - result = await api.getSUMSVersionRxSwins(sums_version, token); + result = await api.getSUMSVersionRxSwins(sums_version, options, token); if (result.error) throw new Error(`Get software version rxswins error. ${result.message}`); setVersionRxSwins(result.data); + if (options && options.offset === 0 && result.total) { + setTotalVersionRxSwins(result.total); + } } finally { setBusy(false); } @@ -374,6 +378,7 @@ export const CarUpdatesProvider = ({ children }) => { stopMonitor, updateSUMSVersion, getSUMSVersionRxSwins, + totalVersionRxSwins, deleteSUMSVersionRxSwins, addSUMSVersionRxSwins, }} diff --git a/src/components/SUMS/__snapshots__/index.test.jsx.snap b/src/components/SUMS/__snapshots__/index.test.jsx.snap index 8d02277..f68b68c 100644 --- a/src/components/SUMS/__snapshots__/index.test.jsx.snap +++ b/src/components/SUMS/__snapshots__/index.test.jsx.snap @@ -71,19 +71,25 @@ exports[`SUMS Render 1`] = ` Created + + sorted descending +
-
- -
-