/**
 * TEAM: frontend_infra
 *
 * @flow
 */

// TODO: Fix this eslint issue on next edit. This is an autogenerated comment.
// eslint-disable-next-line flexport/no-legacy-dependencies
import {shallow} from "enzyme";
import DocumentUploader from "../DocumentUploader";

describe("DocumentUploader", () => {
  it("renders", () => {
    expect(
      shallow(
        <DocumentUploader
          document={null}
          onChange={() => {}}
          serverState="waiting"
          fileAllowList={["application/pdf"]}
        />
      )
    ).toMatchSnapshot();
  });

  it("renders a delete button when canDeleteDocument is true", () => {
    const file = new File(["foo"], "foo.pdf", {
      type: "application/pdf",
    });
    const component = shallow(
      <DocumentUploader
        canDeleteDocument={true}
        document={file}
        onChange={() => {}}
        serverState="waiting"
        fileAllowList={["application/pdf"]}
      />
    );
    expect(
      component.find("Button").findWhere(n => n.text().includes("Delete"))
    ).toHaveLength(1);
  });

  it("does not render a delete button when canDeleteDocument is false", () => {
    const file = new File(["foo"], "foo.pdf", {
      type: "application/pdf",
    });
    const component = shallow(
      <DocumentUploader
        canDeleteDocument={false}
        document={file}
        onChange={() => {}}
        serverState="waiting"
        fileAllowList={["application/pdf"]}
      />
    );
    expect(
      component.find("Button").findWhere(n => n.text().includes("Delete"))
    ).toHaveLength(0);
  });
});
