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,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';