react-native/Libraries/Lists/__flowtests__/SectionList-flowtest.js
Sophie Alpert 1490ab12ef Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:31:53 -08:00

130 lines
2.9 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const React = require('react');
const SectionList = require('SectionList');
function renderMyListItem(info: {item: {title: string}, index: number}) {
return <span />;
}
const renderMyHeader = ({section}: {section: {fooNumber: number} & Object}) => (
<span />
);
module.exports = {
testGoodDataWithGoodItem() {
const sections = [
{
key: 'a',
data: [
{
title: 'foo',
key: 1,
},
],
},
];
return <SectionList renderItem={renderMyListItem} sections={sections} />;
},
testBadRenderItemFunction() {
const sections = [
{
key: 'a',
data: [
{
title: 'foo',
key: 1,
},
],
},
];
return [
// $FlowExpectedError - title should be inside `item`
<SectionList
renderItem={(info: {title: string}) => <span />}
sections={sections}
/>,
<SectionList
// $FlowExpectedError - bad index type string, should be number
renderItem={(info: {index: string}) => <span />}
sections={sections}
/>,
// EverythingIsFine
<SectionList
renderItem={(info: {item: {title: string}}) => <span />}
sections={sections}
/>,
];
},
testBadInheritedDefaultProp(): React.Element<*> {
const sections = [];
return (
<SectionList
renderItem={renderMyListItem}
sections={sections}
// $FlowExpectedError - bad windowSize type "big"
windowSize="big"
/>
);
},
testMissingData(): React.Element<*> {
// $FlowExpectedError - missing `sections` prop
return <SectionList renderItem={renderMyListItem} />;
},
testBadSectionsShape(): React.Element<*> {
const sections = [
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.63 was deployed. To see the error delete this
* comment and run Flow. */
{
key: 'a',
items: [
{
title: 'foo',
key: 1,
},
],
},
];
// $FlowExpectedError - section missing `data` field
return <SectionList renderItem={renderMyListItem} sections={sections} />;
},
testBadSectionsMetadata(): React.Element<*> {
const sections = [
{
key: 'a',
// $FlowExpectedError - section has bad meta data `fooNumber` field of type string
fooNumber: 'string',
data: [
{
title: 'foo',
key: 1,
},
],
},
];
return (
<SectionList
renderSectionHeader={renderMyHeader}
renderItem={renderMyListItem}
sections={sections}
/>
);
},
};