UNPKG

@wix/design-system

Version:

@wix/design-system

545 lines 21.3 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _extends from "@babel/runtime/helpers/extends"; var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/ComposerHeader/test/ComposerHeader.spec.jsx", _this = this; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React from 'react'; import { createRendererWithUniDriver, cleanup } from '../../utils/test-utils/unit'; import ComposerHeader from '../ComposerHeader'; import { composerHeaderPrivateDriverFactory } from './ComposerHeader.private.uni.driver'; var generateComposer = function generateComposer(props) { return /*#__PURE__*/React.createElement(ComposerHeader, _extends({}, props, { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 10, columnNumber: 35 } })); }; var generateActions = function generateActions(props) { return /*#__PURE__*/React.createElement(ComposerHeader.Actions, _extends({}, props, { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 12, columnNumber: 34 } })); }; var generateMainActions = function generateMainActions(props) { return /*#__PURE__*/React.createElement(ComposerHeader.MainActions, _extends({}, props, { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 14, columnNumber: 38 } })); }; var generateSaveStatus = function generateSaveStatus(props) { return /*#__PURE__*/React.createElement(ComposerHeader.SaveStatus, _extends({}, props, { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 16, columnNumber: 37 } })); }; describe('ComposerHeader', function () { var render = createRendererWithUniDriver(composerHeaderPrivateDriverFactory); afterEach(function () { cleanup(); }); it('should render', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var _render, driver; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _render = render(generateComposer()), driver = _render.driver; _context.t0 = expect; _context.next = 4; return driver.exists(); case 4: _context.t1 = _context.sent; (0, _context.t0)(_context.t1).toBe(true); case 6: case "end": return _context.stop(); } }, _callee); }))); describe('Composer.Actions', function () { it('should render [when] given Composer.Actions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var children, _render2, driver; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: children = generateActions({ dataHook: 'random', children: 'random' }); _render2 = render(generateComposer({ children: children })), driver = _render2.driver; _context2.t0 = expect; _context2.next = 5; return driver.actionsExists('random'); case 5: _context2.t1 = _context2.sent; (0, _context2.t0)(_context2.t1).toBe(true); case 7: case "end": return _context2.stop(); } }, _callee2); }))); it('should render [when] given multiple Composer.Actions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var children, _render3, driver; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: children = [generateActions({ dataHook: 'random', children: 'random', key: 1 }), generateActions({ dataHook: 'random2', children: 'random2', key: 2 })]; _render3 = render(generateComposer({ children: children })), driver = _render3.driver; _context3.t0 = expect; _context3.next = 5; return driver.actionsExists('random'); case 5: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toBe(true); _context3.t2 = expect; _context3.next = 10; return driver.actionsExists('random2'); case 10: _context3.t3 = _context3.sent; (0, _context3.t2)(_context3.t3).toBe(true); case 12: case "end": return _context3.stop(); } }, _callee3); }))); }); describe('Composer.MainActions', function () { it('should render [when] given Composer.MainActions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { var children, _render4, driver; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: children = generateMainActions({}); _render4 = render(generateComposer({ children: children })), driver = _render4.driver; _context4.t0 = expect; _context4.next = 5; return driver.mainActionsExists(); case 5: _context4.t1 = _context4.sent; (0, _context4.t0)(_context4.t1).toBe(true); case 7: case "end": return _context4.stop(); } }, _callee4); }))); it('should render only first in the list [when] given multiple Composer.MainActions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { var children, _render5, driver; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: children = [generateMainActions({ dataHook: 'random1', key: 1 }), generateMainActions({ key: 2 })]; _render5 = render(generateComposer({ children: children })), driver = _render5.driver; _context5.t0 = expect; _context5.next = 5; return driver.mainActionsExists('random1'); case 5: _context5.t1 = _context5.sent; (0, _context5.t0)(_context5.t1).toBe(true); case 7: case "end": return _context5.stop(); } }, _callee5); }))); }); describe('Composer.SaveStatus', function () { it('should render [when] given Composer.SaveStatus ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { var children, _render6, driver; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: children = generateActions({ children: generateSaveStatus({ dataHook: 'random', saveStatusValue: 'back' }) }); _render6 = render(generateComposer({ children: children })), driver = _render6.driver; _context6.t0 = expect; _context6.next = 5; return driver.saveStatusExists('random'); case 5: _context6.t1 = _context6.sent; (0, _context6.t0)(_context6.t1).toBe(true); case 7: case "end": return _context6.stop(); } }, _callee6); }))); it('should render status [when] given saveStatusValue ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() { var children, _render7, driver; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: children = generateActions({ children: generateSaveStatus({ dataHook: 'random', saveStatusValue: 'back' }) }); _render7 = render(generateComposer({ children: children })), driver = _render7.driver; _context7.t0 = expect; _context7.next = 5; return driver.getSaveStatusValue('random'); case 5: _context7.t1 = _context7.sent; (0, _context7.t0)(_context7.t1).toBe('back'); case 7: case "end": return _context7.stop(); } }, _callee7); }))); }); describe('Back Button', function () { it('should render [when] given `backButtonValue`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() { var _render8, driver; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: _render8 = render(generateComposer({ backButtonValue: 'back' })), driver = _render8.driver; _context8.t0 = expect; _context8.next = 4; return driver.backButtonExists(); case 4: _context8.t1 = _context8.sent; (0, _context8.t0)(_context8.t1).toBe(true); case 6: case "end": return _context8.stop(); } }, _callee8); }))); it('should render text value [when] given `backButtonValue`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { var _render9, driver; return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: _render9 = render(generateComposer({ backButtonValue: 'back' })), driver = _render9.driver; _context9.t0 = expect; _context9.next = 4; return driver.getBackButtonText(); case 4: _context9.t1 = _context9.sent; (0, _context9.t0)(_context9.t1).toEqual('back'); case 6: case "end": return _context9.stop(); } }, _callee9); }))); it('should trigger onBackClick [when] given back button clicked ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() { var onBackClick, _render0, driver; return _regeneratorRuntime.wrap(function _callee0$(_context0) { while (1) switch (_context0.prev = _context0.next) { case 0: onBackClick = vi.fn(); _render0 = render(generateComposer({ backButtonValue: 'back', onBackClick: onBackClick })), driver = _render0.driver; _context0.next = 4; return driver.clickBack(); case 4: expect(onBackClick).toHaveBeenCalled(); case 5: case "end": return _context0.stop(); } }, _callee0); }))); }); describe('Left Divider', function () { it('should render [when] back button && first item with justifyContent=flex-start', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() { var children, backButtonValue, _render1, driver; return _regeneratorRuntime.wrap(function _callee1$(_context1) { while (1) switch (_context1.prev = _context1.next) { case 0: children = generateActions({ justifyContent: 'flex-start' }); backButtonValue = 'back'; _render1 = render(generateComposer({ backButtonValue: backButtonValue, children: children })), driver = _render1.driver; _context1.t0 = expect; _context1.next = 6; return driver.isLeftDividerExists(); case 6: _context1.t1 = _context1.sent; (0, _context1.t0)(_context1.t1).toBe(true); case 8: case "end": return _context1.stop(); } }, _callee1); }))); it('should render [when] back button && multiple items Composer.Actions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() { var children, backButtonValue, _render10, driver; return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) switch (_context10.prev = _context10.next) { case 0: children = [generateActions({ justifyContent: 'flex-start', key: 0 }), generateActions({ justifyContent: 'flex-end', key: 1 })]; backButtonValue = 'back'; _render10 = render(generateComposer({ backButtonValue: backButtonValue, children: children })), driver = _render10.driver; _context10.t0 = expect; _context10.next = 6; return driver.isLeftDividerExists(); case 6: _context10.t1 = _context10.sent; (0, _context10.t0)(_context10.t1).toBe(true); case 8: case "end": return _context10.stop(); } }, _callee10); }))); it('should not render [when] back button && first item with justifyContent=flex-end', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() { var children, backButtonValue, _render11, driver; return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) switch (_context11.prev = _context11.next) { case 0: children = generateActions({ justifyContent: 'flex-end' }); backButtonValue = 'back'; _render11 = render(generateComposer({ backButtonValue: backButtonValue, children: children })), driver = _render11.driver; _context11.t0 = expect; _context11.next = 6; return driver.isLeftDividerExists(); case 6: _context11.t1 = _context11.sent; (0, _context11.t0)(_context11.t1).toBe(false); case 8: case "end": return _context11.stop(); } }, _callee11); }))); it('is hidden [when] back button is disabled', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() { var children, _render12, driver; return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) switch (_context12.prev = _context12.next) { case 0: children = generateActions({ justifyContent: 'flex-start' }); _render12 = render(generateComposer({ children: children })), driver = _render12.driver; _context12.t0 = expect; _context12.next = 5; return driver.isLeftDividerExists(); case 5: _context12.t1 = _context12.sent; (0, _context12.t0)(_context12.t1).toBe(false); case 7: case "end": return _context12.stop(); } }, _callee12); }))); it('is hidden [when] no Composer.Actions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() { var _render13, driver; return _regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) switch (_context13.prev = _context13.next) { case 0: _render13 = render(generateComposer()), driver = _render13.driver; _context13.t0 = expect; _context13.next = 4; return driver.isLeftDividerExists(); case 4: _context13.t1 = _context13.sent; (0, _context13.t0)(_context13.t1).toBe(false); case 6: case "end": return _context13.stop(); } }, _callee13); }))); }); describe('Right Divider', function () { it('should render [when] mainActions && last item with justifyContent=flex-end', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14() { var children, _render14, driver; return _regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) switch (_context14.prev = _context14.next) { case 0: children = [generateActions({ justifyContent: 'flex-end', key: 1 }), generateMainActions({ key: 2 })]; _render14 = render(generateComposer({ children: children })), driver = _render14.driver; _context14.t0 = expect; _context14.next = 5; return driver.isRightDividerExists(); case 5: _context14.t1 = _context14.sent; (0, _context14.t0)(_context14.t1).toBe(true); case 7: case "end": return _context14.stop(); } }, _callee14); }))); it('should render [when] mainActions && multiple items Composer.Actions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee15() { var children, _render15, driver; return _regeneratorRuntime.wrap(function _callee15$(_context15) { while (1) switch (_context15.prev = _context15.next) { case 0: children = [generateActions({ justifyContent: 'flex-start', key: 0 }), generateActions({ justifyContent: 'flex-end', key: 1 }), generateMainActions({ key: 2 })]; _render15 = render(generateComposer({ children: children })), driver = _render15.driver; _context15.t0 = expect; _context15.next = 5; return driver.isRightDividerExists(); case 5: _context15.t1 = _context15.sent; (0, _context15.t0)(_context15.t1).toBe(true); case 7: case "end": return _context15.stop(); } }, _callee15); }))); it('should not render [when] mainActions && last item with justifyContent=flex-start', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee16() { var children, _render16, driver; return _regeneratorRuntime.wrap(function _callee16$(_context16) { while (1) switch (_context16.prev = _context16.next) { case 0: children = [generateActions({ justifyContent: 'flex-start', key: 0 }), generateMainActions({ key: 1 })]; _render16 = render(generateComposer({ children: children })), driver = _render16.driver; _context16.t0 = expect; _context16.next = 5; return driver.isRightDividerExists(); case 5: _context16.t1 = _context16.sent; (0, _context16.t0)(_context16.t1).toBe(false); case 7: case "end": return _context16.stop(); } }, _callee16); }))); it('is hidden [when] mainActions are not given ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee17() { var children, _render17, driver; return _regeneratorRuntime.wrap(function _callee17$(_context17) { while (1) switch (_context17.prev = _context17.next) { case 0: children = generateActions({ justifyContent: 'flex-end' }); _render17 = render(generateComposer({ children: children })), driver = _render17.driver; _context17.t0 = expect; _context17.next = 5; return driver.isRightDividerExists(); case 5: _context17.t1 = _context17.sent; (0, _context17.t0)(_context17.t1).toBe(false); case 7: case "end": return _context17.stop(); } }, _callee17); }))); it('is hidden [when] no Composer.Actions', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee18() { var _render18, driver; return _regeneratorRuntime.wrap(function _callee18$(_context18) { while (1) switch (_context18.prev = _context18.next) { case 0: _render18 = render(generateComposer()), driver = _render18.driver; _context18.t0 = expect; _context18.next = 4; return driver.isRightDividerExists(); case 4: _context18.t1 = _context18.sent; (0, _context18.t0)(_context18.t1).toBe(false); case 6: case "end": return _context18.stop(); } }, _callee18); }))); }); });