react-native/RNTester/js/RNTesterExampleContainer.js
Rick Hanlon 34ee8250b5 Add filtering to e2e tests (#22828)
Summary:
This PR adds filtering for e2e test examples using the new examples filter introduced in https://github.com/facebook/react-native/pull/22777

To do that we:
- Add a `testID` to `RNTesterExampleFilter` to select an example
- Refactor a few examples to export multiple examples for filtering
- Update all tests to filter by example title
Pull Request resolved: https://github.com/facebook/react-native/pull/22828

Reviewed By: TheSavior

Differential Revision: D13562664

Pulled By: rickhanlonii

fbshipit-source-id: efb0ca8050c1ca5c10d96bd77d35dd1143c3a3b3
2018-12-31 04:33:49 -08:00

72 lines
1.8 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const React = require('react');
const {Platform} = require('react-native');
const RNTesterBlock = require('./RNTesterBlock');
const RNTesterExampleFilter = require('./RNTesterExampleFilter');
const RNTesterPage = require('./RNTesterPage');
class RNTesterExampleContainer extends React.Component {
renderExample(example, i) {
// Filter platform-specific examples
const {description, platform} = example;
let {title} = example;
if (platform) {
if (Platform.OS !== platform) {
return null;
}
title += ' (' + platform + ' only)';
}
return (
<RNTesterBlock key={i} title={title} description={description}>
{example.render()}
</RNTesterBlock>
);
}
render(): React.Element<any> {
if (!this.props.module.examples) {
return <this.props.module />;
}
if (this.props.module.examples.length === 1) {
const Example = this.props.module.examples[0].render;
return <Example />;
}
const filter = ({example, filterRegex}) => filterRegex.test(example.title);
const sections = [
{
data: this.props.module.examples,
title: 'EXAMPLES',
key: 'e',
},
];
return (
<RNTesterPage title={this.props.title}>
<RNTesterExampleFilter
testID="example_search"
sections={sections}
filter={filter}
render={({filteredSections}) =>
filteredSections[0].data.map(this.renderExample)
}
/>
</RNTesterPage>
);
}
}
module.exports = RNTesterExampleContainer;