UNPKG

@enact/ui

Version:

A collection of simplified unstyled cross-platform UI components for Enact

88 lines (87 loc) 3.87 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _userEvent = _interopRequireDefault(require("@testing-library/user-event")); var _Item = _interopRequireDefault(require("../Item")); 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); }); }; } var tap = function tap(node) { _react.fireEvent.mouseDown(node); _react.fireEvent.mouseUp(node); }; describe('Item', function () { test('should render an item', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { children: "I am an item" })); var actual = _react.screen.getByText('I am an item'); expect(actual).toBeInTheDocument(); }); test('should render a disabled item', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { disabled: true, children: "I am a disabled item" })); var actual = _react.screen.getByText('I am a disabled item'); expect(actual).toHaveAttribute('disabled'); }); test('should render an inline item', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { inline: true, children: "I am an inline item" })); var actual = _react.screen.getByText('I am an inline item'); var expected = 'inline'; expect(actual).toHaveClass(expected); }); describe('events', function () { test('should call onTap when tapped', function () { var handleClick = jest.fn(); (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { onTap: handleClick, children: "I am a normal item" })); var item = _react.screen.getByText('I am a normal item'); tap(item); var expected = 1; expect(handleClick).toHaveBeenCalledTimes(expected); }); test('should not call onTap when tapped and disabled', function () { var handleClick = jest.fn(); (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { disabled: true, onTap: handleClick, children: "I am a disabled item" })); var item = _react.screen.getByText('I am a disabled item'); tap(item); expect(handleClick).not.toHaveBeenCalled(); }); test('should call onClick when clicked', /*#__PURE__*/_asyncToGenerator(function* () { var handleClick = jest.fn(); var user = _userEvent["default"].setup(); (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { onClick: handleClick, children: "I am a normal Item" })); var item = _react.screen.getByText('I am a normal Item'); yield user.click(item); var expected = 1; expect(handleClick).toHaveBeenCalledTimes(expected); })); test('should not call onClick when clicked and disabled', /*#__PURE__*/_asyncToGenerator(function* () { var handleClick = jest.fn(); var user = _userEvent["default"].setup(); (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Item["default"], { disabled: true, onClick: handleClick, children: "I am a disabled Item" })); var item = _react.screen.getByText('I am a disabled Item'); yield user.click(item); expect(handleClick).not.toHaveBeenCalled(); })); }); });