CEC-5898 - Bulk action to update flashpack numbers for fleet cars
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { forwardRef, useImperativeHandle } from "react";
|
||||
import { useStatusContext } from "../../Contexts/StatusContext";
|
||||
import { useUserContext } from "../../Contexts/UserContext";
|
||||
import vehiclesAPI from "../../../services/vehiclesAPI";
|
||||
|
||||
export default forwardRef(({
|
||||
ids,
|
||||
idCSV,
|
||||
}, ref) => {
|
||||
const { setMessage } = useStatusContext();
|
||||
const { token: { idToken: { jwtToken: token } } } = useUserContext();
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
async submit() {
|
||||
return vehiclesAPI
|
||||
.flashpackVersionBulkUpdate(ids, token)
|
||||
.then((data) => {
|
||||
if (data.error) {
|
||||
setMessage(`${data.error}: ${data.message}`);
|
||||
} else if (ids.length === 1) {
|
||||
setMessage(`Updating flashpack number for ${ids[0]}`);
|
||||
} else {
|
||||
setMessage(`Updating flashpack numbers for ${ids.length} cars`);
|
||||
}
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
You are updating flashpack numbers for the following VINs: {idCSV}.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
jest.mock("../../Contexts/UserContext");
|
||||
jest.mock("../../Contexts/StatusContext");
|
||||
jest.mock("../../../services/vehiclesAPI");
|
||||
|
||||
import React from "react";
|
||||
import {
|
||||
render,
|
||||
act,
|
||||
} from "@testing-library/react";
|
||||
import { UserProvider, setToken } from "../../Contexts/UserContext";
|
||||
import { StatusProvider } from "../../Contexts/StatusContext";
|
||||
import { TEST_AUTH_OBJECT_FISKER } from "../../../utils/testing";
|
||||
import UpdateFlashpackNumbers from "./UpdateFlashpackNumbers";
|
||||
import vehiclesAPI from "../../../services/vehiclesAPI";
|
||||
|
||||
describe("BulkActions/UpdateFlashpackNumbers", () => {
|
||||
beforeAll(() => {
|
||||
setToken(TEST_AUTH_OBJECT_FISKER);
|
||||
});
|
||||
|
||||
it("makes request to update flashpack numbers", async () => {
|
||||
const flashpackVersionBulkUpdate = jest.spyOn(vehiclesAPI, "flashpackVersionBulkUpdate");
|
||||
const ref = React.createRef();
|
||||
|
||||
const vins = ["TESTVIN123456789a", "TESTVIN123456789b", "TESTVIN123456789c"];
|
||||
|
||||
render(
|
||||
<StatusProvider>
|
||||
<UserProvider>
|
||||
<UpdateFlashpackNumbers
|
||||
ref={ref}
|
||||
ids={vins}
|
||||
idCSV=""
|
||||
/>
|
||||
</UserProvider>
|
||||
</StatusProvider>
|
||||
);
|
||||
|
||||
await act(async () => ref.current.submit());
|
||||
expect(flashpackVersionBulkUpdate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,7 @@ const RemoteCommand = lazy(() => import("./actions/RemoteCommand"));
|
||||
const SendSMS = lazy(() => import("./actions/SendSMS"));
|
||||
const UpdateConfig = lazy(() => import("./actions/UpdateConfig"));
|
||||
const UpdateFleetVehicles = lazy(() => import("./actions/UpdateFleetVehicles"));
|
||||
const UpdateFlashpackNumbers = lazy(() => import("./actions/UpdateFlashpackNumbers"));
|
||||
|
||||
export default function BulkActions({
|
||||
ids = [],
|
||||
@@ -79,6 +80,12 @@ export default function BulkActions({
|
||||
disabled: false,
|
||||
trigger: () => setActive("updateFleetVehicles"),
|
||||
},
|
||||
{
|
||||
id: "updateFlashpackNumbers",
|
||||
name: "Update Flashpack Numbers",
|
||||
disabled: false,
|
||||
trigger: () => setActive("updateFlashpackNumbers")
|
||||
}
|
||||
].filter((action) => actions.includes(action.id));
|
||||
|
||||
const payload = {
|
||||
@@ -127,6 +134,7 @@ export default function BulkActions({
|
||||
{active === "sms" && <SendSMS {...payload} />}
|
||||
{active === "updateConfig" && <UpdateConfig {...payload} />}
|
||||
{active === "updateFleetVehicles" && <UpdateFleetVehicles {...payload} />}
|
||||
{active === "updateFlashpackNumbers" && <UpdateFlashpackNumbers {...payload} />}
|
||||
</section>
|
||||
</Suspense>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user