-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathConditionalScrollView.test.tsx
More file actions
101 lines (88 loc) · 2.82 KB
/
ConditionalScrollView.test.tsx
File metadata and controls
101 lines (88 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from 'react';
import { render } from '@testing-library/react-native';
import { Text, View } from 'react-native';
import ConditionalScrollView from './ConditionalScrollView';
describe('ConditionalScrollView', () => {
const testContent = (
<View>
<Text>Test Content</Text>
</View>
);
describe('when isScrollEnabled is true', () => {
it('wraps children in ScrollView and renders content', () => {
const { getByTestId, getByText } = render(
<ConditionalScrollView
isScrollEnabled
scrollViewProps={{ testID: 'scroll-container' }}
>
{testContent}
</ConditionalScrollView>,
);
expect(getByTestId('scroll-container')).toBeDefined();
expect(getByText('Test Content')).toBeDefined();
});
it('passes scrollViewProps to ScrollView', () => {
const testID = 'test-scroll-view';
const { getByTestId } = render(
<ConditionalScrollView
isScrollEnabled
scrollViewProps={{
testID,
showsVerticalScrollIndicator: false,
bounces: false,
}}
>
{testContent}
</ConditionalScrollView>,
);
const scrollView = getByTestId(testID);
expect(scrollView.props.showsVerticalScrollIndicator).toBe(false);
expect(scrollView.props.bounces).toBe(false);
});
});
describe('when isScrollEnabled is false', () => {
it('renders children without ScrollView wrapper', () => {
const { getByText, queryByTestId } = render(
<ConditionalScrollView
isScrollEnabled={false}
scrollViewProps={{ testID: 'should-not-exist' }}
>
{testContent}
</ConditionalScrollView>,
);
expect(queryByTestId('should-not-exist')).toBeNull();
expect(getByText('Test Content')).toBeDefined();
});
});
describe('dynamic behavior', () => {
it('switches between ScrollView and direct rendering when isScrollEnabled changes', () => {
const result = render(
<ConditionalScrollView
isScrollEnabled
scrollViewProps={{ testID: 'scroll-view' }}
>
{testContent}
</ConditionalScrollView>,
);
expect(result.getByTestId('scroll-view')).toBeDefined();
result.rerender(
<ConditionalScrollView
isScrollEnabled={false}
scrollViewProps={{ testID: 'scroll-view' }}
>
{testContent}
</ConditionalScrollView>,
);
expect(result.queryByTestId('scroll-view')).toBeNull();
result.rerender(
<ConditionalScrollView
isScrollEnabled
scrollViewProps={{ testID: 'scroll-view' }}
>
{testContent}
</ConditionalScrollView>,
);
expect(result.getByTestId('scroll-view')).toBeDefined();
});
});
});