Skip to content

Commit 197ebb4

Browse files
committed
moving component to TestCase
1 parent 67322ce commit 197ebb4

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ const props = {
2727
//animatedScrollOffset: // set to check Animated
2828
};
2929

30+
const TestCase = props => {
31+
return (
32+
<Carousel {...props}>
33+
{map([...Array(numberOfPagesShown)], (_, index) => (
34+
<Page key={index}>
35+
<Text testID={`page-${index}`}>Page #{index}</Text>
36+
</Page>
37+
))}
38+
</Carousel>
39+
);
40+
};
41+
3042
const Page = ({children, ...others}) => {
3143
return (
3244
<View {...others} style={{flex: 1}}>
@@ -35,29 +47,17 @@ const Page = ({children, ...others}) => {
3547
);
3648
};
3749

38-
describe('Carousel tests', () => {
50+
describe('Carousel render tests', () => {
51+
3952
describe('default setup', () => {
4053
it('should be set to default', () => {
41-
const component = render(<Carousel {...props}>
42-
{map([...Array(numberOfPagesShown)], (_, index) => (
43-
<Page key={index}>
44-
<Text testID={`page-${index}`}>Page #{index}</Text>
45-
</Page>
46-
))}
47-
</Carousel>);
54+
const component = render(<TestCase {...props}/>);
4855

4956
component.getByText('Page #0'); // Validates that the text is there
5057
});
5158

5259
it('should trigger onScroll from the second scroll', () => {
53-
const component = render(<Carousel {...props}>
54-
{map([...Array(numberOfPagesShown)], (_, index) => (
55-
<Page key={index}>
56-
<Text testID={`page-${index}`}>Page #{index}</Text>
57-
</Page>
58-
))}
59-
</Carousel>);
60-
60+
const component = render(<TestCase {...props}/>);
6161
const scrollView = component.getByTestId('carousel.scrollView');
6262

6363
fireEvent.scroll(scrollView, eventData); //NOTE: first scroll will no fire onScroll
@@ -68,14 +68,7 @@ describe('Carousel tests', () => {
6868
});
6969

7070
it('should trigger onChangePage with current page', async () => {
71-
const component = render(<Carousel {...props}>
72-
{map([...Array(numberOfPagesShown)], (_, index) => (
73-
<Page key={index}>
74-
<Text testID={`page-${index}`}>Page #{index}</Text>
75-
</Page>
76-
))}
77-
</Carousel>);
78-
71+
const component = render(<TestCase {...props}/>);
7972
const scrollView = component.getByTestId('carousel.scrollView');
8073

8174
fireEvent.scroll(scrollView, eventData); //NOTE: first scroll will no fire onScroll

0 commit comments

Comments
 (0)