-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate FlatList/SectionList E2E testss from Catalyst to RNTester (#4…
…6274) Summary: Pull Request resolved: #46274 changelog: [General][Add] - Add E2E test cases for Flat/SectionList to RNTester Reviewed By: philIip Differential Revision: D62002065
- Loading branch information
1 parent
1bd4a11
commit 5f6a29c
Showing
28 changed files
with
532 additions
and
139 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
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
78 changes: 78 additions & 0 deletions
78
packages/rn-tester/js/examples/FlatList/FlatList-BaseOnViewableItemsChanged.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,78 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {ViewToken} from 'react-native/Libraries/Lists/ViewabilityHelper'; | ||
|
||
import BaseFlatListExample from './BaseFlatListExample'; | ||
import * as React from 'react'; | ||
import {FlatList, StyleSheet, View} from 'react-native'; | ||
|
||
type FlatListProps = React.ElementProps<typeof FlatList>; | ||
type ViewabilityConfig = $PropertyType<FlatListProps, 'viewabilityConfig'>; | ||
|
||
const BASE_VIEWABILITY_CONFIG = { | ||
minimumViewTime: 1000, | ||
viewAreaCoveragePercentThreshold: 100, | ||
}; | ||
|
||
export function FlatList_BaseOnViewableItemsChanged(props: { | ||
offScreen?: ?boolean, | ||
horizontal?: ?boolean, | ||
useScrollRefScroll?: ?boolean, | ||
waitForInteraction?: ?boolean, | ||
}): React.Node { | ||
const {offScreen, horizontal, useScrollRefScroll, waitForInteraction} = props; | ||
const [output, setOutput] = React.useState(''); | ||
const onViewableItemsChanged = React.useCallback( | ||
(info: {changed: Array<ViewToken>, viewableItems: Array<ViewToken>, ...}) => | ||
setOutput( | ||
info.viewableItems | ||
.filter(viewToken => viewToken.index != null && viewToken.isViewable) | ||
.map(viewToken => viewToken.item) | ||
.join(', '), | ||
), | ||
[setOutput], | ||
); | ||
const viewabilityConfig: ViewabilityConfig = { | ||
...BASE_VIEWABILITY_CONFIG, | ||
waitForInteraction: waitForInteraction ?? false, | ||
}; | ||
const exampleProps = { | ||
onViewableItemsChanged, | ||
viewabilityConfig, | ||
horizontal, | ||
}; | ||
|
||
const ref = React.useRef<any>(null); | ||
const onTest = | ||
useScrollRefScroll === true | ||
? () => { | ||
ref?.current?.getScrollResponder()?.scrollToEnd(); | ||
} | ||
: null; | ||
|
||
return ( | ||
<BaseFlatListExample | ||
ref={ref} | ||
exampleProps={exampleProps} | ||
onTest={onTest} | ||
testOutput={output}> | ||
{offScreen === true ? <View style={styles.offScreen} /> : null} | ||
</BaseFlatListExample> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
offScreen: { | ||
height: 1000, | ||
}, | ||
}); |
30 changes: 30 additions & 0 deletions
30
...r/js/examples/FlatList/FlatList-onViewableItemsChanged-horizontal-noWaitForInteraction.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,30 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
||
import {FlatList_BaseOnViewableItemsChanged} from './FlatList-BaseOnViewableItemsChanged'; | ||
import * as React from 'react'; | ||
|
||
export default ({ | ||
title: 'onViewableItemsChanged horizontal', | ||
name: 'onViewableItemsChanged-horizontal-noWaitForInteraction', | ||
description: | ||
'E2E Test:\nonViewableItemsChanged-horizontal-noWaitForInteraction', | ||
hidden: true, | ||
render: () => ( | ||
<FlatList_BaseOnViewableItemsChanged | ||
horizontal={true} | ||
waitForInteraction={false} | ||
/> | ||
), | ||
}: RNTesterModuleExample); |
29 changes: 29 additions & 0 deletions
29
...es/rn-tester/js/examples/FlatList/FlatList-onViewableItemsChanged-horizontal-offScreen.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,29 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
||
import {FlatList_BaseOnViewableItemsChanged} from './FlatList-BaseOnViewableItemsChanged'; | ||
import * as React from 'react'; | ||
|
||
export default ({ | ||
title: 'onViewableItemsChanged horizontal', | ||
name: 'onViewableItemsChanged-horizontal-offScreen', | ||
description: 'E2E Test:\nonViewableItemsChanged-horizontal-offScreen', | ||
hidden: true, | ||
render: () => ( | ||
<FlatList_BaseOnViewableItemsChanged | ||
horizontal={true} | ||
waitForInteraction={true} | ||
/> | ||
), | ||
}: RNTesterModuleExample); |
30 changes: 30 additions & 0 deletions
30
...ter/js/examples/FlatList/FlatList-onViewableItemsChanged-horizontal-waitForInteraction.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,30 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
||
import {FlatList_BaseOnViewableItemsChanged} from './FlatList-BaseOnViewableItemsChanged'; | ||
import * as React from 'react'; | ||
|
||
export default ({ | ||
title: 'onViewableItemsChanged horizontal', | ||
name: 'onViewableItemsChanged-horizontal-waitForInteraction', | ||
description: | ||
'E2E Test:\nonViewableItemsChanged-horizontal-waitForInteraction', | ||
hidden: true, | ||
render: () => ( | ||
<FlatList_BaseOnViewableItemsChanged | ||
horizontal={true} | ||
waitForInteraction={true} | ||
/> | ||
), | ||
}: RNTesterModuleExample); |
26 changes: 26 additions & 0 deletions
26
...es/rn-tester/js/examples/FlatList/FlatList-onViewableItemsChanged-noWaitForInteraction.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,26 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
||
import {FlatList_BaseOnViewableItemsChanged} from './FlatList-BaseOnViewableItemsChanged'; | ||
import * as React from 'react'; | ||
|
||
export default ({ | ||
title: 'onViewableItemsChanged', | ||
name: 'onViewableItemsChanged_noWaitForInteraction', | ||
description: 'E2E Test:\nonViewableItemsChanged-noWaitForInteraction', | ||
hidden: true, | ||
render: () => ( | ||
<FlatList_BaseOnViewableItemsChanged waitForInteraction={false} /> | ||
), | ||
}: RNTesterModuleExample); |
29 changes: 29 additions & 0 deletions
29
packages/rn-tester/js/examples/FlatList/FlatList-onViewableItemsChanged-offScreen.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,29 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
||
import {FlatList_BaseOnViewableItemsChanged} from './FlatList-BaseOnViewableItemsChanged'; | ||
import * as React from 'react'; | ||
|
||
export default ({ | ||
title: 'onViewableItemsChanged offScreen', | ||
name: 'onViewableItemsChanged-offScreen', | ||
description: 'E2E Test:\nonViewableItemsChanged-offScreen', | ||
hidden: true, | ||
render: () => ( | ||
<FlatList_BaseOnViewableItemsChanged | ||
offScreen={true} | ||
waitForInteraction={true} | ||
/> | ||
), | ||
}: RNTesterModuleExample); |
26 changes: 26 additions & 0 deletions
26
...ages/rn-tester/js/examples/FlatList/FlatList-onViewableItemsChanged-waitForInteraction.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,26 @@ | ||
/** | ||
* 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. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; | ||
|
||
import {FlatList_BaseOnViewableItemsChanged} from './FlatList-BaseOnViewableItemsChanged'; | ||
import * as React from 'react'; | ||
|
||
export default ({ | ||
title: 'onViewableItemsChanged', | ||
name: 'onViewableItemsChanged-waitForInteraction', | ||
description: 'E2E Test:\nonViewableItemsChanged-waitForInteraction', | ||
hidden: true, | ||
render: () => ( | ||
<FlatList_BaseOnViewableItemsChanged waitForInteraction={true} /> | ||
), | ||
}: RNTesterModuleExample); |
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
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
Oops, something went wrong.