"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
var _Keypad = _interopRequireDefault(require("../Keypad"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
describe('Keypad Specs', function () {
  test('should add new digits on every digit click', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
      onChange: handleChange
    }));
    yield user.click(_react.screen.getByLabelText('2'));
    yield user.click(_react.screen.getByLabelText('5'));
    yield user.click(_react.screen.getByLabelText('7'));
    var expected = '257';
    var actual = handleChange.mock.calls[2][0].value;
    expect(actual).toBe(expected);
  }));
  test('should remove digits on every backspace button click', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
      onChange: handleChange
    }));
    yield user.click(_react.screen.getByLabelText('2'));
    yield user.click(_react.screen.getByLabelText('5'));
    yield user.click(_react.screen.getByLabelText('7'));
    yield user.click(_react.screen.getByLabelText('backspace'));
    var expected = '25';
    var actual = handleChange.mock.calls[3][0].value;
    expect(actual).toBe(expected);
  }));
  test('should reset the digits after pressing `phone` key', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleChange = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
      onChange: handleChange
    }));
    yield user.click(_react.screen.getByLabelText('2'));
    yield user.click(_react.screen.getByLabelText('5'));
    yield user.click(_react.screen.getByLabelText('7'));
    var expected1 = '257';
    var actual1 = handleChange.mock.calls[2][0].value;
    expect(actual1).toBe(expected1);
    yield user.click(_react.screen.getByLabelText('call'));
    var expected2 = '';
    var actual2 = handleChange.mock.calls[3][0].value;
    expect(actual2).toBe(expected2);
  }));
  describe('Disabled Keypad', function () {
    test('should not run the onChange handler when disabled', /*#__PURE__*/_asyncToGenerator(function* () {
      var handleChange = jest.fn();
      var user = _userEvent["default"].setup();
      (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
        disabled: true,
        onChange: handleChange
      }));
      yield user.click(_react.screen.getByLabelText('2'));
      yield user.click(_react.screen.getByLabelText('5'));
      yield user.click(_react.screen.getByLabelText('7'));
      expect(handleChange).not.toHaveBeenCalled();
    }));
  });
});