removed greeting and fixed grafana mock

This commit is contained in:
Drew Taylor
2021-08-10 15:52:10 -07:00
parent e50eb886e6
commit 378e58a310
5 changed files with 29 additions and 45 deletions

View File

@@ -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 () => {

View File

@@ -277,13 +277,6 @@ exports[`App Route / authenticated 1`] = `
<div
class="makeStyles-paper-601"
>
<h1
class="MuiTypography-root makeStyles-homePageTitle-632 MuiTypography-h5"
>
Welcome
John
!
</h1>
<div
data-testid="mocked-vehicleprovider"
>
@@ -3073,13 +3066,6 @@ exports[`App Route /home authenticated 1`] = `
<div
class="makeStyles-paper-647"
>
<h1
class="MuiTypography-root makeStyles-homePageTitle-678 MuiTypography-h5"
>
Welcome
John
!
</h1>
<div
data-testid="mocked-vehicleprovider"
>

View File

@@ -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 (
<div className={classes.paper}>
<Typography className={classes.homePageTitle} component="h1" variant="h5">
Welcome {getName(token)}!
</Typography>
<VehicleMap />
</div>
);

View File

@@ -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;

View File

@@ -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;