Skip to content

Commit af0e6af

Browse files
kmichalikkkkafar
andauthored
chore: Simplify single test import in App.tsx (#3678)
## Description This PR aims to simplify importing of single tests instead of the whole example app. Depending on which test needs to be selected, part of the `apps/App.tsx` file needs to be uncommented & modified. The whole Example is selected by default. ## Changes Modify typing & imports for tests. ## Checklist - [x] Included code example that can be used to test this change. --------- Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
1 parent a6a7575 commit af0e6af

11 files changed

Lines changed: 55 additions & 30 deletions

File tree

apps/App.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import React from 'react';
22
import { enableFreeze } from 'react-native-screens';
3+
34
import Example from './Example';
4-
// import * as Test from './src/tests/issue-tests';
5+
// import { NavigationContainer } from '@react-navigation/native';
6+
// import { Tests } from './src/tests';
57

68
enableFreeze(true);
79

810
export default function App() {
911
return <Example />;
10-
// return <Test.TestBottomTabs />;
12+
// return (
13+
// <NavigationContainer>
14+
// <Tests.Issue.TestBottomTabs />
15+
// </NavigationContainer>
16+
// );
1117
}

apps/src/tests/component-integration-tests/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import {
55
NavigationIndependentTree,
66
} from '@react-navigation/native';
77
import { createNativeStackNavigator } from '@react-navigation/native-stack';
8-
import { ScenarioGroup } from '../shared/helpers';
98
import { ScenarioButton } from '../shared/ScenarioButton';
109

1110
import OrientationScenarioGroup from './orientation';
1211
import ScrollViewScenarioGroup from './scroll-view';
1312
import ScenarioSelectionScreen from '../shared/ScenarioScreen';
1413

15-
const COMPONENT_SCENARIOS: Record<string, ScenarioGroup> = {
14+
export const COMPONENT_SCENARIOS = {
1615
Orientation: OrientationScenarioGroup,
1716
ScrollView: ScrollViewScenarioGroup,
1817
} as const;

apps/src/tests/component-integration-tests/orientation/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { ScenarioGroup } from '../../shared/helpers';
22
import StackInTabs from './orientation-stack-in-tabs';
33
import TabsInStack from './orientation-tabs-in-stack';
44

5-
const OrientationScenarios: ScenarioGroup = {
5+
const scenarios = { StackInTabs, TabsInStack };
6+
7+
const OrientationScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
68
name: 'Orientation tests',
79
details:
810
'Test interaction between different components when orientation changes',
9-
scenarios: [StackInTabs, TabsInStack],
11+
scenarios,
1012
};
1113

12-
export default OrientationScenarios;
14+
export default OrientationScenarioGroup;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { ScenarioGroup } from '../../shared/helpers';
22

3-
const ScrollViewScenarioGroup: ScenarioGroup = {
3+
const scenarios = {};
4+
5+
const ScrollViewScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
46
name: 'ScrollView integration tests',
57
details: 'Tests related to integration of our components with ScrollView',
6-
scenarios: [],
8+
scenarios,
79
};
810

911
export default ScrollViewScenarioGroup;

apps/src/tests/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { COMPONENT_SCENARIOS as Feature } from './single-feature-tests';
2+
import { COMPONENT_SCENARIOS as Integration } from './component-integration-tests';
3+
import * as Issue from './issue-tests';
4+
5+
export const Tests = {
6+
Feature,
7+
Integration,
8+
Issue,
9+
};

apps/src/tests/shared/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface Scenario {
2828
AppComponent: React.ComponentType;
2929
}
3030

31-
export interface ScenarioGroup {
31+
export interface ScenarioGroup<K extends string> {
3232
/**
3333
* Name of this scenario group
3434
*/
@@ -37,7 +37,7 @@ export interface ScenarioGroup {
3737
* Additional description of what this group of scenarios is related to.
3838
*/
3939
details?: string;
40-
scenarios: Scenario[];
40+
scenarios: Record<K, Scenario>;
4141
}
4242

4343
export type KeyList = Record<keyof any, undefined>;

apps/src/tests/single-feature-tests/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import TabsScenarioGroup from './tabs';
1010
import SplitScenarioGroup from './split';
1111
import StackV5ScenarioGroup from './stack-v5';
1212
import StackV4ScenarioGroup from './stack-v4';
13-
import type { ScenarioGroup } from '../shared/helpers';
1413
import { ScenarioButton } from '../shared/ScenarioButton';
1514
import ScenarioSelectionScreen from '../shared/ScenarioScreen';
1615

17-
export const COMPONENT_SCENARIOS: Record<string, ScenarioGroup> = {
16+
export const COMPONENT_SCENARIOS = {
1817
Tabs: TabsScenarioGroup,
1918
Split: SplitScenarioGroup,
2019
StackV5: StackV5ScenarioGroup,

apps/src/tests/single-feature-tests/split/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { ScenarioGroup } from '../../shared/helpers';
22
import TestTopColumnForCollapsing from './test-top-column-for-collapsing';
33
import TestCommandShowColumn from './test-command-show-column';
44

5-
const SplitScenarioGroup: ScenarioGroup = {
5+
const scenarios = { TestTopColumnForCollapsing, TestCommandShowColumn };
6+
7+
const SplitScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
68
name: 'Split',
79
details: 'Single feature tests for Split',
8-
scenarios: [TestTopColumnForCollapsing, TestCommandShowColumn],
10+
scenarios,
911
};
1012

1113
export default SplitScenarioGroup;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { ScenarioGroup } from '../../shared/helpers';
22
import Orientation from './stack-v4-orientation';
33

4-
const StackV4ScenarioGroup: ScenarioGroup = {
4+
const scenarios = { Orientation };
5+
6+
const StackV4ScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
57
name: 'Stack v4',
68
details: 'Single feature tests for Stack v4',
7-
scenarios: [Orientation],
9+
scenarios,
810
};
911

1012
export default StackV4ScenarioGroup;

apps/src/tests/single-feature-tests/stack-v5/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import PreventNativeDismissSingleStack from './prevent-native-dismiss-single-sta
33
import PreventNativeDismissNestedStack from './prevent-native-dismiss-nested-stack';
44
import AnimationAndroid from './test-animation-android';
55

6-
const StackScenarioGroup: ScenarioGroup = {
6+
const scenarios = {
7+
PreventNativeDismissSingleStack,
8+
PreventNativeDismissNestedStack,
9+
AnimationAndroid,
10+
};
11+
12+
const StackScenarioGroup: ScenarioGroup<keyof typeof scenarios> = {
713
name: 'Stack v5',
814
details: 'Single feature tests for new stack implementation',
9-
scenarios: [
10-
PreventNativeDismissSingleStack,
11-
PreventNativeDismissNestedStack,
12-
AnimationAndroid,
13-
],
15+
scenarios,
1416
};
1517

1618
export default StackScenarioGroup;

0 commit comments

Comments
 (0)