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

import React, { useState } 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 SendSMS from "./SendSMS";
import vehiclesAPI from "../../../services/vehiclesAPI";
import smsAPI from "../../../services/smsAPI";

jest.mock('react', () => ({
  ...jest.requireActual('react'),
  useState: jest.fn(),
}));

jest.mock('@material-ui/core/FormControlLabel', () => {
  const React = require('react');
  return () => <div data-testid="mock-form-control-label" />;
});

jest.mock('@material-ui/core/TextField', () => {
  const React = require('react');
  return () => <div data-testid="mock-text-field" />;
});

jest.mock('@material-ui/core/Checkbox', () => {
  const React = require('react');
  return () => <div data-testid="mock-checkbox" />;
});

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

  it("makes request to send multiple SMS messages", async () => {
    useState
      .mockReturnValueOnce([true, jest.fn()])
      .mockReturnValueOnce(["body", jest.fn()]);
    const vehiclesAPIMock = jest.spyOn(vehiclesAPI, "getVehicle");
    const smsAPIMock = jest.spyOn(smsAPI, "send");
    const ref = React.createRef();

    render(
      <StatusProvider>
        <UserProvider>
          <SendSMS
            ref={ref}
            ids={["3C4PDCBG0ET127145"]}
            idCSV=""
          />
        </UserProvider>
      </StatusProvider>
    );

    await act(async () => ref.current.submit());
    expect(vehiclesAPIMock).toHaveBeenCalledTimes(1);
    expect(smsAPIMock).toHaveBeenCalledTimes(1);
  });
});
