UNPKG

@enact/sandstone

Version:

Large-screen/TV support library for Enact, containing a variety of UI components.

131 lines (129 loc) 5.1 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _Icon = require("../Icon"); var _jsxRuntime = require("react/jsx-runtime"); describe('Icon Specs', function () { test('should return the correct Unicode value for named icon \'star\'', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: "star" })); var expected = 983080; // decimal converted charCode of Unicode 'star' character var actual = _react.screen.getByTestId('icon').textContent.codePointAt(); expect(actual).toBe(expected); }); test('should return the correct Unicode value when provided \'star\' hex value', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: "0x0F0028" })); var expected = 983080; // decimal converted charCode of character var actual = _react.screen.getByTestId('icon').textContent.codePointAt(); expect(actual).toBe(expected); }); test('should return the correct Unicode value when provided HTML entity as hex value', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: "\u2605" })); var expected = 9733; // decimal converted charCode of character var actual = _react.screen.getByTestId('icon').textContent.codePointAt(); expect(actual).toBe(expected); }); test('should return the correct Unicode value when provided Unicode reference', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: "\\u0F0028" })); var expected = 983080; // decimal converted charCode of Unicode 'star' character var actual = _react.screen.getByTestId('icon').textContent.codePointAt(); expect(actual).toBe(expected); }); test('should support high code point Unicode values', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", children: String.fromCodePoint(0x0F0028) })); var expected = 983080; // decimal converted charCode of Unicode 'star' character var actual = _react.screen.getByTestId('icon').textContent.codePointAt(); expect(actual).toBe(expected); }); test('should support preset size "large"', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", size: "large", children: "star" })); var expected = 'large'; var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveClass(expected); }); test('should support preset size "medium"', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", size: "medium", children: "star" })); var expected = 'medium'; var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveClass(expected); }); test('should support preset size "small"', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", size: "small", children: "star" })); var expected = 'small'; var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveClass(expected); }); test('should support preset size "tiny"', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", size: "tiny", children: "star" })); var expected = 'tiny'; var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveClass(expected); }); test('should support arbitrary custom numeric sizes that scale to the correct value', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", size: 96, children: "star" })); var icon = _react.screen.getByTestId('icon'); // surprisingly this returns 8rem, instead of what you'd expect // with a base pxToRem value of 48px, which would be 2rem. // Tests must run at a tiny simulated screen size. expect(icon).toHaveStyle({ '--icon-size': '8rem' }); }); test('should support RTL flip', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", rtl: true, flip: "auto", children: "star" })); var expected = "flipHorizontal"; var icon = _react.screen.getByTestId('icon'); expect(icon).toHaveClass(expected); }); test('should not support RTL flip when locale is he-IL and children is \'help\'', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.IconBase, { "data-testid": "icon", rtl: true, flip: "auto", locale: "he-IL", children: "help" })); var expected = "flipHorizontal"; var icon = _react.screen.getByTestId('icon'); expect(icon).not.toHaveClass(expected); }); });