UNPKG

@enact/sandstone

Version:

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

151 lines (150 loc) 6.61 kB
"use strict"; var _spotlight = _interopRequireDefault(require("@enact/spotlight")); require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _ = _interopRequireDefault(require("../")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } describe('ThemeDecorator', function () { var AppRoot = function AppRoot(props) { return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread({ "data-app": true }, props)); }; var a11yConfig = { "float": false, ri18n: false, ri: false, spotlight: false }; var A11yApp = (0, _["default"])(a11yConfig, AppRoot); test('should add base classes to wrapped component', function () { var config = { ri: false, i18n: false, spotlight: false, "float": false, overlay: false }; var App = (0, _["default"])(config, AppRoot); (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, { "data-testid": "app" })); _spotlight["default"].terminate(); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('neutral'); expect(appRoot).toHaveClass('bg'); }); test('should add author classes to wrapped component', function () { var config = { ri: false, i18n: false, spotlight: false, "float": false, overlay: false }; var App = (0, _["default"])(config, AppRoot); (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, { className: "author-class", "data-testid": "app" })); _spotlight["default"].terminate(); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('author-class'); }); test('should not add skin classname to wrapped component when float is enabled', function () { var config = { ri: false, i18n: false, spotlight: false, "float": true, overlay: false }; var App = (0, _["default"])(config, AppRoot); (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, { "data-testid": "app" })); _spotlight["default"].terminate(); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).not.toHaveClass('neutral'); }); test('should not add .bg class to wrapped component when overlay is enabled', function () { var config = { ri: false, i18n: false, spotlight: false, "float": false, overlay: true }; var App = (0, _["default"])(config, AppRoot); (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(App, { "data-testid": "app" })); _spotlight["default"].terminate(); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).not.toHaveClass('bg'); }); describe('AccessibilityDecorator', function () { test('should add the highContrast class if passing the highContrast prop of true', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(A11yApp, { "data-testid": "app", highContrast: true })); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('highContrast'); }); test('should add the largeText class if passing the textSize prop of `large`', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(A11yApp, { "data-testid": "app", textSize: "large" })); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('largeText'); }); test('should update the skinVariants based on the skinVariants prop', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(A11yApp, { "data-testid": "app", skinVariants: ['grayscale'] })); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('grayscale'); }); test('should add the largeText class when the type of the skinVariants prop is a string', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(A11yApp, { "data-testid": "app", textSize: "large", skinVariants: "grayscale" })); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('largeText'); expect(appRoot).toHaveClass('grayscale'); }); test('should add largeText class when the type of the skinVariants prop is an array', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(A11yApp, { "data-testid": "app", textSize: "large", skinVariants: ['grayscale'] })); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('largeText'); expect(appRoot).toHaveClass('grayscale'); }); test('should add largeText class when the type of the skinVariants prop is an object', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(A11yApp, { "data-testid": "app", textSize: "large", skinVariants: { grayscale: true } })); var appRoot = _react.screen.getByTestId('app'); expect(appRoot).toHaveClass('largeText'); expect(appRoot).toHaveClass('grayscale'); }); }); });