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);
  });
});
