"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

var React = _interopRequireWildcard(require("react"));

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

var _testUtils = require("react-dom/test-utils");

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

describe('WaterMark', function () {
  it('renders correctly', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
    return _regenerator.default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _context2.next = 2;
            return (0, _testUtils.act)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
              var _render, asFragment;

              return _regenerator.default.wrap(function _callee$(_context) {
                while (1) {
                  switch (_context.prev = _context.next) {
                    case 0:
                      _render = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
                        text: "\u4F17\u5B89\u79D1\u6280"
                      })), asFragment = _render.asFragment;
                      expect(asFragment()).toMatchSnapshot();

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

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  it('image watermark', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
    return _regenerator.default.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            _context4.next = 2;
            return (0, _testUtils.act)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
              var _render2, asFragment;

              return _regenerator.default.wrap(function _callee3$(_context3) {
                while (1) {
                  switch (_context3.prev = _context3.next) {
                    case 0:
                      _render2 = (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, {
                        image: "https://zarm.design/images/logo.1a6cfc30.svg"
                      })), asFragment = _render2.asFragment;
                      expect(asFragment()).toMatchSnapshot();

                    case 2:
                    case "end":
                      return _context3.stop();
                  }
                }
              }, _callee3);
            })));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  })));
  var originalError = console.error; // @ts-ignore
  // eslint-disable-next-line no-return-assign

  afterEach(function () {
    return console.error = originalError;
  });
  var consoleOutput = [];

  var mockedError = function mockedError(output) {
    consoleOutput.push(output);
  }; // eslint-disable-next-line no-return-assign


  beforeEach(function () {
    return console.error = mockedError;
  });
  it.only('canvas non-supported', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
    var mockCanvasContext;
    return _regenerator.default.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            mockCanvasContext = jest.spyOn(HTMLCanvasElement.prototype, 'getContext');
            mockCanvasContext.mockReturnValue(null);
            (0, _react2.render)( /*#__PURE__*/React.createElement(_index.default, null));
            _context5.next = 5;
            return (0, _react2.waitFor)(function () {
              expect(consoleOutput).toEqual(['当前环境不支持 Canvas']);
            });

          case 5:
            mockCanvasContext.mockRestore();

          case 6:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  })));
});