|
| 1 | +import React from 'react'; |
1 | 2 | import * as uut from '../CarouselPresenter';
|
2 | 3 |
|
3 | 4 | describe('Carousel presenter', () => {
|
4 | 5 | it('should getChildrenLength', () => {
|
5 |
| - expect(uut.getChildrenLength({children: [{}, {}, {}]})).toBe(3); |
6 |
| - expect(uut.getChildrenLength({children: [{}]})).toBe(1); |
7 |
| - expect(uut.getChildrenLength()).toBe(0); |
| 6 | + expect(uut.getChildrenLength({children: [<></>, <></>, <></>]})).toBe(3); |
| 7 | + expect(uut.getChildrenLength({children: [<></>]})).toBe(1); |
| 8 | + expect(uut.getChildrenLength({children: [[], <></>]})).toBe(1); |
| 9 | + expect(uut.getChildrenLength(<></>)).toBe(0); |
8 | 10 | });
|
9 | 11 |
|
10 | 12 | describe('calcOffset', () => {
|
11 | 13 | it('should calcOffset (default mode)', () => {
|
12 |
| - expect(uut.calcOffset({children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 0, y: 0}); |
13 |
| - expect(uut.calcOffset({children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 120, y: 0}); |
14 |
| - expect(uut.calcOffset({children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 240, y: 0}); |
15 |
| - expect(uut.calcOffset({children: [{}, {}, {}], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 0})).toStrictEqual({x: 0, y: 0}); |
16 |
| - expect(uut.calcOffset({children: [{}, {}, {}], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 1})).toStrictEqual({x: 0, y: 150}); |
17 |
| - expect(uut.calcOffset({children: [{}, {}, {}], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 2})).toStrictEqual({x: 0, y: 300}); |
| 14 | + expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 0, y: 0}); |
| 15 | + expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 120, y: 0}); |
| 16 | + expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 240, y: 0}); |
| 17 | + expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 0})).toStrictEqual({x: 0, y: 0}); |
| 18 | + expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 1})).toStrictEqual({x: 0, y: 150}); |
| 19 | + expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 2})).toStrictEqual({x: 0, y: 300}); |
18 | 20 | });
|
19 | 21 |
|
20 | 22 | it('should calcOffset (loop mode)', () => {
|
21 |
| - expect(uut.calcOffset({loop: true, children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 120, y: 0}); |
22 |
| - expect(uut.calcOffset({loop: true, children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 240, y: 0}); |
23 |
| - expect(uut.calcOffset({loop: true, children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 360, y: 0}); |
| 23 | + expect(uut.calcOffset({loop: true, children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 120, y: 0}); |
| 24 | + expect(uut.calcOffset({loop: true, children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 240, y: 0}); |
| 25 | + expect(uut.calcOffset({loop: true, children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 360, y: 0}); |
24 | 26 | });
|
25 | 27 | });
|
26 | 28 |
|
27 | 29 | describe('calcPageIndex', () => {
|
28 | 30 | it('should calcPageIndex', () => {
|
29 |
| - expect(uut.calcPageIndex(120, {children: [{}, {}, {}]}, 120)).toBe(1); |
30 |
| - expect(uut.calcPageIndex(245, {children: [{}, {}, {}]}, 120)).toBe(2); |
31 |
| - expect(uut.calcPageIndex(481, {children: [{}, {}, {}]}, 120)).toBe(2); |
32 |
| - expect(uut.calcPageIndex(5, {children: [{}, {}, {}]}, 120)).toBe(0); |
| 31 | + expect(uut.calcPageIndex(120, {children: [<></>, <></>, <></>]}, 120)).toBe(1); |
| 32 | + expect(uut.calcPageIndex(245, {children: [<></>, <></>, <></>]}, 120)).toBe(2); |
| 33 | + expect(uut.calcPageIndex(481, {children: [<></>, <></>, <></>]}, 120)).toBe(2); |
| 34 | + expect(uut.calcPageIndex(5, {children: [<></>, <></>, <></>]}, 120)).toBe(0); |
33 | 35 | });
|
34 | 36 |
|
35 | 37 | it('should calcPageIndex (loop mode)', () => {
|
36 |
| - expect(uut.calcPageIndex(120, {loop: true, children: [{}, {}, {}]}, 120)).toBe(0); |
37 |
| - expect(uut.calcPageIndex(245, {loop: true, children: [{}, {}, {}]}, 120)).toBe(1); |
38 |
| - expect(uut.calcPageIndex(481, {loop: true, children: [{}, {}, {}]}, 120)).toBe(0); |
39 |
| - expect(uut.calcPageIndex(5, {loop: true, children: [{}, {}, {}]}, 120)).toBe(2); |
| 38 | + expect(uut.calcPageIndex(120, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(0); |
| 39 | + expect(uut.calcPageIndex(245, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(1); |
| 40 | + expect(uut.calcPageIndex(481, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(0); |
| 41 | + expect(uut.calcPageIndex(5, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(2); |
40 | 42 | });
|
41 | 43 | });
|
42 | 44 |
|
43 | 45 | it('should return isOutsideLimits', () => {
|
44 |
| - expect(uut.isOutOfBounds(120, {children: [{}, {}, {}]}, 120)).toBe(false); |
45 |
| - expect(uut.isOutOfBounds(1125, {children: [{}, {}, {}, {}]}, 375)).toBe(false); |
46 |
| - expect(uut.isOutOfBounds(0, {children: [{}, {}, {}]}, 120)).toBe(true); |
47 |
| - expect(uut.isOutOfBounds(481, {children: [{}, {}, {}]}, 120)).toBe(true); |
48 |
| - expect(uut.isOutOfBounds(1875, {children: [{}, {}, {}, {}]}, 375)).toBe(true); |
| 46 | + expect(uut.isOutOfBounds(120, {children: [<></>, <></>, <></>]}, 120)).toBe(false); |
| 47 | + expect(uut.isOutOfBounds(1125, {children: [<></>, <></>, <></>, <></>]}, 375)).toBe(false); |
| 48 | + expect(uut.isOutOfBounds(0, {children: [<></>, <></>, <></>]}, 120)).toBe(true); |
| 49 | + expect(uut.isOutOfBounds(481, {children: [<></>, <></>, <></>]}, 120)).toBe(true); |
| 50 | + expect(uut.isOutOfBounds(1875, {children: [<></>, <></>, <></>, <></>]}, 375)).toBe(true); |
49 | 51 | });
|
50 | 52 | });
|
0 commit comments