mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-27 12:42:28 +02:00
improvement: flow coverage
This commit is contained in:
@@ -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)
|
||||
|
@@ -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) {
|
||||
|
@@ -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)
|
||||
|
@@ -1 +1,2 @@
|
||||
// @flow
|
||||
export { default } from './Comments';
|
||||
|
@@ -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 }} />
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import renderer from 'react-test-renderer';
|
||||
import Content from './Content';
|
||||
|
@@ -1 +1,2 @@
|
||||
// @flow
|
||||
export { default } from './Content';
|
||||
|
@@ -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>
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import renderer from 'react-test-renderer';
|
||||
import Meta from './Meta';
|
||||
|
@@ -1 +1,2 @@
|
||||
// @flow
|
||||
export { default } from './Meta';
|
||||
|
@@ -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>
|
||||
|
||||
|
@@ -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'
|
||||
|
@@ -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]}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import renderer from 'react-test-renderer';
|
||||
import Tags from './Tags';
|
||||
|
@@ -1 +1,2 @@
|
||||
// @flow
|
||||
export { default } from './Tags';
|
||||
|
@@ -1 +1,2 @@
|
||||
// @flow
|
||||
export { default } from './Post';
|
||||
|
Reference in New Issue
Block a user