Skip to content

Commit eab886d

Browse files
committed
fix tests
1 parent 2216bc5 commit eab886d

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/components/carousel/__tests__/index.spec.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@ const eventData = {
1515
};
1616
const onChangePageMock = jest.fn();
1717
const onScrollMock = jest.fn();
18-
const props = {
19-
testID: 'carousel',
20-
initialPage: 0,
21-
pagingEnabled: true,
22-
autoplay: false,
23-
autoplayInterval: 4000,
24-
horizontal: true,
25-
onChangePage: onChangePageMock,
26-
onScroll: onScrollMock
27-
//animatedScrollOffset: // set to check Animated
28-
};
2918

3019
const TestCase = props => {
3120
return (
32-
<Carousel {...props}>
21+
<Carousel
22+
testID={'carousel'}
23+
onChangePage={onChangePageMock}
24+
onScroll={onScrollMock}
25+
{...props}
26+
>
3327
{map([...Array(numberOfPagesShown)], (_, index) => (
3428
<Page key={index}>
3529
<Text testID={`page-${index}`}>Page #{index}</Text>
@@ -49,29 +43,41 @@ const Page = ({children, ...others}) => {
4943

5044
describe('Carousel render tests', () => {
5145

52-
describe('default setup', () => {
53-
it('should be set to default', () => {
54-
const component = render(<TestCase {...props}/>);
46+
describe('initialPage', () => {
47+
it('should be set to default initialPage', () => {
48+
const component = render(<TestCase/>);
49+
const scrollView = component.getByTestId('carousel.scrollView');
50+
51+
expect(scrollView.props.contentOffset.x).toBe(0);
52+
});
5553

56-
component.getByText('Page #0'); // Validates that the text is there
54+
it('should be set to initialPage = 2', () => {
55+
const component = render(<TestCase initialPage={2}/>);
56+
const scrollView = component.getByTestId('carousel.scrollView');
57+
58+
expect(scrollView.props.contentOffset.x).toBe(Constants.screenWidth * 2);
5759
});
60+
});
5861

62+
describe('onScroll', () => {
5963
it('should trigger onScroll from the second scroll', () => {
60-
const component = render(<TestCase {...props}/>);
64+
const component = render(<TestCase/>);
6165
const scrollView = component.getByTestId('carousel.scrollView');
6266

63-
fireEvent.scroll(scrollView, eventData); //NOTE: first scroll will no fire onScroll
67+
fireEvent.scroll(scrollView, eventData); //NOTE: first scroll doesn't fire onScroll
6468
expect(onScrollMock).not.toHaveBeenCalled();
6569

6670
fireEvent.scroll(scrollView, eventData);
6771
expect(onScrollMock).toHaveBeenCalled();
6872
});
73+
});
6974

75+
describe('onChangePage', () => {
7076
it('should trigger onChangePage with current page', async () => {
71-
const component = render(<TestCase {...props}/>);
77+
const component = render(<TestCase/>);
7278
const scrollView = component.getByTestId('carousel.scrollView');
7379

74-
fireEvent.scroll(scrollView, eventData); //NOTE: first scroll will no fire onScroll
80+
fireEvent.scroll(scrollView, eventData); //NOTE: first scroll doesn't fire onScroll
7581
fireEvent.scroll(scrollView, eventData);
7682
expect(onChangePageMock).not.toHaveBeenCalled();
7783

0 commit comments

Comments
 (0)