UNPKG

@wix/design-system

Version:

@wix/design-system

454 lines 17.4 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/Transition/test/Transition.spec.jsx", _this = this; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React from 'react'; import { createRendererWithUniDriver, cleanup, waitFor } from '../../utils/test-utils/unit'; import Transition from '../Transition'; import { transitionPrivateDriverFactory } from './Transition.private.uni.driver'; var createTransition = function createTransition() { var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return /*#__PURE__*/React.createElement(Transition, _extends({}, props, { dataHook: "transitionHook", __self: _this, __source: { fileName: _jsxFileName, lineNumber: 13, columnNumber: 5 } }), /*#__PURE__*/React.createElement("div", { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 14, columnNumber: 7 } }, "Children")); }; describe(Transition.displayName, function () { var fadeIn = { delay: 'long', duration: 'slow02', easing: 'enterEasing' }; var fadeOut = { delay: 'long', duration: 'slow02', easing: 'exitEasing' }; var moveIn = { delay: 'long', direction: 'topToBottom', distance: '10px', duration: 'slow02', easing: 'enterEasing' }; var moveOut = { delay: 'long', direction: 'topToBottom', distance: '10px', duration: 'slow02', easing: 'exitEasing' }; var expand = { delay: 'long', direction: 'topToBottom', duration: 'slow02', easing: 'enterEasing' }; var collapse = { delay: 'long', direction: 'topToBottom', duration: 'slow02', easing: 'exitEasing' }; var scaleUp = { delay: 'long', direction: 'bottom', scale: '100%', duration: 'slow02', easing: 'enterEasing' }; var scaleDown = { delay: 'long', direction: 'bottom', scale: '0%', duration: 'slow02', easing: 'exitEasing' }; var render = createRendererWithUniDriver(transitionPrivateDriverFactory); afterEach(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(createTransition()), 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); }))); it('should add fade styles', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var _render2, driver; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _render2 = render(createTransition({ enterAnimation: { fadeIn: fadeIn }, exitAnimation: { fadeOut: fadeOut }, animateOnLoad: true, show: true })), driver = _render2.driver; _context3.t0 = expect; _context3.next = 4; return driver.getFadeStyles(); case 4: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toEqual(['opacity: 0; transition-property: opacity; transition-duration: 600ms;']); _context3.next = 8; return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.t0 = expect; _context2.next = 3; return driver.getFadeStyles(); case 3: _context2.t1 = _context2.sent; (0, _context2.t0)(_context2.t1).toEqual(['opacity: 1; transition-property: opacity; transition-duration: 600ms; transition-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1); transition-delay: 200ms;']); case 5: case "end": return _context2.stop(); } }, _callee2); }))); case 8: case "end": return _context3.stop(); } }, _callee3); }))); it('should add move styles', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { var _render3, driver; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: _render3 = render(createTransition({ enterAnimation: { moveIn: moveIn }, exitAnimation: { moveOut: moveOut }, show: true, animateOnLoad: true })), driver = _render3.driver; _context5.t0 = expect; _context5.next = 4; return driver.getMoveStyles(); case 4: _context5.t1 = _context5.sent; (0, _context5.t0)(_context5.t1).toEqual(['transform: translateY(-10px); transition-property: transform; transition-duration: 600ms;']); _context5.next = 8; return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.t0 = expect; _context4.next = 3; return driver.getMoveStyles(); case 3: _context4.t1 = _context4.sent; (0, _context4.t0)(_context4.t1).toEqual(['transform: none; transition-property: transform; transition-duration: 600ms; transition-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1); transition-delay: 200ms;']); case 5: case "end": return _context4.stop(); } }, _callee4); }))); case 8: case "end": return _context5.stop(); } }, _callee5); }))); it('should add toggle styles', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() { var _render4, driver; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: _render4 = render(createTransition({ enterAnimation: { expand: expand }, exitAnimation: { collapse: collapse }, show: true, animateOnLoad: true })), driver = _render4.driver; _context7.t0 = expect; _context7.next = 4; return driver.getToggleStyles(); case 4: _context7.t1 = _context7.sent; (0, _context7.t0)(_context7.t1).toEqual(['width: 100%; position: relative; overflow: hidden; transition-property: bottom, left; transition-duration: 600ms; bottom: 100%; height: 0px;']); _context7.next = 8; return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: _context6.t0 = expect; _context6.next = 3; return driver.getToggleStyles(); case 3: _context6.t1 = _context6.sent; (0, _context6.t0)(_context6.t1).toEqual(['width: 100%; position: relative; overflow: hidden; transition-property: bottom, left; transition-duration: 600ms; bottom: 0%; height: 0px; transition-timing-function: cubic-bezier(0.4, 0.0, 1, 1); transition-delay: 200ms;']); case 5: case "end": return _context6.stop(); } }, _callee6); }))); case 8: case "end": return _context7.stop(); } }, _callee7); }))); it('should add scale styles', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9() { var _render5, driver; return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: _render5 = render(createTransition({ enterAnimation: { scaleUp: scaleUp }, exitAnimation: { scaleDown: scaleDown }, show: true, animateOnLoad: true })), driver = _render5.driver; _context9.t0 = expect; _context9.next = 4; return driver.getScaleStyles(); case 4: _context9.t1 = _context9.sent; (0, _context9.t0)(_context9.t1).toEqual(['transform: scale(0, 0); transition-property: transform; transition-duration: 600ms; transform-origin: 50% 100%;']); _context9.next = 8; return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() { return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: _context8.t0 = expect; _context8.next = 3; return driver.getScaleStyles(); case 3: _context8.t1 = _context8.sent; (0, _context8.t0)(_context8.t1).toEqual(['transform: scale(1, 1); transition-property: transform; transition-duration: 600ms; transform-origin: 50% 100%; transition-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1); transition-delay: 200ms;']); case 5: case "end": return _context8.stop(); } }, _callee8); }))); case 8: case "end": return _context9.stop(); } }, _callee9); }))); it('should not add styles when show is false', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0() { var _render6, driver; return _regeneratorRuntime.wrap(function _callee0$(_context0) { while (1) switch (_context0.prev = _context0.next) { case 0: _render6 = render(createTransition({ enterAnimation: { fadeIn: fadeIn, moveIn: moveIn, expand: expand, scaleUp: scaleUp }, exitAnimation: { fadeOut: fadeOut, moveOut: moveOut, collapse: collapse, scaleDown: scaleDown }, show: false })), driver = _render6.driver; _context0.t0 = expect; _context0.next = 4; return driver.getMoveStyles(); case 4: _context0.t1 = _context0.sent; (0, _context0.t0)(_context0.t1).toEqual([]); _context0.t2 = expect; _context0.next = 9; return driver.getFadeStyles(); case 9: _context0.t3 = _context0.sent; (0, _context0.t2)(_context0.t3).toEqual([]); _context0.t4 = expect; _context0.next = 14; return driver.getToggleStyles(); case 14: _context0.t5 = _context0.sent; (0, _context0.t4)(_context0.t5).toEqual([]); _context0.t6 = expect; _context0.next = 19; return driver.getScaleStyles(); case 19: _context0.t7 = _context0.sent; (0, _context0.t6)(_context0.t7).toEqual([]); case 21: case "end": return _context0.stop(); } }, _callee0); }))); it('should call onEnd callback on enterAnimation transition end', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10() { var onEndCallback, _render7, driver; return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) switch (_context10.prev = _context10.next) { case 0: onEndCallback = vi.fn(); _render7 = render(createTransition({ enterAnimation: { fadeIn: fadeIn }, onEnd: onEndCallback, animateOnLoad: true, show: true })), driver = _render7.driver; _context10.next = 4; return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1() { return _regeneratorRuntime.wrap(function _callee1$(_context1) { while (1) switch (_context1.prev = _context1.next) { case 0: _context1.t0 = expect; _context1.next = 3; return driver.getFadeStyles(); case 3: _context1.t1 = _context1.sent; (0, _context1.t0)(_context1.t1).toEqual(['opacity: 1; transition-property: opacity; transition-duration: 600ms; transition-timing-function: cubic-bezier(0.0, 0.0, 0.2, 1); transition-delay: 200ms;']); expect(onEndCallback).toHaveBeenCalledWith('enter'); case 6: case "end": return _context1.stop(); } }, _callee1); }))); case 4: case "end": return _context10.stop(); } }, _callee10); }))); it('should call onEnd callback on exitAnimation transition end', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12() { var onEndCallback, _render8, rerender; return _regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) switch (_context12.prev = _context12.next) { case 0: onEndCallback = vi.fn(); // Start shown, no animation on load initially _render8 = render(createTransition({ exitAnimation: { fadeOut: fadeOut }, onEnd: onEndCallback, animateOnLoad: false, show: true })), rerender = _render8.rerender; rerender(createTransition({ exitAnimation: { fadeOut: fadeOut }, onEnd: onEndCallback, animateOnLoad: false, show: false })); _context12.next = 5; return waitFor(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11() { return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) switch (_context11.prev = _context11.next) { case 0: expect(onEndCallback).toHaveBeenCalledWith('exit'); case 1: case "end": return _context11.stop(); } }, _callee11); }))); case 5: case "end": return _context12.stop(); } }, _callee12); }))); it('should call onStart callback on enterAnimation transition start ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13() { var onStartCallback; return _regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) switch (_context13.prev = _context13.next) { case 0: onStartCallback = vi.fn(); render(createTransition({ enterAnimation: { fadeIn: fadeIn }, onStart: onStartCallback, animateOnLoad: true, show: true })); expect(onStartCallback).toHaveBeenCalledWith('enter'); case 3: case "end": return _context13.stop(); } }, _callee13); }))); it('should call onStart callback on exitAnimation transition start ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14() { var onStartCallback, _render9, rerender; return _regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) switch (_context14.prev = _context14.next) { case 0: onStartCallback = vi.fn(); _render9 = render(createTransition({ exitAnimation: { fadeOut: fadeOut }, onStart: onStartCallback, animateOnLoad: false, show: true })), rerender = _render9.rerender; rerender(createTransition({ exitAnimation: { fadeOut: fadeOut }, onStart: onStartCallback, animateOnLoad: false, show: false })); expect(onStartCallback).toHaveBeenCalledWith('exit'); case 4: case "end": return _context14.stop(); } }, _callee14); }))); });