improvement: flow coverage

This commit is contained in:
alxshelepenok
2019-05-10 02:15:43 +03:00
parent 091834f16a
commit 35f2170bf5
66 changed files with 308 additions and 56 deletions

View File

@@ -1,9 +1,15 @@
// @flow
import React from 'react';
import moment from 'moment';
import { Link } from 'gatsby';
import type { Edges } from '../../types';
import styles from './Feed.module.scss';
const Feed = ({ edges }) => (
type Props = {
edges: Edges
};
const Feed = ({ edges }: Props) => (
<div className={styles['feed']}>
{edges.map((edge) => (
<div className={styles['feed__item']} key={edge.node.fields.slug}>

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Feed from './Feed';
@@ -9,28 +10,50 @@ describe('Feed', () => {
node: {
fields: {
slug: '/test_0',
categorySlug: '/test_0'
categorySlug: '/test_0',
tagSlugs: [
'/test-1',
'/test-2'
]
},
frontmatter: {
date: '2016-09-01',
description: 'test_0',
category: 'test_0',
tags: [
'test-1',
'test-2'
],
title: 'test_0'
}
},
id: 'test-123',
html: '<p>test</p>'
}
},
{
node: {
fields: {
slug: '/test_1',
categorySlug: '/test_1'
categorySlug: '/test_1',
tagSlugs: [
'/test-1',
'/test-2'
]
},
frontmatter: {
date: '2016-09-01',
description: 'test_1',
category: 'test_1',
tags: [
'test-1',
'test-2'
],
title: 'test_1'
}
},
id: 'test-321',
html: '<p>test</p>'
}
}
]

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Feed';

View File

@@ -1,7 +1,15 @@
// @flow
import React from 'react';
import styles from './Icon.module.scss';
const Icon = ({ icon }) => (
type Props = {
icon: {
viewBox?: string,
path?: string
}
};
const Icon = ({ icon }: Props) => (
<svg className={styles['icon']} viewBox={icon.viewBox}>
<path d={icon.path} />
</svg>

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Icon from './Icon';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Icon';

View File

@@ -1,8 +1,16 @@
// @flow
import React from 'react';
import Helmet from 'react-helmet';
import type { Node as ReactNode } from 'react';
import styles from './Layout.module.scss';
const Layout = ({ children, title, description }) => (
type Props = {
children: ReactNode,
title: string,
description?: string
};
const Layout = ({ children, title, description }: Props) => (
<div className={styles.layout}>
<Helmet>
<html lang="en" />

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Layout from './Layout';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Layout';

View File

@@ -1,7 +1,12 @@
import React, { useRef, useEffect } from 'react';
import styles from './Page.module.scss';
const Page = ({ title, children }) => {
type Props = {
title?: string,
children: React.Node
};
const Page = ({ title, children }: Props) => {
const pageRef = useRef();
useEffect(() => {

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Page from './Page';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Page';

View File

@@ -1,9 +1,17 @@
// @flow
import React from 'react';
import classNames from 'classnames/bind';
import { Link } from 'gatsby';
import { PAGINATION } from '../../constants';
import styles from './Pagination.module.scss';
type Props = {
prevPagePath: string,
nextPagePath: string,
hasNextPage: boolean,
hasPrevPage: boolean
};
const cx = classNames.bind(styles);
const Pagination = ({
@@ -11,7 +19,7 @@ const Pagination = ({
nextPagePath,
hasNextPage,
hasPrevPage
}) => {
}: Props) => {
const prevClassName = cx({
'pagination__prev-link': true,
'pagination__prev-link--disable': !hasPrevPage

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Pagination from './Pagination';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Pagination';

View File

@@ -1,13 +1,15 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Author from './Author';
import siteMetadata from '../../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../../types';
describe('Author', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }) => (
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)

View File

@@ -1,8 +1,14 @@
// @flow
import React from 'react';
import ReactDisqusComments from 'react-disqus-comments';
import { useSiteMetadata } from '../../../hooks';
const Comments = ({ postTitle, postSlug }) => {
type Props = {
postTitle: string,
postSlug: string
};
const Comments = ({ postTitle, postSlug }: Props) => {
const { url, disqusShortname } = useSiteMetadata();
if (!disqusShortname) {

View File

@@ -1,13 +1,15 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Comments from './Comments';
import siteMetadata from '../../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../../types';
describe('Comments', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }) => (
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Comments';

View File

@@ -1,7 +1,13 @@
// @flow
import React from 'react';
import styles from './Content.module.scss';
const Content = ({ body, title }) => (
type Props = {
body: string,
title: string
};
const Content = ({ body, title }: Props) => (
<div className={styles['content']}>
<h1 className={styles['content__title']}>{title}</h1>
<div className={styles['content__body']} dangerouslySetInnerHTML={{ __html: body }} />

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Content from './Content';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Content';

View File

@@ -1,8 +1,13 @@
// @flow
import React from 'react';
import moment from 'moment';
import styles from './Meta.module.scss';
const Meta = ({ date }) => (
type Props = {
date: string
};
const Meta = ({ date }: Props) => (
<div className={styles['meta']}>
<p className={styles['meta__date']}>Published {moment(date).format('D MMM YYYY')}</p>
</div>

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Meta from './Meta';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Meta';

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import { Link } from 'gatsby';
import Author from './Author';
@@ -6,8 +7,13 @@ import Content from './Content';
import Meta from './Meta';
import Tags from './Tags';
import styles from './Post.module.scss';
import type { Node } from '../../types';
const Post = ({ post }) => {
type Props = {
post: Node
};
const Post = ({ post }: Props) => {
const { html } = post;
const { tagSlugs, slug } = post.fields;
const { tags, title, date } = post.frontmatter;
@@ -22,7 +28,7 @@ const Post = ({ post }) => {
<div className={styles['post__footer']}>
<Meta date={date} />
{tags && <Tags tags={tags} tagSlugs={tagSlugs} />}
{tags && tagSlugs && <Tags tags={tags} tagSlugs={tagSlugs} />}
<Author />
</div>

View File

@@ -1,13 +1,15 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Post from './Post';
import siteMetadata from '../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../types';
describe('Post', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }) => (
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)
@@ -16,8 +18,11 @@ describe('Post', () => {
const props = {
post: {
id: 'test-123',
html: '<p>test</p>',
fields: {
slug: '/test',
categorySlug: '/test-category',
tagSlugs: [
'/test_0',
'/test_1'

View File

@@ -1,11 +1,17 @@
// @flow
import React from 'react';
import { Link } from 'gatsby';
import styles from './Tags.module.scss';
const Tags = ({ tags, tagSlugs }) => (
type Props = {
tags: string[],
tagSlugs: string[]
};
const Tags = ({ tags, tagSlugs }: Props) => (
<div className={styles['tags']}>
<ul className={styles['tags__list']}>
{tagSlugs.map((slug, i) => (
{tagSlugs && tagSlugs.map((slug, i) => (
<li className={styles['tags__list-item']} key={tags[i]}>
<Link to={slug} className={styles['tags__list-item-link']}>
{tags[i]}

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Tags from './Tags';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Tags';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Post';

View File

@@ -1,8 +1,18 @@
// @flow
import React from 'react';
import { withPrefix, Link } from 'gatsby';
import styles from './Author.module.scss';
const Author = ({ author, isIndex }) => (
type Props = {
author: {
name: string,
bio: string,
photo: string
},
isIndex: ?boolean
};
const Author = ({ author, isIndex }: Props) => (
<div className={styles['author']}>
<Link to="/">
<img

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Author from './Author';
@@ -8,7 +9,8 @@ describe('Author', () => {
name: 'test',
photo: '/photo.jpg',
bio: 'test'
}
},
isIndex: false
};
it('renders correctly', () => {

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Author';

View File

@@ -4,11 +4,11 @@ import { getContactHref, getIcon } from '../../../utils';
import Icon from '../../Icon';
import styles from './Contacts.module.scss';
type Props = {|
+contacts: {
type Props = {
contacts: {
[string]: string,
},
|};
};
const Contacts = ({ contacts }: Props) => (
<div className={styles['contacts']}>

View File

@@ -1,3 +1,5 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Contacts from './Contacts';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Contacts';

View File

@@ -1,7 +1,12 @@
// @flow
import React from 'react';
import styles from './Copyright.module.scss';
const Copyright = ({ copyright }) => (
type Props = {
copyright: string
};
const Copyright = ({ copyright }: Props) => (
<div className={styles['copyright']}>
{copyright}
</div>

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Copyright from './Copyright';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Copyright';

View File

@@ -1,8 +1,16 @@
// @flow
import React from 'react';
import { Link } from 'gatsby';
import styles from './Menu.module.scss';
const Menu = ({ menu }) => (
type Props = {
menu: {
label: string,
path: string
}[]
};
const Menu = ({ menu }: Props) => (
<nav className={styles['menu']}>
<ul className={styles['menu__list']}>
{menu.map((item) => (

View File

@@ -1,3 +1,4 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import Menu from './Menu';

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Menu';

View File

@@ -8,7 +8,7 @@ import styles from './Sidebar.module.scss';
import { useSiteMetadata } from '../../hooks';
type Props = {
+isIndex: ?boolean,
isIndex?: boolean,
};
const Sidebar = ({ isIndex }: Props) => {

View File

@@ -1,13 +1,15 @@
// @flow
import React from 'react';
import renderer from 'react-test-renderer';
import { useStaticQuery, StaticQuery } from 'gatsby';
import Sidebar from './Sidebar';
import siteMetadata from '../../../jest/__fixtures__/site-metadata';
import type { RenderCallback } from '../../types';
describe('Sidebar', () => {
beforeEach(() => {
StaticQuery.mockImplementationOnce(
({ render }) => (
({ render }: RenderCallback) => (
render(siteMetadata)
),
useStaticQuery.mockReturnValue(siteMetadata)

View File

@@ -1 +1,2 @@
// @flow
export { default } from './Sidebar';