Skip to content

Commit

Permalink
Feature/array empty (#9)
Browse files Browse the repository at this point in the history
* remove data prop required

* add empty list test
  • Loading branch information
gusgard committed May 31, 2018
1 parent 682e517 commit 069b541
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/components/GridList/__snapshots__/test.js.snap
Expand Up @@ -99,6 +99,32 @@ exports[`grid list renders correctly 1`] = `
/>
`;

exports[`grid list renders empty list 1`] = `
<FlatList
ItemSeparatorComponent={[Function]}
animationDuration={500}
animationInitialBackgroundColor="#FFFFFF"
contentContainerStyle={false}
data={Array []}
disableVirtualization={false}
horizontal={false}
initialNumToRender={10}
itemStyle={Object {}}
keyExtractor={[Function]}
maxToRenderPerBatch={10}
numColumns={3}
onEndReachedThreshold={2}
renderItem={[Function]}
scrollEventThrottle={50}
separatorBorderColor="#FFFFFF"
separatorBorderWidth={0}
showAnimation={false}
showsVerticalScrollIndicator={false}
updateCellsBatchingPeriod={50}
windowSize={21}
/>
`;

exports[`grid list renders showAnimation 1`] = `
<FlatList
ItemSeparatorComponent={[Function]}
Expand Down
3 changes: 2 additions & 1 deletion src/components/GridList/index.js
Expand Up @@ -22,7 +22,7 @@ export default class GridList extends PureComponent {
// Only is allowed children or data not both
children(props, propName) {
const { data } = props;
if (!props[propName] && data && data.length === 0) {
if (!props[propName] && !data) {
return new Error('Invalid props, `data` or `children` is required');
}
if (data && data.length !== 0 && !props.renderItem) {
Expand All @@ -34,6 +34,7 @@ export default class GridList extends PureComponent {

static defaultProps = {
numColumns: 3,
data: [],
itemStyle: {},
showSeparator: false,
showAnimation: false,
Expand Down
10 changes: 10 additions & 0 deletions src/components/GridList/test.js
Expand Up @@ -17,6 +17,16 @@ describe('grid list', () => {
);
expect(wrapper).toMatchSnapshot();
});

it('renders empty list', () => {
const wrapper = shallow(
<GridList
data={[]}
renderItem={({ item }) => <Image source={item.thumbnail} />}
/>,
);
expect(wrapper).toMatchSnapshot();
});

it('renders showSeparator', () => {
const wrapper = shallow(
Expand Down

0 comments on commit 069b541

Please sign in to comment.