-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FlatList Visual Snapshot Tests to E2E Tests Fabric (#12870)
* Add FlatList Tests * Update Snapshots * Adjust Snapshots + Merge * Test Fix * Test Fix * Add Search for Example * Update Snapshots * Merge * Update Snapshots * Lint * Test Fewer * Fix Dangling Symbol * Update Overrides * Update Snapshots * Remove Tests * Update Snapshots * Update Snapshots * Update Snapshots * Remove Extra Test
- Loading branch information
1 parent
c0be76e
commit c4f3dd3
Showing
9 changed files
with
7,725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
...ages/@react-native-windows/tester/src/js/examples/FlatList/BaseFlatListExample.windows.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
import type {RenderItemProps} from 'react-native/Libraries/Lists/VirtualizedList'; | ||
|
||
import * as React from 'react'; | ||
import { | ||
Button, | ||
FlatList, | ||
Pressable, | ||
StyleSheet, | ||
Text, | ||
View, | ||
} from 'react-native'; | ||
|
||
const DATA = [ | ||
'Pizza', | ||
'Burger', | ||
'Risotto', | ||
'French Fries', | ||
'Onion Rings', | ||
'Fried Shrimps', | ||
'Water', | ||
'Coke', | ||
'Beer', | ||
'Cheesecake', | ||
'Brownie', | ||
]; | ||
|
||
const Item = ({item, separators}: RenderItemProps<string>) => { | ||
return ( | ||
<Pressable | ||
onPressIn={() => { | ||
separators.highlight(); | ||
}} | ||
onPress={() => { | ||
separators.updateProps('trailing', {hasBeenHighlighted: true}); | ||
separators.updateProps('leading', {hasBeenHighlighted: true}); | ||
}} | ||
onPressOut={() => { | ||
separators.unhighlight(); | ||
}} | ||
style={({pressed}) => [ | ||
styles.item, | ||
{ | ||
backgroundColor: pressed ? 'red' : 'pink', | ||
}, | ||
]} | ||
testID={item}> | ||
<Text style={styles.title}>{item}</Text> | ||
</Pressable> | ||
); | ||
}; | ||
|
||
type Props = { | ||
exampleProps: Partial<React.ElementConfig<typeof FlatList>>, | ||
onTest?: ?() => void, | ||
testLabel?: ?string, | ||
testOutput?: ?string, | ||
children?: ?React.Node, | ||
}; | ||
|
||
const BaseFlatListExample = React.forwardRef( | ||
// $FlowFixMe[incompatible-call] | ||
( | ||
props: Props, | ||
ref: | ||
| ((null | FlatList<string>) => mixed) | ||
| {current: null | FlatList<string>, ...}, | ||
) => { | ||
return ( | ||
<View style={styles.container}> | ||
{props.testOutput != null ? ( | ||
<View testID="test_container" style={styles.testContainer}> | ||
<Text style={styles.output} numberOfLines={1} testID="output"> | ||
{props.testOutput} | ||
</Text> | ||
{props.onTest != null ? ( | ||
<Button | ||
testID="start_test" | ||
onPress={props.onTest} | ||
title={props.testLabel ?? 'Test'} | ||
/> | ||
) : null} | ||
</View> | ||
) : null} | ||
{props.children} | ||
<FlatList | ||
{...props.exampleProps} | ||
// $FlowFixMe[incompatible-type] | ||
ref={ref} | ||
testID="flat_list" | ||
// $FlowFixMe[incompatible-type] | ||
data={DATA} | ||
keyExtractor={(item, index) => item + index} | ||
style={styles.list} | ||
// $FlowFixMe[incompatible-type-arg] | ||
renderItem={Item} | ||
accessible | ||
/> | ||
</View> | ||
); | ||
}, | ||
); | ||
|
||
export default (BaseFlatListExample: React.AbstractComponent< | ||
Props, | ||
FlatList<string>, | ||
>); | ||
|
||
const ITEM_INNER_HEIGHT = 70; | ||
const ITEM_MARGIN = 8; | ||
export const ITEM_HEIGHT: number = ITEM_INNER_HEIGHT + ITEM_MARGIN * 2; | ||
|
||
const styles = StyleSheet.create({ | ||
item: { | ||
backgroundColor: 'pink', | ||
paddingHorizontal: 20, | ||
height: ITEM_INNER_HEIGHT, | ||
marginVertical: ITEM_MARGIN, | ||
justifyContent: 'center', | ||
}, | ||
header: { | ||
fontSize: 32, | ||
backgroundColor: 'white', | ||
}, | ||
title: { | ||
fontSize: 24, | ||
}, | ||
titleContainer: { | ||
position: 'absolute', | ||
top: 45, | ||
left: 0, | ||
right: 0, | ||
justifyContent: 'flex-end', | ||
alignItems: 'center', | ||
backgroundColor: 'gray', | ||
zIndex: 1, | ||
}, | ||
titleText: { | ||
fontSize: 24, | ||
lineHeight: 44, | ||
fontWeight: 'bold', | ||
}, | ||
testContainer: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
backgroundColor: '#f2f2f7ff', | ||
height: 40, | ||
}, | ||
output: { | ||
fontSize: 12, | ||
}, | ||
separator: { | ||
height: 12, | ||
}, | ||
separatorText: { | ||
fontSize: 10, | ||
}, | ||
list: { | ||
flex: 1, | ||
}, | ||
container: {flex: 1}, | ||
offScreen: { | ||
height: 1000, | ||
}, | ||
}); |
Oops, something went wrong.