Skip to content

Commit 9379924

Browse files
committed
fix: welcome video not rendered
1 parent 3856251 commit 9379924

File tree

6 files changed

+118
-15
lines changed

6 files changed

+118
-15
lines changed

src/CONST.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,6 +5117,11 @@ const CONST = {
51175117
},
51185118
SELECTION_LIST_WITH_MODAL_TEST_ID: 'selectionListWithModalMenuItem',
51195119

5120+
IMAGE_TEST_ID: 'Image',
5121+
IMAGE_SVG_TEST_ID: 'ImageSVG',
5122+
VIDEO_PLAYER_TEST_ID: 'VideoPlayer',
5123+
LOTTIE_VIEW_TEST_ID: 'LottieView',
5124+
51205125
CHAT_HEADER_LOADER_HEIGHT: 36,
51215126

51225127
HORIZONTAL_SPACER: {

src/components/FeatureTrainingModal.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,23 @@ function FeatureTrainingModal({
219219
(!!videoURL || !!image) && {aspectRatio},
220220
]}
221221
>
222-
{!!image && shouldRenderSVG ? (
223-
<ImageSVG
224-
src={image}
225-
contentFit={contentFitImage}
226-
width={imageWidth}
227-
height={imageHeight}
228-
/>
229-
) : (
230-
<Image
231-
source={image as ImageSourcePropType}
232-
resizeMode={contentFitImage as ImageResizeMode}
233-
style={styles.featureTrainingModalImage}
234-
/>
235-
)}
222+
{!!image &&
223+
(shouldRenderSVG ? (
224+
<ImageSVG
225+
src={image}
226+
contentFit={contentFitImage}
227+
width={imageWidth}
228+
height={imageHeight}
229+
testID={CONST.IMAGE_SVG_TEST_ID}
230+
/>
231+
) : (
232+
<Image
233+
source={image as ImageSourcePropType}
234+
resizeMode={contentFitImage as ImageResizeMode}
235+
style={styles.featureTrainingModalImage}
236+
testID={CONST.IMAGE_TEST_ID}
237+
/>
238+
))}
236239
{!!videoURL && videoStatus === 'video' && (
237240
<GestureHandlerRootView>
238241
<VideoPlayer

src/components/ImageSVG/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ type ImageSVGProps = {
3232

3333
/** The preserveAspectRatio attribute indicates how an element with a viewBox providing a given aspect ratio must fit into a viewport with a different aspect ratio. */
3434
preserveAspectRatio?: string;
35+
36+
/** TestID for test */
37+
testID?: string;
3538
};
3639

3740
export default ImageSVGProps;

src/components/Lottie/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ function Lottie({source, webStyle, shouldLoadAfterInteractions, ...props}: Props
9595
// 1. heavy rendering, see issues: https://github.com/Expensify/App/issues/34696 and https://github.com/Expensify/App/issues/47273
9696
// 2. lag on react navigation transitions, see issue: https://github.com/Expensify/App/issues/44812
9797
if (isError || appState.isBackground || !animationFile || splashScreenState !== CONST.BOOT_SPLASH_STATE.HIDDEN || (!isInteractionComplete && shouldLoadAfterInteractions)) {
98-
return <View style={[aspectRatioStyle, props.style]} />;
98+
return (
99+
<View
100+
style={[aspectRatioStyle, props.style]}
101+
testID={CONST.LOTTIE_VIEW_TEST_ID}
102+
/>
103+
);
99104
}
100105

101106
return (
@@ -116,6 +121,7 @@ function Lottie({source, webStyle, shouldLoadAfterInteractions, ...props}: Props
116121
style={[aspectRatioStyle, props.style]}
117122
webStyle={{...aspectRatioStyle, ...webStyle}}
118123
onAnimationFailure={() => setIsError(true)}
124+
testID={CONST.LOTTIE_VIEW_TEST_ID}
119125
/>
120126
);
121127
}

src/components/VideoPlayer/BaseVideoPlayer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ function BaseVideoPlayer({
504504
onError={() => {
505505
setHasError(true);
506506
}}
507+
testID={CONST.VIDEO_PLAYER_TEST_ID}
507508
/>
508509
</View>
509510
)}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {render, screen} from '@testing-library/react-native';
2+
import type {ViewProps} from 'react-native';
3+
import type ReactNative from 'react-native';
4+
import ReceiptDoc from '@assets/images/receipt-doc.png';
5+
import FeatureTrainingModal from '@components/FeatureTrainingModal';
6+
import * as Illustrations from '@components/Icon/Illustrations';
7+
import {FullScreenContextProvider} from '@components/VideoPlayerContexts/FullScreenContext';
8+
import {PlaybackContextProvider} from '@components/VideoPlayerContexts/PlaybackContext';
9+
import {VideoPopoverMenuContextProvider} from '@components/VideoPlayerContexts/VideoPopoverMenuContext';
10+
import {VolumeContextProvider} from '@components/VideoPlayerContexts/VolumeContext';
11+
import CONST from '@src/CONST';
12+
13+
const CONFIRM_TEXT = 'Start';
14+
15+
jest.mock('@libs/Navigation/Navigation', () => ({
16+
isTopmostRouteModalScreen: jest.fn(),
17+
isNavigationReady: jest.fn(() => Promise.resolve()),
18+
}));
19+
20+
jest.mock('@libs/Fullstory');
21+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
22+
jest.mock('expo-av', () => {
23+
const {View} = require<typeof ReactNative>('react-native');
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
25+
return {
26+
...jest.requireActual('expo-av'),
27+
// eslint-disable-next-line react/jsx-props-no-spreading
28+
Video: (props: ViewProps) => <View {...props} />,
29+
};
30+
});
31+
32+
jest.mock('@components/ImageSVG', () => {
33+
const {View} = require<typeof ReactNative>('react-native');
34+
// eslint-disable-next-line react/jsx-props-no-spreading
35+
return (props: ViewProps) => <View {...props} />;
36+
});
37+
38+
describe('FeatureTrainingModal', () => {
39+
describe('renderIllustration', () => {
40+
it('renders video', () => {
41+
render(
42+
<PlaybackContextProvider>
43+
<FullScreenContextProvider>
44+
<VolumeContextProvider>
45+
<VideoPopoverMenuContextProvider>
46+
<FeatureTrainingModal
47+
confirmText={CONFIRM_TEXT}
48+
videoURL={CONST.WELCOME_VIDEO_URL}
49+
/>
50+
</VideoPopoverMenuContextProvider>
51+
</VolumeContextProvider>
52+
</FullScreenContextProvider>
53+
</PlaybackContextProvider>,
54+
);
55+
56+
expect(screen.getByTestId(CONST.VIDEO_PLAYER_TEST_ID)).toBeOnTheScreen();
57+
});
58+
it('renders svg image', () => {
59+
render(
60+
<FeatureTrainingModal
61+
confirmText={CONFIRM_TEXT}
62+
image={Illustrations.HoldExpense}
63+
/>,
64+
);
65+
66+
expect(screen.getByTestId(CONST.IMAGE_SVG_TEST_ID)).toBeOnTheScreen();
67+
});
68+
it('renders non-svg image', () => {
69+
render(
70+
<FeatureTrainingModal
71+
confirmText={CONFIRM_TEXT}
72+
image={ReceiptDoc}
73+
shouldRenderSVG={false}
74+
/>,
75+
);
76+
77+
expect(screen.getByTestId(CONST.IMAGE_TEST_ID)).toBeOnTheScreen();
78+
});
79+
it('renders animation', () => {
80+
render(<FeatureTrainingModal confirmText={CONFIRM_TEXT} />);
81+
82+
expect(screen.getByTestId(CONST.LOTTIE_VIEW_TEST_ID)).toBeOnTheScreen();
83+
});
84+
});
85+
});

0 commit comments

Comments
 (0)