UNPKG

@wix/design-system

Version:

@wix/design-system

193 lines 7.53 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/common/ScrollableContainer/test/ScrollableContainer.spec.jsx", _this = this; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React from 'react'; import { createRendererWithUniDriver, cleanup } from '../../../utils/test-utils/unit'; import { scrollableContainerDriverFactory } from '../ScrollableContainer.uni.driver'; import ScrollableContainer from '../ScrollableContainer'; import { getScrollAreaY } from '../scrollAreaLogic'; import { AreaY } from '../index'; describe('ScrollableContainer', function () { var render = createRendererWithUniDriver(scrollableContainerDriverFactory); afterEach(cleanup); it('should render the provided children', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var children, _render, driver; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: children = /*#__PURE__*/React.createElement("div", { "data-hook": "children", __self: _this, __source: { fileName: _jsxFileName, lineNumber: 17, columnNumber: 22 } }); _render = render(/*#__PURE__*/React.createElement(ScrollableContainer, { __self: _this, __source: { fileName: _jsxFileName, lineNumber: 19, columnNumber: 7 } }, children)), driver = _render.driver; _context.t0 = expect; _context.next = 5; return driver.childExists('children'); case 5: _context.t1 = _context.sent; (0, _context.t0)(_context.t1).toBe(true); case 7: case "end": return _context.stop(); } }, _callee); }))); it('should call the `onScrollAreaChanged` method after container was mounted ', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var onScrollAreaChangedSpy; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: onScrollAreaChangedSpy = vi.fn(); render(/*#__PURE__*/React.createElement(ScrollableContainer, { onScrollAreaChanged: onScrollAreaChangedSpy, __self: _this, __source: { fileName: _jsxFileName, lineNumber: 27, columnNumber: 7 } })); expect(onScrollAreaChangedSpy).toHaveBeenCalledTimes(1); expect(onScrollAreaChangedSpy).toHaveBeenCalledWith(expect.objectContaining({ area: { y: AreaY.NONE } })); case 4: case "end": return _context2.stop(); } }, _callee2); }))); it('should use received forwarded ref when passed while internal registering to scroll events still works', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { var testValue, testRef, onScrollAreaChangedSpy; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: testValue = 'test'; testRef = /*#__PURE__*/React.createRef(); onScrollAreaChangedSpy = vi.fn(); render(/*#__PURE__*/React.createElement(ScrollableContainer, { ref: testRef, onScrollAreaChanged: onScrollAreaChangedSpy, __self: _this, __source: { fileName: _jsxFileName, lineNumber: 40, columnNumber: 7 } }, testValue)); expect(onScrollAreaChangedSpy).toHaveBeenCalledTimes(1); expect(onScrollAreaChangedSpy).toHaveBeenCalledWith(expect.objectContaining({ area: { y: AreaY.NONE } })); expect(testRef.current.textContent).toEqual(testValue); case 7: case "end": return _context3.stop(); } }, _callee3); }))); describe('Scroll Logic', function () { it('should calculate the Y scroll area to `none` when clientHeight is equal to scrollHeight', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() { var area; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: area = getScrollAreaY({ scrollHeight: 50, clientHeight: 50, scrollTop: 0 }); expect(area).toBe(AreaY.NONE); case 2: case "end": return _context4.stop(); } }, _callee4); }))); it('should calculate the Y scroll area to `none` when clientHeight is greater than scrollHeight', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5() { var area; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: area = getScrollAreaY({ scrollHeight: 50, clientHeight: 51, scrollTop: 0 }); expect(area).toBe(AreaY.NONE); case 2: case "end": return _context5.stop(); } }, _callee5); }))); it('should calculate the Y scroll area to `top`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() { var area; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: area = getScrollAreaY({ scrollHeight: 100, clientHeight: 50, scrollTop: 0 }); expect(area).toBe(AreaY.TOP); case 2: case "end": return _context6.stop(); } }, _callee6); }))); it('should calculate the Y scroll area to `middle`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() { var area; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: area = getScrollAreaY({ scrollHeight: 100, clientHeight: 50, scrollTop: 10 }); expect(area).toBe(AreaY.MIDDLE); case 2: case "end": return _context7.stop(); } }, _callee7); }))); it('should calculate the Y scroll area to `bottom`', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8() { var area; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: area = getScrollAreaY({ scrollHeight: 100, clientHeight: 50, scrollTop: 50 }); expect(area).toBe(AreaY.BOTTOM); case 2: case "end": return _context8.stop(); } }, _callee8); }))); }); });