Skip to content

Commit

Permalink
Add e2e test for Image resize method (#46982)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46982

E2E test setup for each of the `resizeMethod` methods for Image on Android

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D64136839

fbshipit-source-id: 876939a50243836030401c6456410f119abe01b5
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Oct 14, 2024
1 parent e08c7eb commit 6e120b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
37 changes: 17 additions & 20 deletions packages/rn-tester/js/components/RNTesterModuleContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {type RNTesterTheme, RNTesterThemeContext} from './RNTesterTheme';
import RNTPressableRow from './RNTPressableRow';
import RNTTestDetails from './RNTTestDetails';
import * as React from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import {Platform, ScrollView, StyleSheet, Text, View} from 'react-native';

const RNTesterBlock = require('./RNTesterBlock');
const RNTesterExampleFilter = require('./RNTesterExampleFilter');
Expand Down Expand Up @@ -62,18 +62,6 @@ export default function RNTesterModuleContainer(props: Props): React.Node {
);
};

// TODO remove this case
if (module.examples.length === 1) {
const description = module.examples[0].description ?? module.description;
const ModuleSingleExample = module.examples[0].render;
return (
<>
<Header description={description} theme={theme} />
<ModuleSingleExample />
</>
);
}

const filter = ({example: e, filterRegex}: $FlowFixMe) =>
filterRegex.test(e.title);

Expand All @@ -87,17 +75,26 @@ export default function RNTesterModuleContainer(props: Props): React.Node {
},
];

return example != null ? (
const singleModule =
example ?? (module.examples.length === 1 ? module.examples[0] : null);

return singleModule != null ? (
<>
<RNTTestDetails
title={example.title}
description={example.description}
expect={example.expect}
title={singleModule.title}
description={singleModule.description}
expect={singleModule.expect}
theme={theme}
/>
<View style={styles.examplesContainer} testID="example-container">
<example.render />
</View>
{singleModule.scrollable === true ? (
<ScrollView style={styles.examplesContainer} testID="example-container">
<singleModule.render />
</ScrollView>
) : (
<View style={styles.examplesContainer} testID="example-container">
<singleModule.render />
</View>
)}
</>
) : (
<>
Expand Down
18 changes: 14 additions & 4 deletions packages/rn-tester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -1651,10 +1651,17 @@ exports.examples = [
},
{
title: 'Large image with different resize methods',
name: 'resize-method',
description:
'Demonstrating the effects of loading a large image with different resize methods',
scrollable: true,
render: function (): React.Node {
const methods = ['auto', 'resize', 'scale', 'none'];
const methods: Array<ImageProps['resizeMethod']> = [
'auto',
'resize',
'scale',
'none',
];
// Four copies of the same image so we don't serve cached copies of the same image
const images = [
require('../../assets/large-image-1.png'),
Expand All @@ -1663,10 +1670,13 @@ exports.examples = [
require('../../assets/large-image-4.png'),
];
return (
<View>
<View testID="resize-method-example">
{methods.map((method, index) => (
<View key={method} style={{display: 'flex', overflow: 'hidden'}}>
<RNTesterText>`{method}`</RNTesterText>
<View
key={method}
style={{display: 'flex', overflow: 'hidden'}}
testID={`resize-method-example-${method ?? ''}`}>
<RNTesterText>{method}</RNTesterText>
<Image
resizeMethod={method}
source={images[index]}
Expand Down
1 change: 1 addition & 0 deletions packages/rn-tester/js/types/RNTesterTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type RNTesterModuleExample = $ReadOnly<{|
description?: string,
expect?: string,
hidden?: boolean,
scrollable?: boolean,
render: ({testID?: ?string}) => React.Node,
|}>;

Expand Down

0 comments on commit 6e120b3

Please sign in to comment.