UNPKG

wix-style-react

Version:
350 lines (302 loc) • 11.9 kB
var _this = this; function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } import React from 'react'; import CardGalleryItem from '.'; import { createUniDriverFactory } from 'wix-ui-test-utils/uni-driver-factory'; import cardGalleryItemDriverFactory from './CardGalleryItem.driver'; import ReactTestUtils from 'react-dom/test-utils'; var hover = function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(driver) { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.t0 = ReactTestUtils.SimulateNative; _context.next = 3; return driver.getHoverComponent().getNative(); case 3: _context.t1 = _context.sent; return _context.abrupt('return', _context.t0.mouseOver.call(_context.t0, _context.t1)); case 5: case 'end': return _context.stop(); } } }, _callee, _this); })); return function hover(_x) { return _ref.apply(this, arguments); }; }(); describe('CardGalleryItem', function () { var createDriver = createUniDriverFactory(cardGalleryItemDriverFactory); it('should exist', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { var driver; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, null)); _context2.t0 = expect; _context2.next = 4; return driver.exists(); case 4: _context2.t1 = _context2.sent; (0, _context2.t0)(_context2.t1).toBeTruthy(); case 6: case 'end': return _context2.stop(); } } }, _callee2, _this); }))); it('should render title', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { var driver; return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, { title: 'Card' })); _context3.t0 = expect; _context3.next = 4; return driver.getTitle(); case 4: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toBe('Card'); case 6: case 'end': return _context3.stop(); } } }, _callee3, _this); }))); it('should render subtitle', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { var driver; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, { subtitle: 'Subtitle' })); _context4.t0 = expect; _context4.next = 4; return driver.getSubtitle(); case 4: _context4.t1 = _context4.sent; (0, _context4.t0)(_context4.t1).toBe('Subtitle'); case 6: case 'end': return _context4.stop(); } } }, _callee4, _this); }))); it('should set background image', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { var driver; return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, { backgroundImageUrl: 'http://test.com/img.png' })); _context5.t0 = expect; _context5.next = 4; return driver.getBackgroundImageUrl(); case 4: _context5.t1 = _context5.sent; (0, _context5.t0)(_context5.t1).toBe('http://test.com/img.png'); case 6: case 'end': return _context5.stop(); } } }, _callee5, _this); }))); it('should not render hovered content', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { var driver; return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, null)); _context6.t0 = expect; _context6.next = 4; return driver.getHoveredContent().exists(); case 4: _context6.t1 = _context6.sent; (0, _context6.t0)(_context6.t1).toBeFalsy(); case 6: case 'end': return _context6.stop(); } } }, _callee6, _this); }))); describe('on hover', function () { it('should render hovered content', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { var driver; return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, null)); _context7.next = 3; return hover(driver); case 3: _context7.t0 = expect; _context7.next = 6; return driver.getHoveredContent().exists(); case 6: _context7.t1 = _context7.sent; (0, _context7.t0)(_context7.t1).toBeTruthy(); case 8: case 'end': return _context7.stop(); } } }, _callee7, _this); }))); it('on click on card should call once only primary action', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() { var primaryActionOnClick, secondaryActionOnClick, driver; return regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: primaryActionOnClick = jest.fn(); secondaryActionOnClick = jest.fn(); driver = createDriver(React.createElement(CardGalleryItem, { primaryActionProps: { onClick: primaryActionOnClick }, secondaryActionProps: { onClick: secondaryActionOnClick } })); _context8.next = 5; return driver.click(); case 5: expect(primaryActionOnClick).toHaveBeenCalledTimes(1); expect(secondaryActionOnClick).not.toHaveBeenCalled(); case 7: case 'end': return _context8.stop(); } } }, _callee8, _this); }))); it('should render primary button label', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() { var driver; return regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, { primaryActionProps: { label: 'Primary' } })); _context9.next = 3; return hover(driver); case 3: _context9.t0 = expect; _context9.next = 6; return driver.getPrimaryActionLabel(); case 6: _context9.t1 = _context9.sent; (0, _context9.t0)(_context9.t1).toBe('Primary'); case 8: case 'end': return _context9.stop(); } } }, _callee9, _this); }))); it('on click on primary button should call once only primary action', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() { var primaryActionOnClick, secondaryActionOnClick, driver; return regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: primaryActionOnClick = jest.fn(); secondaryActionOnClick = jest.fn(); driver = createDriver(React.createElement(CardGalleryItem, { primaryActionProps: { onClick: primaryActionOnClick }, secondaryActionProps: { onClick: secondaryActionOnClick } })); _context10.next = 5; return hover(driver); case 5: _context10.next = 7; return driver.clickOnPrimaryAction(); case 7: expect(primaryActionOnClick).toHaveBeenCalledTimes(1); expect(secondaryActionOnClick).not.toHaveBeenCalled(); case 9: case 'end': return _context10.stop(); } } }, _callee10, _this); }))); it('should render secondary button label', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() { var driver; return regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: driver = createDriver(React.createElement(CardGalleryItem, { secondaryActionProps: { label: 'Secondary' } })); _context11.next = 3; return hover(driver); case 3: _context11.t0 = expect; _context11.next = 6; return driver.getSecondaryActionLabel(); case 6: _context11.t1 = _context11.sent; (0, _context11.t0)(_context11.t1).toBe('Secondary'); case 8: case 'end': return _context11.stop(); } } }, _callee11, _this); }))); it('on click on primary button should call once only secondary action', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() { var primaryActionOnClick, secondaryActionOnClick, driver; return regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: primaryActionOnClick = jest.fn(); secondaryActionOnClick = jest.fn(); driver = createDriver(React.createElement(CardGalleryItem, { primaryActionProps: { onClick: primaryActionOnClick }, secondaryActionProps: { onClick: secondaryActionOnClick } })); _context12.next = 5; return hover(driver); case 5: _context12.next = 7; return driver.clickOnSecondaryAction(); case 7: expect(secondaryActionOnClick).toHaveBeenCalledTimes(1); expect(primaryActionOnClick).not.toHaveBeenCalled(); case 9: case 'end': return _context12.stop(); } } }, _callee12, _this); }))); }); });