CEC-2654: Map polls for curren visible area (#222)

Update index.jsx
Added some tests, still don't meet  threshold

Co-authored-by: Alexander Andrews <aandrews@fiskerinc.com>
This commit is contained in:
Alexander Andrews
2022-10-24 16:08:18 -04:00
committed by GitHub
parent 525c1ca6d5
commit b45c70bd52
10 changed files with 324 additions and 45 deletions

View File

@@ -89,10 +89,10 @@ export const VehicleProvider = ({ children }) => {
}
};
const getLocations = async (token) => {
const getLocations = async (token, mapLocationInfo) => {
try {
setBusy(true);
const result = await api.getLocations(token);
const result = await api.getLocations(token, mapLocationInfo);
if (result.error)
throw new Error(`Get locations error. ${result.message}`);
return result;

View File

@@ -9,6 +9,7 @@ import {
} from "@testing-library/react";
import { VehicleProvider, useVehicleContext } from "./VehicleContext";
import { StatusProvider, useStatusContext } from "./StatusContext";
import { act } from "react-dom/test-utils";
const checkVehicleResult = (error, busy, vehicle) => {
checkBaseResults(error, busy);
@@ -437,6 +438,56 @@ describe("VehicleContext", () => {
checkBaseResults("", "false");
});
});
describe("Get Locations", () => {
var locationFilter = {
center: {
longitude: 0,
latitude: 0
},
width: 0,
height: 0
}
var locations;
beforeEach(() => {
const TestComp = () => {
const { busy, error, getLocations } = useVehicleContext();
return (
<>
<div data-testid="error">{error}</div>
<div data-testid="busy">{busy.toString()}</div>
<button data-testid="getLocations" onClick={() => locations = getLocations(null, locationFilter)} />
</>
)
}
render(
<VehicleProvider>
<TestComp />
</VehicleProvider>
)
})
afterEach(() => {
cleanup()
})
it("Initial state", () => {
checkBaseResults("", "false")
})
it("getVehicleLocations", async () => {
await act(async () => {
fireEvent.click(screen.getByTestId("getLocations"))
locations = await locations
})
checkBaseResults("", "false")
expect(locations.data).toStrictEqual(expectedLocationsData)
})
})
});
const expectedFilters = [
@@ -528,3 +579,5 @@ const expectedVehiclesData = [
connectedHMI: false,
},
];
const expectedLocationsData = [{ altitude: 0, longitude: 10, latitude: 15, vin: "TESTVIN123" }]