UNPKG

@enact/ui

Version:

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

115 lines (114 loc) 4.65 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _Icon = _interopRequireWildcard(require("../Icon")); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } describe('Icon', function () { test('should allow icon-name words to pass through', function () { var iconName = 'hollow_star'; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: iconName })); var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveTextContent(iconName); }); test('should allow single-byte characters to pass through', function () { var iconName = '+'; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: iconName })); var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveTextContent(iconName); }); test('should allow multi-byte characters to pass through', function () { var iconName = '󰂪'; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: iconName })); var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveTextContent(iconName); }); test('should allow pre-defined icon names as an icon', function () { var iconName = 'factory'; var iconGlyph = 'F'; var iconList = { train: 'T', factory: 'F' }; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", iconList: iconList, children: iconName })); var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveTextContent(iconGlyph); }); test('should allow un-matched icon names to fall through, even when pre-defined icons exist', function () { var iconName = 'custom-icon-word'; var iconList = { train: 'T', factory: 'F' }; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", iconList: iconList, children: iconName })); var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveTextContent(iconName); }); test('should allow URIs to be used as an icon', function () { var src = 'images/icon.png'; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: src })); var icon = _react.screen.getByTestId('icon'); var expected = { backgroundImage: "url(".concat(src, ")") }; expect(icon).toHaveStyle(expected); }); test('should allow URLs to be used as an icon', function () { var src = 'http://enactjs.com/images/logo'; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: src })); var icon = _react.screen.getByTestId('icon'); var expected = { backgroundImage: "url(".concat(src, ")") }; expect(icon).toHaveStyle(expected); }); test('should merge author styles with image URLs', function () { var src = 'images/icon.png'; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", style: { color: 'green' }, children: src })); var icon = _react.screen.getByTestId('icon'); var expected = { color: 'green', backgroundImage: "url(".concat(src, ")") }; expect(icon).toHaveStyle(expected); }); test('should return a DOM node reference for `componentRef`', function () { var ref = jest.fn(); (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], { ref: ref })); var expected = 'DIV'; var actual = ref.mock.calls[0][0].nodeName; expect(actual).toBe(expected); }); });