jest.mock("../../Contexts/UserContext");
jest.mock("../../Contexts/StatusContext");
jest.mock("../../../services/updatesAPI");

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 Cancel from "./Cancel";
import updatesAPI from "../../../services/updatesAPI";

describe("Manifest/Cancel", () => {
  beforeAll(() => {
    setToken(TEST_AUTH_OBJECT_FISKER);
  });

  it("makes request to cancel an update", async () => {
    const api = jest.spyOn(updatesAPI, "cancelCarUpdate");
    const ref = React.createRef();

    render(
      <StatusProvider>
        <UserProvider>
          <Cancel
            ref={ref}
            ids={["1", "2", "3"]}
            idCSV=""
          />
        </UserProvider>
      </StatusProvider>
    );

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