+ Issue Details +
++ + ID + + : + FISKER123 +
++ + VIN + + : + 1GNGC26RXXJ407648 +
++ + Title + + : + sometitle +
++ + Description + + : + 2343242 +
++ + timestamp + + : + 2022-12-09T23:16:38.074858Z +
+diff --git a/src/components/App/App.test.js b/src/components/App/App.test.js index 0eab94a..b118fc8 100644 --- a/src/components/App/App.test.js +++ b/src/components/App/App.test.js @@ -3,9 +3,12 @@ jest.mock("../Contexts/FileUploadContext"); jest.mock("../Contexts/VehicleContext"); jest.mock("../Contexts/ManifestsContext"); jest.mock("../Contexts/UserContext"); +jest.mock("../Contexts/IssueContext"); jest.mock("../../services/monitoring"); jest.mock("../../services/vehiclesAPI"); -jest.mock("../../services/superset") +jest.mock("../../services/superset"); +jest.mock("../../services/suppliersAPI"); +jest.mock("../../services/issueAPI"); import { act, cleanup, render, @@ -39,13 +42,14 @@ const check = async (path, selector, compare) => { const sleepAndCheck = async (path, selector, compare) => { const container = await renderRoute(path); - await waitFor(() => {}); + await waitFor(() => { }); expect(container.querySelector(selector).innerHTML).toEqual(compare); expect(container).toMatchSnapshot(); }; describe("App", () => { beforeAll(() => { + global.URL.createObjectURL = jest.fn(); addSnapshotSerializer(expect); }, 60000); @@ -78,6 +82,14 @@ describe("App", () => { await check("/vehicle-add", "span.MuiButton-label", "Sign In"); }); + it("Route /issues unauthenticated", async () => { + await check("/issues", "span.MuiButton-label", "Sign In"); + }); + + it("Route /issue-info unauthenticated", async () => { + await check("/issue-info/FISKER123", "span.MuiButton-label", "Sign In"); + }); + it("Route /vehicles unauthenticated", async () => { await check("/vehicles", "span.MuiButton-label", "Sign In"); }); @@ -158,6 +170,17 @@ describe("App", () => { await check("/vehicles", "h6", "Vehicles"); }); + it("Route /issues authenticated", async () => { + setToken(TEST_AUTH_OBJECT_FISKER); + await check("/issues", "h6", "Issues"); + }); + + it("Route /issue-info authenticated", async () => { + setToken(TEST_AUTH_OBJECT_FISKER); + await check("/issue-info/FISKER123", "h6", "Issue FISKER123 Details"); + }); + + it("Route /vehicle-status authenticated", async () => { setToken(TEST_AUTH_OBJECT_FISKER); await check("/vehicle-status/FISKER123", "h6", "Vehicle FISKER123 Details"); diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index 6d15848..348551e 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -173,6 +173,42 @@ exports[`App Route / authenticated 1`] = ` /> +
+ + ID + + : + FISKER123 +
++ + VIN + + : + 1GNGC26RXXJ407648 +
++ + Title + + : + sometitle +
++ + Description + + : + 2343242 +
++ + timestamp + + : + 2022-12-09T23:16:38.074858Z +
++ + Note: Your email address will be used as the user id + +
+| + + Id + + + | ++ + VIN + + + | ++ + Title + + + | ++ + Description + + + | ++ + Driver ID + + + | ++ + Created + + sorted ascending + + + + | ++ |
|---|---|---|---|---|---|---|
| + + 15 + + | ++ 4Y1SL65848Z411439 + | ++ sometitle + | ++ 2343242 + | ++ 12345 + | ++ 12/9/2022 11:16:38 PM + | +|
| + + 17 + + | ++ 1GNGC26RXXJ407648 + | ++ sometitle + | ++ 2343242 + | ++ valid-cognito-id-1 + | ++ 12/9/2022 11:16:38 PM + | +|
| + + | +||||||
+ + Note: Your email address will be used as the user id + +
++ No Car Updates found +
diff --git a/src/components/Contexts/IssueContext.jsx b/src/components/Contexts/IssueContext.jsx new file mode 100644 index 0000000..570929a --- /dev/null +++ b/src/components/Contexts/IssueContext.jsx @@ -0,0 +1,55 @@ +import React, { useContext, useState, useMemo, useCallback } from "react"; +import api from "../../services/issueAPI"; + +const IssueContext = React.createContext(); + +export const IssueProvider = ({ children }) => { + const [issue, setIssue] = useState({}); + const [issues, setIssues] = useState([]); + const [totalIssues, setTotalIssues] = useState(0); + + const getIssue = useCallback(async (id, token) => { + const result = await api.getIssue(id, token); + if (result.error) throw new Error(`Get issue error. ${result.message}`); + + setIssue(result.data ?? []); + return result; + }, []); + + const getIssues = useCallback(async (search,token) => { + const result = await api.getIssues(search,token); + if (result.error) { + setIssues([]); + throw new Error(`Get issues error. ${result.message}`); + } + setIssues(result.data ?? []); + if (result.total) { + setTotalIssues(result.total); + } + }, []); + + const deleteIssue = useCallback(async (id, token) => { + const result = await api.deleteIssue(id, token); + if (result.error) + throw new Error(`Delete issue error. ${result.message}`); + return result; + }, []); + + const value = useMemo(() => ({ + totalIssues, + issue, + issues, + + deleteIssue, + getIssue, + getIssues, + }), [totalIssues, issue, issues, deleteIssue, getIssue, getIssues]); + + return ( +