From 6757eda23a8a927d8ad2228fe64e300298d5d57e Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 15 May 2017 16:44:02 +0800 Subject: [web] Add tests for js/components/helpers/VirtualScroll.js --- .../components/helpers/VirtualScrollSpec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 web/src/js/__tests__/components/helpers/VirtualScrollSpec.js (limited to 'web') diff --git a/web/src/js/__tests__/components/helpers/VirtualScrollSpec.js b/web/src/js/__tests__/components/helpers/VirtualScrollSpec.js new file mode 100644 index 00000000..8081e90d --- /dev/null +++ b/web/src/js/__tests__/components/helpers/VirtualScrollSpec.js @@ -0,0 +1,21 @@ +import { calcVScroll } from '../../../components/helpers/VirtualScroll' + +describe('VirtualScroll', () => { + + it('should return default state without options', () => { + expect(calcVScroll()).toEqual({start: 0, end: 0, paddingTop: 0, paddingBottom: 0}) + }) + + it('should calculate position without itemHeights', () => { + expect(calcVScroll({itemCount: 0, rowHeight: 32, viewportHeight: 400, viewportTop: 0})).toEqual({ + start: 0, end: 0, paddingTop: 0, paddingBottom: 0 + }) + }) + + it('should calculate position with itemHeights', () => { + expect(calcVScroll({itemCount: 5, itemHeights: [100, 100, 100, 100, 100], + viewportHeight: 300, viewportTop: 0})).toEqual({ + start: 0, end: 4, paddingTop: 0, paddingBottom: 100 + }) + }) +}) -- cgit v1.2.3