"use strict";

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("enzyme");

var _enzymeToJson = require("enzyme-to-json");

var _index = _interopRequireDefault(require("../index"));

var _Button = _interopRequireDefault(require("../../Button"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

jest.mock("copy-to-clipboard", function () {
  return jest.fn();
});
describe("components/CopyButton", function () {
  it("should render children the icon button", function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      textToCopy: 'let bingo = "BINGO"',
      testSection: "fake-test-section"
    }));
    expect((0, _enzymeToJson.shallowToJson)(component)).toMatchSnapshot();
  });
  it("should render default text when usesTextLabel is true", function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      textToCopy: 'let bingo = "BINGO"',
      testSection: "fake-test-section",
      usesTextLabel: true,
      style: "highlight"
    }));
    expect((0, _enzymeToJson.shallowToJson)(component)).toMatchSnapshot();
  });
  it("should render provided text when usesTextLabel is true and textLabel is given", function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      textToCopy: 'let bingo = "BINGO"',
      testSection: "fake-test-section",
      usesTextLabel: true,
      textLabel: "custom-copy-label",
      style: "highlight"
    }));
    expect((0, _enzymeToJson.shallowToJson)(component)).toMatchSnapshot();
  });
  it("should call onCopy callback when CopyButton is clicked", function () {
    var mockFunction = jest.fn();
    var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
      textToCopy: 'let bingo = "BINGO"',
      usesTextLabel: true,
      testSection: "fake-test-section",
      onCopy: mockFunction,
      style: "highlight"
    }));
    var button = component.find("CopyToClipboard");
    button.simulate("click");
    expect(mockFunction).toHaveBeenCalled();
  });
  describe("when given a className", function () {
    it("appends it to the button element", function () {
      var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
        className: "extra-class",
        textToCopy: "Text"
      }));
      expect(component.find(_Button["default"]).prop("className").includes("extra-class")).toBe(true);
    });
  });
  describe("when given an unknown prop", function () {
    it("passes it to the button element", function () {
      // @ts-ignore: `unknownProps` is not part of any typed interface and therefore a good test value.
      var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
        unknownProp: "some value",
        textToCopy: "Text"
      }));
      expect(component.find(_Button["default"])).toHaveProp({
        unknownProp: "some value"
      });
    });
  });
});