From 378e58a31092162b4727f8562d0825160f5d8b52 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Tue, 10 Aug 2021 15:52:10 -0700 Subject: [PATCH 1/3] removed greeting and fixed grafana mock --- src/components/App/App.test.js | 13 ++++++------ .../App/__snapshots__/App.test.js.snap | 14 ------------- src/components/Home/index.jsx | 7 ------- src/services/__mocks__/grafana.js | 19 +++-------------- src/services/grafana.js | 21 +++++++++++++++++-- 5 files changed, 29 insertions(+), 45 deletions(-) diff --git a/src/components/App/App.test.js b/src/components/App/App.test.js index 44c1aba..b1e5178 100644 --- a/src/components/App/App.test.js +++ b/src/components/App/App.test.js @@ -5,6 +5,7 @@ jest.mock("../Contexts/UserContext"); jest.mock("../Contexts/ManifestsContext"); jest.mock("../Contexts/CarUpdatesContext"); jest.mock("../../services/monitoring"); +jest.mock("../../services/grafana"); import { render, screen, cleanup, waitFor, waitForElementToBeRemoved } from "@testing-library/react"; import { setToken } from "../Contexts/UserContext"; @@ -57,11 +58,11 @@ describe("App", () => { }); it("Route / unauthenticated", async () => { - await check("/", "span.MuiButton-label", "Sign In"); + await sleepAndCheck("/", "span.MuiButton-label", "Sign In"); }); it("Route /home unauthenticated", async () => { - await check("/home", "span.MuiButton-label", "Sign In"); + await sleepAndCheck("/home", "span.MuiButton-label", "Sign In"); }); it("Route /vehicle-add unauthenticated", async () => { @@ -85,7 +86,7 @@ describe("App", () => { }); it("Route /datascope unauthenticated", async () => { - await check("/datascope", "span.MuiButton-label", "Sign In"); + await sleepAndCheck("/datascope", "span.MuiButton-label", "Sign In"); }); it("Route /datascope/battery unauthenticated", async () => { @@ -110,12 +111,12 @@ describe("App", () => { it("Route / authenticated", async () => { setToken(TEST_AUTH_OBJECT); - await sleepAndCheck("/", "h1", "Welcome John!"); + await sleepAndCheck("/", "h6", "Home"); }); it("Route /home authenticated", async () => { setToken(TEST_AUTH_OBJECT); - await sleepAndCheck("/home", "h1", "Welcome John!"); + await sleepAndCheck("/home", "h6", "Home"); }); it("Route /vehicle-add authenticated", async () => { @@ -154,7 +155,7 @@ describe("App", () => { it("Route /datascope authenticated", async () => { setToken(TEST_AUTH_OBJECT); - await check("/datascope", "h6", "Datascope"); + await sleepAndCheck("/datascope", "h6", "Datascope"); }); it("Route /datascope/battery authenticated", async () => { diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index a11d353..f2dbf63 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -277,13 +277,6 @@ exports[`App Route / authenticated 1`] = `
-

- Welcome - John - ! -

@@ -3073,13 +3066,6 @@ exports[`App Route /home authenticated 1`] = `
-

- Welcome - John - ! -

diff --git a/src/components/Home/index.jsx b/src/components/Home/index.jsx index ff649f4..c8832aa 100644 --- a/src/components/Home/index.jsx +++ b/src/components/Home/index.jsx @@ -1,15 +1,11 @@ import React, { useEffect } from "react"; -import { Typography } from "@material-ui/core"; import useStyles from "../useStyles"; -import { useUserContext } from "../Contexts/UserContext"; import { useStatusContext } from "../Contexts/StatusContext"; import VehicleMap from "../VehicleMap"; -import { getName } from "../../utils/jwt"; const Home = () => { const classes = useStyles(); - const { token } = useUserContext(); const { setTitle, setSitePath } = useStatusContext(); useEffect(() => { @@ -20,9 +16,6 @@ const Home = () => { return (
- - Welcome {getName(token)}! -
); diff --git a/src/services/__mocks__/grafana.js b/src/services/__mocks__/grafana.js index 4424256..8376f2c 100644 --- a/src/services/__mocks__/grafana.js +++ b/src/services/__mocks__/grafana.js @@ -1,19 +1,6 @@ const grafanaAPI = { - getCarsCount: async () => fetch(`${API_ENDPOINT}/?query=SELECT%20countDistinct(vin)%20as%20count%0AFROM%20default.vehicle_data%20FORMAT%20JSON`, { - method: "GET", - headers: Object.assign({ "Content-Type": "application/json" }), - }) - .then(fetchRespHandler) - .then(result => result.data[0].count) - .catch(error => console.log(error)), - - getSignalsCount: async () => fetch(`${API_ENDPOINT}/?query=SELECT%20count()%20as%20count%0AFROM%20default.vehicle_signal%20FORMAT%20JSON`, { - method: "GET", - headers: Object.assign({ "Content-Type": "application/json" }), - }) - .then(fetchRespHandler) - .then(result => result.data[0].count) - .catch(error => console.log(error)), + getCarsCount: async () => 500, + getSignalsCount: async () => 1234567890, }; -export default vehiclesAPI; +export default grafanaAPI; diff --git a/src/services/grafana.js b/src/services/grafana.js index 8376f2c..a162eac 100644 --- a/src/services/grafana.js +++ b/src/services/grafana.js @@ -1,6 +1,23 @@ +import { fetchRespHandler } from "../utils/http" + +const API_ENDPOINT = "https://grafana.fiskerdps.com/api/datasources/proxy/2" + const grafanaAPI = { - getCarsCount: async () => 500, - getSignalsCount: async () => 1234567890, + getCarsCount: async () => fetch(`${API_ENDPOINT}/?query=SELECT%20countDistinct(vin)%20as%20count%0AFROM%20default.vehicle_data%20FORMAT%20JSON`, { + method: "GET", + headers: Object.assign({ "Content-Type": "application/json" }), + }) + .then(fetchRespHandler) + .then(result => result.data[0].count) + .catch(error => console.log(error)), + + getSignalsCount: async () => fetch(`${API_ENDPOINT}/?query=SELECT%20count()%20as%20count%0AFROM%20default.vehicle_signal%20FORMAT%20JSON`, { + method: "GET", + headers: Object.assign({ "Content-Type": "application/json" }), + }) + .then(fetchRespHandler) + .then(result => result.data[0].count) + .catch(error => console.log(error)), }; export default grafanaAPI; From 2b95bab38b8374c5040bb94bc7d3b6d674de8300 Mon Sep 17 00:00:00 2001 From: John Wu <76966357+jwu-fisker@users.noreply.github.com> Date: Tue, 10 Aug 2021 18:11:14 -0700 Subject: [PATCH 2/3] CEC-381 Install messages and update styling (#76) * Styling * Handle install messages * Update progress * Display download and install status --- .../App/__snapshots__/App.test.js.snap | 779 +++++++++--------- src/components/Cars/SendCommand/index.jsx | 15 +- src/components/Cars/SendCommandBulk/index.jsx | 10 +- src/components/Contexts/CarUpdatesContext.jsx | 39 +- src/components/Layouts/MenuDrawer.jsx | 4 +- src/components/Manifest/Deploy/index.jsx | 7 +- src/components/Manifest/List/index.jsx | 19 +- src/components/useStyles.jsx | 7 +- 8 files changed, 477 insertions(+), 403 deletions(-) diff --git a/src/components/App/__snapshots__/App.test.js.snap b/src/components/App/__snapshots__/App.test.js.snap index f2dbf63..0d7a7a5 100644 --- a/src/components/App/__snapshots__/App.test.js.snap +++ b/src/components/App/__snapshots__/App.test.js.snap @@ -6,10 +6,10 @@ exports[`App Route / authenticated 1`] = ` data-testid="mocked-userprovider" >
Fisker Admin Portal
@@ -266,16 +266,16 @@ exports[`App Route / authenticated 1`] = `
Fisker Admin Portal
@@ -716,10 +716,10 @@ exports[`App Route /carupdate-deploy authenticated 1`] = `

0 Selected
@@ -813,7 +813,7 @@ exports[`App Route /carupdate-deploy authenticated 1`] = ` style="text-align: right;" >
VIN sorted ascending @@ -1166,10 +1166,10 @@ exports[`App Route /carupdate-deploy unauthenticated 1`] = ` data-testid="mocked-userprovider" >
@@ -1740,10 +1740,10 @@ exports[`App Route /datascope authenticated 1`] = ` data-testid="mocked-userprovider" >
Fisker Admin Portal
@@ -2000,34 +2000,34 @@ exports[`App Route /datascope authenticated 1`] = `

500

Cars

@@ -2037,16 +2037,16 @@ exports[`App Route /datascope authenticated 1`] = ` class="MuiGrid-root MuiGrid-item MuiGrid-grid-md-6" >

1,234,567,890

Signals Collected

@@ -2056,10 +2056,10 @@ exports[`App Route /datascope authenticated 1`] = ` class="MuiGrid-root MuiGrid-item MuiGrid-grid-md-12" >