"use strict";

var _jsxRuntime = require("react/jsx-runtime");

var _enzyme = require("enzyme");

var _Keypad = _interopRequireDefault(require("../Keypad"));

var _KeypadModule = _interopRequireDefault(require("../Keypad.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var click = function click(key, value) {
  return key.find(".".concat(_KeypadModule["default"].button, "[aria-label=\"").concat(value, "\"]")).simulate('click');
};

describe('Keypad Specs', function () {
  test('should add new digits on every digit click', function () {
    var handleChange = jest.fn();
    var keypad = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
      onChange: handleChange
    }));
    click(keypad, 2);
    click(keypad, 5);
    click(keypad, 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', function () {
    var handleChange = jest.fn();
    var keypad = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
      onChange: handleChange
    }));
    click(keypad, 2);
    click(keypad, 5);
    click(keypad, 7);
    click(keypad, 'backspace');
    var expected = '25';
    var actual = handleChange.mock.calls[3][0].value;
    expect(actual).toBe(expected);
  });
  describe('Disabled Keypad', function () {
    test('should not run the onChange handler when disabled', function () {
      var handleChange = jest.fn();
      var keypad = (0, _enzyme.mount)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Keypad["default"], {
        disabled: true,
        onChange: handleChange
      }));
      click(keypad, 2);
      click(keypad, 5);
      click(keypad, 7);
      var expected = 0;
      var actual = handleChange.mock.calls.length;
      expect(actual).toBe(expected);
    });
  });
});