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

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

  it("makes request to delete multiple vehicles", async () => {
    const api = jest.spyOn(vehiclesAPI, "deleteVehicle");
    const ref = React.createRef();

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

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