UNPKG

@enact/ui

Version:

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

89 lines (88 loc) 3.78 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _Card = _interopRequireWildcard(require("../Card")); 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); } var src = { 'hd': 'https://placehold.co/200x200/000000/ffffff/png', 'fhd': 'https://placehold.co/300x300/000000/ffffff/png', 'uhd': 'https://placehold.co/600x600/000000/ffffff/png' }; describe('Card', function () { test('should support `children` prop', function () { var children = 'children'; (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { src: src.hd, children: children })); var expected = children; var card = _react.screen.getByText(children); expect(card).toHaveTextContent(expected); }); test('should apply `.horizontal` when `orientation="horizontal"`', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { "data-testid": "card", orientation: "horizontal", src: src })); var expected = 'horizontal'; var card = _react.screen.getByTestId('card'); expect(card).toHaveClass(expected); }); test('should apply `.vertical` when `oreintation="vertical"`', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { "data-testid": "card", orientation: "vertical", src: src })); var expected = 'vertical'; var card = _react.screen.getByTestId('card'); expect(card).toHaveClass(expected); }); test('should apply `.selected` when `selected`', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { "data-testid": "card", selected: true, src: src })); var expected = 'selected'; var card = _react.screen.getByTestId('card'); expect(card).toHaveClass(expected); }); test('should apply `.captionOverlay` when `captionOverlay`', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { "data-testid": "card", captionOverlay: true, src: src })); var expected = 'captionOverlay'; var card = _react.screen.getByTestId('card'); expect(card).toHaveClass(expected); }); test('should support string for `src` prop', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { src: src.hd })); var expected = src.hd; var imgElement = _react.screen.getAllByRole('img')[1]; expect(imgElement).toHaveAttribute('src', expected); }); test('should support object for `src` prop', function () { (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.CardBase, { src: src })); var imgElementSrc = _react.screen.getAllByRole('img')[1]; expect(imgElementSrc).not.toBeNull(); }); test('should return a DOM node reference for `componentRef`', function () { var ref = jest.fn(); (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Card["default"], { ref: ref, src: src })); var expected = 'DIV'; var actual = ref.mock.calls[0][0].nodeName; expect(actual).toBe(expected); }); });