UNPKG

@enact/ui

Version:

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

114 lines (113 loc) 4.46 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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } 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); }); });