Skip to content

Commit

Permalink
Fix consistent image proptype
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahaog committed Feb 11, 2018
1 parent 2d310ef commit dcbeb9c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/components/IndexPage.test.jsx
Expand Up @@ -2,7 +2,11 @@ import React from 'react';
import { shallow } from 'enzyme';
import IndexPage from './IndexPage';

import { imagePropType } from '../../test/fixtures';

test('rendering', () => {
const wrapper = shallow(<IndexPage posts={[]} coverImageSizes={{}} />);
const wrapper = shallow(
<IndexPage posts={[]} coverImageSizes={imagePropType} />,
);
expect(wrapper).toMatchSnapshot();
});
6 changes: 5 additions & 1 deletion src/components/__snapshots__/IndexPage.test.jsx.snap
Expand Up @@ -4,7 +4,11 @@ exports[`rendering 1`] = `
<div>
<Styled(Image)
alt="Index page cover"
sizes={Object {}}
sizes={
Object {
"sizes": "something",
}
}
width="70vw"
/>
<CoverDivider />
Expand Down
6 changes: 5 additions & 1 deletion src/components/__snapshots__/Post.test.jsx.snap
Expand Up @@ -19,7 +19,11 @@ exports[`rendering 1`] = `
</styled.p>
<Styled(Image)
alt="title"
sizes={Object {}}
sizes={
Object {
"sizes": "something",
}
}
/>
<div
dangerouslySetInnerHTML={
Expand Down
6 changes: 5 additions & 1 deletion src/pages/__snapshots__/index.test.jsx.snap
Expand Up @@ -27,7 +27,11 @@ exports[`rendering 1`] = `
title=""
/>
<IndexPage
coverImageSizes={Object {}}
coverImageSizes={
Object {
"sizes": "something",
}
}
posts={Array []}
/>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/index.jsx
Expand Up @@ -38,7 +38,9 @@ export default function SiteIndex({
SiteIndex.propTypes = {
data: PropTypes.shape({
allMarkdownRemark: allMarkdownRemarkPropType,
indexCover: imagePropType,
indexCover: PropTypes.shape({
sizes: imagePropType,
}),
}).isRequired,
};

Expand Down
13 changes: 10 additions & 3 deletions src/proptypes/index.js
Expand Up @@ -27,16 +27,23 @@ export const site = ptShape({
}).isRequired,
});

// eslint-disable-next-line react/forbid-prop-types
export const image = ptObject;
export const image = ptShape({
// eslint-disable-next-line react/forbid-prop-types
sizes: ptString.isRequired,
// TODO: more fields here
});

export const markdownRemark = ptShape({
frontmatter: ptShape({
excerpt: ptString,
title: ptString.isRequired,
date: ptString.isRequired,
path: ptString.isRequired,
cover: image,
cover: ptShape({
childImageSharp: ptShape({
sizes: image.isRequired,
}).isRequired,
}),
}).isRequired,
excerpt: ptString.isRequired,
timeToRead: ptNumber.isRequired,
Expand Down
10 changes: 8 additions & 2 deletions test/fixtures/index.js
@@ -1,12 +1,18 @@
export const imagePropType = {};
export const imagePropType = {
sizes: 'something',
};

export const markdownRemarkPropType = {
frontmatter: {
excerpt: 'excerpt',
title: 'title',
date: 'date',
path: 'path',
cover: imagePropType,
cover: {
childImageSharp: {
sizes: imagePropType,
},
},
},
excerpt: 'excerpt',
timeToRead: 10,
Expand Down

0 comments on commit dcbeb9c

Please sign in to comment.