-
Notifications
You must be signed in to change notification settings - Fork 734
fix #1218 where carousel is not calculating children correctly #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
import React from 'react'; | ||
import * as uut from '../CarouselPresenter'; | ||
|
||
describe('Carousel presenter', () => { | ||
it('should getChildrenLength', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could argue this test is pointless now and can be deleted. It's just testing that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you changing the tests from objects to tags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because |
||
expect(uut.getChildrenLength({children: [{}, {}, {}]})).toBe(3); | ||
expect(uut.getChildrenLength({children: [{}]})).toBe(1); | ||
expect(uut.getChildrenLength()).toBe(0); | ||
expect(uut.getChildrenLength({children: [<></>, <></>, <></>]})).toBe(3); | ||
expect(uut.getChildrenLength({children: [<></>]})).toBe(1); | ||
expect(uut.getChildrenLength({children: [[], <></>]})).toBe(1); | ||
expect(uut.getChildrenLength(<></>)).toBe(0); | ||
}); | ||
|
||
describe('calcOffset', () => { | ||
it('should calcOffset (default mode)', () => { | ||
expect(uut.calcOffset({children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 0, y: 0}); | ||
expect(uut.calcOffset({children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 120, y: 0}); | ||
expect(uut.calcOffset({children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 240, y: 0}); | ||
expect(uut.calcOffset({children: [{}, {}, {}], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 0})).toStrictEqual({x: 0, y: 0}); | ||
expect(uut.calcOffset({children: [{}, {}, {}], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 1})).toStrictEqual({x: 0, y: 150}); | ||
expect(uut.calcOffset({children: [{}, {}, {}], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 2})).toStrictEqual({x: 0, y: 300}); | ||
expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 0, y: 0}); | ||
expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 120, y: 0}); | ||
expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 240, y: 0}); | ||
expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 0})).toStrictEqual({x: 0, y: 0}); | ||
expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 1})).toStrictEqual({x: 0, y: 150}); | ||
expect(uut.calcOffset({children: [<></>, <></>, <></>], horizontal: false}, {pageWidth: 80, pageHeight: 150, currentPage: 2})).toStrictEqual({x: 0, y: 300}); | ||
}); | ||
|
||
it('should calcOffset (loop mode)', () => { | ||
expect(uut.calcOffset({loop: true, children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 120, y: 0}); | ||
expect(uut.calcOffset({loop: true, children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 240, y: 0}); | ||
expect(uut.calcOffset({loop: true, children: [{}, {}, {}], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 360, y: 0}); | ||
expect(uut.calcOffset({loop: true, children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 0})).toStrictEqual({x: 120, y: 0}); | ||
expect(uut.calcOffset({loop: true, children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 1})).toStrictEqual({x: 240, y: 0}); | ||
expect(uut.calcOffset({loop: true, children: [<></>, <></>, <></>], horizontal: true}, {pageWidth: 120, pageHeight: 100, currentPage: 2})).toStrictEqual({x: 360, y: 0}); | ||
}); | ||
}); | ||
|
||
describe('calcPageIndex', () => { | ||
it('should calcPageIndex', () => { | ||
expect(uut.calcPageIndex(120, {children: [{}, {}, {}]}, 120)).toBe(1); | ||
expect(uut.calcPageIndex(245, {children: [{}, {}, {}]}, 120)).toBe(2); | ||
expect(uut.calcPageIndex(481, {children: [{}, {}, {}]}, 120)).toBe(2); | ||
expect(uut.calcPageIndex(5, {children: [{}, {}, {}]}, 120)).toBe(0); | ||
expect(uut.calcPageIndex(120, {children: [<></>, <></>, <></>]}, 120)).toBe(1); | ||
expect(uut.calcPageIndex(245, {children: [<></>, <></>, <></>]}, 120)).toBe(2); | ||
expect(uut.calcPageIndex(481, {children: [<></>, <></>, <></>]}, 120)).toBe(2); | ||
expect(uut.calcPageIndex(5, {children: [<></>, <></>, <></>]}, 120)).toBe(0); | ||
}); | ||
|
||
it('should calcPageIndex (loop mode)', () => { | ||
expect(uut.calcPageIndex(120, {loop: true, children: [{}, {}, {}]}, 120)).toBe(0); | ||
expect(uut.calcPageIndex(245, {loop: true, children: [{}, {}, {}]}, 120)).toBe(1); | ||
expect(uut.calcPageIndex(481, {loop: true, children: [{}, {}, {}]}, 120)).toBe(0); | ||
expect(uut.calcPageIndex(5, {loop: true, children: [{}, {}, {}]}, 120)).toBe(2); | ||
expect(uut.calcPageIndex(120, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(0); | ||
expect(uut.calcPageIndex(245, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(1); | ||
expect(uut.calcPageIndex(481, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(0); | ||
expect(uut.calcPageIndex(5, {loop: true, children: [<></>, <></>, <></>]}, 120)).toBe(2); | ||
}); | ||
}); | ||
|
||
it('should return isOutsideLimits', () => { | ||
expect(uut.isOutOfBounds(120, {children: [{}, {}, {}]}, 120)).toBe(false); | ||
expect(uut.isOutOfBounds(1125, {children: [{}, {}, {}, {}]}, 375)).toBe(false); | ||
expect(uut.isOutOfBounds(0, {children: [{}, {}, {}]}, 120)).toBe(true); | ||
expect(uut.isOutOfBounds(481, {children: [{}, {}, {}]}, 120)).toBe(true); | ||
expect(uut.isOutOfBounds(1875, {children: [{}, {}, {}, {}]}, 375)).toBe(true); | ||
expect(uut.isOutOfBounds(120, {children: [<></>, <></>, <></>]}, 120)).toBe(false); | ||
expect(uut.isOutOfBounds(1125, {children: [<></>, <></>, <></>, <></>]}, 375)).toBe(false); | ||
expect(uut.isOutOfBounds(0, {children: [<></>, <></>, <></>]}, 120)).toBe(true); | ||
expect(uut.isOutOfBounds(481, {children: [<></>, <></>, <></>]}, 120)).toBe(true); | ||
expect(uut.isOutOfBounds(1875, {children: [<></>, <></>, <></>, <></>]}, 375)).toBe(true); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'children' are not already part of CarouselProps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - It is fine in the component because the class uses a generic which looks like
readonly props: Readonly<P> & Readonly<{ children?: ReactNode }>;