"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

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

var _react2 = require("@testing-library/react");

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

var src = 'src="https://camo.githubusercontent.com/f5847256d81e5f8c31aee6554f749baf64654a131fed0fca987bd39e023a690f/68747470733a2f2f7a61726d2e64657369676e2f696d616765732f6c6f676f2e31613663666333302e737667"';
describe('Image', function () {
  it('render correctly', function () {
    var _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src
    })),
        asFragment = _render.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('width', function () {
    var _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      width: 50
    })),
        asFragment = _render2.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('height', function () {
    var _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      height: 40
    })),
        asFragment = _render3.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('placeholder', function () {
    var _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      placeholder: "loading"
    })),
        asFragment = _render4.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('alt', function () {
    var _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      alt: "image"
    })),
        asFragment = _render5.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('shape', function () {
    var _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      shape: "circle"
    })),
        asFragment = _render6.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('fill', function () {
    var _render7 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      fit: "cover"
    })),
        asFragment = _render7.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('fallback', function () {
    var _render8 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      fallback: /*#__PURE__*/_react.default.createElement("span", null, "\u56FE\u7247\u4E0D\u89C1\u5566")
    })),
        asFragment = _render8.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('onLoad', function () {
    var onLoad = jest.fn();
    (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      src: src,
      alt: "test-img",
      onLoad: onLoad
    }));

    var img = _react2.screen.getByAltText('test-img');

    _react2.fireEvent.load(img);

    expect(onLoad).toHaveBeenCalled();
  });
  it('onError', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var onError, img;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            onError = jest.fn();
            (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
              src: "xx",
              alt: "test-img",
              fallback: false,
              placeholder: false,
              onError: onError
            }));
            img = _react2.screen.getByAltText('test-img');

            _react2.fireEvent.error(img);

            expect(onError).toHaveBeenCalled();

          case 5:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
});