"use strict";

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

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

var _enzyme = require("enzyme");

var _Dropdown = _interopRequireDefault(require("../../Dropdown"));

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

/* eslint-disable no-console */
describe('components/Tile', function () {
  it('should render default, basic tile', function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Goose"
    }));
    expect(component.find('.oui-tile').containsMatchingElement(_react["default"].createElement("p", null, "Goose"))).toBe(true);
  });
  it('should render a description when provided', function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Goose",
      description: "Duck"
    }));
    expect(component.find('.oui-tile').containsMatchingElement(_react["default"].createElement("p", null, "Duck"))).toBe(true);
  });
  it('should render a button when onTileClick is provided', function () {
    var mockClickFunction = jest.fn();
    var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
      name: "Goose",
      description: "Duck",
      onTileClick: mockClickFunction
    }));
    expect(component.find('.oui-button').length).toBe(1);
  });
  it('should not render a button when onTileClick is not provided', function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Goose",
      description: "Duck"
    }));
    expect(component.find('.oui-button').length).toBe(0);
  });
  it('should call the function passed in for `onTileClick` when the main tile is clicked', function () {
    var mockClickFunction = jest.fn();
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction
    }));
    component.find('Button').simulate('click');
    expect(mockClickFunction).toHaveBeenCalled();
  });
  it('should call the function passed in for an action item when the button icon is clicked', function () {
    var mockClickFunction = jest.fn();
    var mockDeleteClick = jest.fn();
    var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      onDismiss: mockDeleteClick
    }));
    component.find('.oui-button-icon').simulate('click');
    expect(mockClickFunction).not.toHaveBeenCalled();
    expect(mockDeleteClick).toHaveBeenCalled();
  });
  it('should render the corresponding ButtonIcons when functions are passed in', function () {
    var mockClickFunction = jest.fn();
    var mockDeleteClick = jest.fn();
    var mockCopyClick = jest.fn();
    var mockEditClick = jest.fn();
    console.error = jest.fn();
    var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      onCopy: mockCopyClick,
      onDismiss: mockDeleteClick,
      onEdit: mockEditClick
    }));
    expect(component.find('.oui-button-icon').length).toBe(3);
  });
  it('should render the title in monospace when `usesMonospaceTitle` is true', function () {
    var mockClickFunction = jest.fn();
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      usesMonospaceName: true
    }));
    expect(component.find('.monospace').length).toBe(1);
  });
  it('should not render the drag handle when `isDraggable` is false', function () {
    var mockClickFunction = jest.fn();
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      isDraggable: false
    }));
    expect(component.find('.oui-tile__drag-handle').length).toBe(0);
  });
  it('should render the drag handle when `isDraggable` is true', function () {
    var mockClickFunction = jest.fn();
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      isDraggable: true
    }));
    expect(component.find('.oui-tile__drag-handle').length).toBe(1);
  });
  it('should render the error popover when `hasWarning` is true', function () {
    var mockClickFunction = jest.fn();
    var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      hasWarning: true,
      warningTitle: 'Test Warning',
      warningContent: ' Warning Content',
      testSection: "test-tile"
    }));
    expect(component.find('[data-test-section="test-tile-warning-popover"]').length).toBe(1);
  });
  it('should render a `status` when provided', function () {
    var component = (0, _enzyme.shallow)(_react["default"].createElement(_index["default"], {
      name: "Goose",
      description: "Duck",
      status: "Running"
    }));
    expect(component.find('.oui-tile').containsMatchingElement(_react["default"].createElement("p", null, "Running"))).toBe(true);
  });
  it('should render a dropdown menu when `dropdownItems` are passed in', function () {
    var mockClickFunction = jest.fn();
    var mockDropdownAFunction = jest.fn();
    var component = (0, _enzyme.mount)(_react["default"].createElement(_index["default"], {
      name: "Alpha",
      testSection: "test-tile",
      description: "ID:12345678",
      onTileClick: mockClickFunction,
      dropdownItems: [_react["default"].createElement(_Dropdown["default"].ListItem, {
        key: 2,
        removeBorderTop: true
      }, _react["default"].createElement(_Dropdown["default"].BlockLink, {
        onClick: mockDropdownAFunction,
        testSection: 'dropdown-block-link-duplicate'
      }, _react["default"].createElement(_Dropdown["default"].BlockLinkText, {
        text: 'Duplicate'
      })))]
    }));
    expect(component.find('.oui-button-icon').length).toBe(1);
    component.find('.oui-button-icon').simulate('click');
    expect(component.find('.oui-dropdown').length).toBe(1);
    expect(component.find('.oui-dropdown__item').length).toBe(1);
    component.find('[data-test-section="dropdown-block-link-duplicate"]').simulate('click');
    expect(mockDropdownAFunction).toHaveBeenCalledTimes(1);
  });
});