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 UpdateConfig from "./UpdateConfig";
import vehiclesAPI from "../../../services/vehiclesAPI";

describe("BulkActions/UpdateConfig", () => {
  beforeAll(() => {
    setToken(TEST_AUTH_OBJECT_FISKER);
  });

  it("makes request to update the config of multiple vehicles", async () => {
    const api = jest.spyOn(vehiclesAPI, "updateConfig");
    const ref = React.createRef();

    render(
      <StatusProvider>
        <UserProvider>
          <UpdateConfig
            ref={ref}
            ids={["TESTVIN123456789a", "TESTVIN123456789b", "TESTVIN123456789c"]}
            idCSV=""
          />
        </UserProvider>
      </StatusProvider>
    );

    await act(async () => ref.current.submit());
    expect(api).toHaveBeenCalledTimes(3);
  });
});
