|
| 1 | +import { getAttrMap } from '../../src/utils'; |
| 2 | +import { getCurIndex } from '../../src/useScrollWatch'; |
| 3 | +describe('test src/utils', () => { |
| 4 | + describe('getAttrMap', () => { |
| 5 | + it('should return exact map when pass x', () => { |
| 6 | + expect(getAttrMap('x')).toMatchObject({ |
| 7 | + scrollLeftTop: 'scrollLeft', |
| 8 | + scrollWidthHeight: 'scrollWidth', |
| 9 | + clientWidthHeight: 'clientWidth', |
| 10 | + offsetLeftTop: 'offsetLeft', |
| 11 | + offsetWidthHeight: 'offsetWidth', |
| 12 | + leftTop: 'left', |
| 13 | + }); |
| 14 | + }); |
| 15 | + it('should return exact map when pass y', () => { |
| 16 | + expect(getAttrMap('y')).toMatchObject({ |
| 17 | + scrollLeftTop: 'scrollTop', |
| 18 | + scrollWidthHeight: 'scrollHeight', |
| 19 | + clientWidthHeight: 'clientHeight', |
| 20 | + offsetLeftTop: 'offsetTop', |
| 21 | + offsetWidthHeight: 'offsetHeight', |
| 22 | + leftTop: 'top', |
| 23 | + }); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('getCurIndex', () => { |
| 28 | + expect(getCurIndex(0, [])).toBe(-1); |
| 29 | + expect(getCurIndex(100, [101, 200])).toBe(-1); |
| 30 | + expect(getCurIndex(100, [100, 200])).toBe(0); |
| 31 | + expect(getCurIndex(102, [101, 200])).toBe(0); |
| 32 | + expect(getCurIndex(199, [101, 200])).toBe(0); |
| 33 | + expect(getCurIndex(200, [101, 200])).toBe(1); |
| 34 | + }); |
| 35 | +}); |
0 commit comments