UNPKG

@enact/ui

Version:

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

68 lines (67 loc) 2.61 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _LabeledIcon = _interopRequireDefault(require("../LabeledIcon")); var _Icon = _interopRequireDefault(require("../../Icon")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } var iconName = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { "data-testid": "iconName", children: "anIconName" }); var iconLabel = 'A real label'; var iconComponent = function iconComponent(_ref) { var children = _ref.children; return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", { children: children }); }; describe('LabeledIcon Specs', function () { test('should insert the icon source into the icon when using the prop approach', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_LabeledIcon["default"], { icon: iconName, iconComponent: iconComponent, children: iconLabel })); var icon = _react.screen.getByTestId('iconName'); var expected = 'anIconName'; expect(icon).toHaveClass('icon'); expect(icon.textContent).toBe(expected); }); test('should insert the icon source into the icon slot element', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_LabeledIcon["default"], { iconComponent: iconComponent, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("icon", { children: iconName }), iconLabel] })); var icon = _react.screen.getByTestId('iconName'); var expected = 'anIconName'; expect(icon).toHaveClass('icon'); expect(icon.textContent).toBe(expected); }); test('should insert custom icon components into the icon slot', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsxs)(_LabeledIcon["default"], { iconComponent: iconComponent, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("icon", { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], { "data-testid": "customIcon", children: iconName }) }), iconLabel] })); var customIcon = _react.screen.getByTestId('customIcon'); expect(customIcon).toBeInTheDocument(); }); test('should return a DOM node reference for `componentRef`', function () { var ref = jest.fn(); (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_LabeledIcon["default"], { icon: iconName, iconComponent: iconComponent, ref: ref })); var expected = 'DIV'; var actual = ref.mock.calls[0][0].nodeName; expect(actual).toBe(expected); }); });