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, TEST_TOKEN_FISKER } from "../../../utils/testing";
import Diagnostic from "./Diagnostic";
import vehiclesAPI from "../../../services/vehiclesAPI";

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

  it("makes request to send remote command", async () => {
    const sendDiagnosticCommand = jest.spyOn(vehiclesAPI, "sendDiagnosticCommand");
    const getECUs = jest.spyOn(vehiclesAPI, "getECUs");
    const ref = React.createRef();

    const vins = ["TESTVIN123456789a", "TESTVIN123456789b", "TESTVIN123456789c"];

    render(
      <StatusProvider>
        <UserProvider>
          <Diagnostic
            ref={ref}
            ids={vins}
            idCSV=""
          />
        </UserProvider>
      </StatusProvider>
    );

    await act(async () => ref.current.submit());
    expect(sendDiagnosticCommand).toHaveBeenCalledTimes(1);
    expect(sendDiagnosticCommand).toHaveBeenCalledWith(vins, {
      command: "remote_reset",
      ecu_name: "TBOX",
    }, TEST_TOKEN_FISKER);
    expect(getECUs).toHaveBeenCalledTimes(3);
  });
});
