UNPKG

@enact/ui

Version:

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

59 lines (58 loc) 1.82 kB
"use strict"; require("@testing-library/jest-dom"); var _Scroller = require("../Scroller"); describe('ScrollBasic', function () { var scrollContentRef; beforeEach(function () { jest.createMockFromModule('@enact/core/platform'); scrollContentRef = { current: { scrollLeft: 0, scrollTop: 0, scrollBy: jest.fn(), scrollTo: jest.fn() } }; }); afterEach(function () { jest.clearAllMocks(); }); test('should call scrollBy on scrollToPosition', function () { var instance = new _Scroller.ScrollerBasic({ scrollContentRef: scrollContentRef, direction: 'both' }); instance.scrollToPosition(100, 200, 'smooth'); expect(scrollContentRef.current.scrollTo).toHaveBeenCalledWith({ left: 100, top: 200, behavior: 'smooth' }); instance.scrollToPosition(100, 200, 'instant'); expect(scrollContentRef.current.scrollTo).toHaveBeenCalledWith({ left: 100, top: 200, behavior: 'instant' }); }); test('should call scrollBy with animated values during animateScroll', function () { var rafCallback; var instance = new _Scroller.ScrollerBasic({ scrollContentRef: scrollContentRef, direction: 'both' }); instance.scrollBounds.maxTop = 500; instance.scrollBounds.maxLeft = 500; window.requestAnimationFrame = jest.fn(function (cb) { rafCallback = cb; }); window.cancelAnimationFrame = jest.fn(); instance.animateScroll(100, 200, scrollContentRef.current); rafCallback(); expect(scrollContentRef.current.scrollBy).toHaveBeenCalled(); scrollContentRef.current.scrollTop = 500; instance.animateScroll(550, 550, scrollContentRef.current); rafCallback(); expect(window.cancelAnimationFrame).toHaveBeenCalled(); }); });