"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 _utils = require("../utils");

jest.useFakeTimers();
var District = [{
  value: '340000',
  label: '安徽省',
  children: [{
    value: '340800',
    label: '安庆市',
    children: [{
      value: '340803',
      label: '大观区',
      children: []
    }, {
      value: '340822',
      label: '怀宁县',
      children: []
    }, {
      value: '340882',
      label: '其它区',
      children: []
    }]
  }]
}, {
  value: '310000',
  label: '上海',
  children: [{
    value: '310100',
    label: '上海市',
    children: [{
      value: '310113',
      label: '宝山区',
      children: []
    }, {
      value: '310105',
      label: '长宁区',
      children: []
    }, {
      value: '310230',
      label: '崇明县',
      children: []
    }, {
      value: '310152',
      label: '川沙区',
      children: []
    }]
  }]
}];
describe('Cascader', function () {
  it('renders correctly', function () {
    var _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
      dataSource: District
    })),
        container = _render.container;

    expect(container).toMatchSnapshot();
  });
  it('basic usage', /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
    var onChange, _render2, container, currentValue, items;

    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            onChange = jest.fn();
            _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
              "data-testid": "root",
              defaultValue: [],
              value: [],
              dataSource: District,
              onChange: onChange
            })), container = _render2.container;

            _react2.fireEvent.click(_react2.screen.getAllByDisplayValue('340000')[0]);

            _context.next = 5;
            return _react2.screen.findByText('安庆市');

          case 5:
            expect(container).toMatchSnapshot();

            _react2.fireEvent.click(_react2.screen.getAllByDisplayValue('340800')[0]);

            _context.next = 9;
            return _react2.screen.findByText('大观区');

          case 9:
            expect(container).toMatchSnapshot();

            _react2.fireEvent.click(_react2.screen.getAllByDisplayValue('340803')[0]);

            expect(container).toMatchSnapshot();
            expect(onChange).toBeCalledTimes(3);
            currentValue = ['340000', '340800', '340803'];
            items = (0, _utils.parseItems)(District, currentValue);
            expect(onChange).toHaveBeenCalledWith(currentValue, items);

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