Skip to content

Commit

Permalink
Optional prop for RNTesterApp to provide custom test lists (facebook#…
Browse files Browse the repository at this point in the history
…41537)

Summary:
Pull Request resolved: facebook#41537

# Changelog:
[Internal] -

This allows to optionally provide a custom list of component/api test clauses into `RNTesterApp`.

Reviewed By: christophpurrer

Differential Revision: D51429407

fbshipit-source-id: 3ee35f13f6156fd055f6e0cbc788b7cf01c22b36
  • Loading branch information
rshest authored and facebook-github-bot committed Nov 17, 2023
1 parent ba43dd2 commit f4d006a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 12 additions & 3 deletions packages/rn-tester/js/RNTesterAppShared.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @flow
*/

import type {RNTesterModuleInfo} from './types/RNTesterTypes';

import RNTesterModuleContainer from './components/RNTesterModuleContainer';
import RNTesterModuleList from './components/RNTesterModuleList';
import RNTesterNavBar, {navBarHeight} from './components/RNTesterNavbar';
Expand All @@ -28,7 +30,14 @@ import {BackHandler, StyleSheet, View, useColorScheme} from 'react-native';

// RNTester App currently uses in memory storage for storing navigation state

const RNTesterApp = (): React.Node => {
const RNTesterApp = ({
testList,
}: {
testList?: {
components?: Array<RNTesterModuleInfo>,
apis?: Array<RNTesterModuleInfo>,
},
}): React.Node => {
const [state, dispatch] = React.useReducer(
RNTesterNavigationReducer,
initialNavigationState,
Expand All @@ -44,8 +53,8 @@ const RNTesterApp = (): React.Node => {
} = state;

const examplesList = React.useMemo(
() => getExamplesListWithRecentlyUsed({recentlyUsed}),
[recentlyUsed],
() => getExamplesListWithRecentlyUsed({recentlyUsed, testList}),
[recentlyUsed, testList],
);

const handleBackPress = React.useCallback(() => {
Expand Down
11 changes: 9 additions & 2 deletions packages/rn-tester/js/utils/testerStateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ const filterEmptySections = (examplesList: ExamplesList): any => {

export const getExamplesListWithRecentlyUsed = ({
recentlyUsed,
testList,
}: {
recentlyUsed: ComponentList,
testList?: {
components?: Array<RNTesterModuleInfo>,
apis?: Array<RNTesterModuleInfo>,
},
}): ExamplesList | null => {
// Return early if state has not been initialized from storage
if (!recentlyUsed) {
return null;
}

const components = RNTesterList.Components.map(
const componentList = testList?.components ?? RNTesterList.Components;
const components = componentList.map(
(componentExample): RNTesterModuleInfo => ({
...componentExample,
exampleType: Screens.COMPONENTS,
Expand All @@ -69,7 +75,8 @@ export const getExamplesListWithRecentlyUsed = ({
)
.filter(Boolean);

const apis = RNTesterList.APIs.map((apiExample): RNTesterModuleInfo => ({
const apisList = testList?.apis ?? RNTesterList.APIs;
const apis = apisList.map((apiExample): RNTesterModuleInfo => ({
...apiExample,
exampleType: Screens.APIS,
}));
Expand Down

0 comments on commit f4d006a

Please sign in to comment.