import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import Image from '../index';
var src = 'src="https://camo.githubusercontent.com/f5847256d81e5f8c31aee6554f749baf64654a131fed0fca987bd39e023a690f/68747470733a2f2f7a61726d2e64657369676e2f696d616765732f6c6f676f2e31613663666333302e737667"';
describe('Image', function () {
  it('render correctly', function () {
    var _render = render( /*#__PURE__*/React.createElement(Image, {
      src: src
    })),
        asFragment = _render.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('width', function () {
    var _render2 = render( /*#__PURE__*/React.createElement(Image, {
      src: src,
      width: 50
    })),
        asFragment = _render2.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('height', function () {
    var _render3 = render( /*#__PURE__*/React.createElement(Image, {
      src: src,
      height: 40
    })),
        asFragment = _render3.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('placeholder', function () {
    var _render4 = render( /*#__PURE__*/React.createElement(Image, {
      src: src,
      placeholder: "loading"
    })),
        asFragment = _render4.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('alt', function () {
    var _render5 = render( /*#__PURE__*/React.createElement(Image, {
      src: src,
      alt: "image"
    })),
        asFragment = _render5.asFragment;

    expect(asFragment()).toMatchSnapshot();
  });
  it('shape', function () {
    var _render6 = render( /*#__PURE__*/React.createElement(Image, {
      src: src,
      shape: "circle"
    })),
        asFragment = _render6.asFragment;

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

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

    expect(asFragment()).toMatchSnapshot();
  });
  it('onLoad', function () {
    var onLoad = jest.fn();
    render( /*#__PURE__*/React.createElement(Image, {
      src: src,
      alt: "test-img",
      onLoad: onLoad
    }));
    var img = screen.getByAltText('test-img');
    fireEvent.load(img);
    expect(onLoad).toHaveBeenCalled();
  });
  it('onError', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var onError, img;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            onError = jest.fn();
            render( /*#__PURE__*/React.createElement(Image, {
              src: "xx",
              alt: "test-img",
              fallback: false,
              placeholder: false,
              onError: onError
            }));
            img = screen.getByAltText('test-img');
            fireEvent.error(img);
            expect(onError).toHaveBeenCalled();

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