mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-10-30 00:07:36 +01:00
refactor(starter): upgrade to new version of gatsby
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
// @flow strict
|
||||
import React from 'react';
|
||||
import { getContactHref } from '../../../utils';
|
||||
import styles from './Author.module.scss';
|
||||
import { useSiteMetadata } from '../../../hooks';
|
||||
|
||||
const Author = () => {
|
||||
const { author } = useSiteMetadata();
|
||||
|
||||
return (
|
||||
<div className={styles['author']}>
|
||||
<p className={styles['author__bio']}>
|
||||
{author.bio}
|
||||
<a
|
||||
className={styles['author__bio-twitter']}
|
||||
href={getContactHref('twitter', author.contacts.twitter)}
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<strong>{author.name}</strong> on Twitter
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Author;
|
||||
@@ -1,5 +1,5 @@
|
||||
@import '../../../assets/scss/variables';
|
||||
@import '../../../assets/scss/mixins';
|
||||
@import "../../../assets/scss/variables";
|
||||
@import "../../../assets/scss/mixins";
|
||||
|
||||
.author {
|
||||
border-top: 1px solid $color-gray-border;
|
||||
@@ -22,5 +22,4 @@
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// @flow strict
|
||||
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 }: RenderCallback) => (
|
||||
render(siteMetadata)
|
||||
),
|
||||
useStaticQuery.mockReturnValue(siteMetadata)
|
||||
);
|
||||
});
|
||||
|
||||
it('renders correctly', () => {
|
||||
const tree = renderer.create(<Author />).toJSON();
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
25
src/components/Post/Author/Author.test.tsx
Normal file
25
src/components/Post/Author/Author.test.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from "react";
|
||||
import renderer from "react-test-renderer";
|
||||
|
||||
import { StaticQuery, useStaticQuery } from "gatsby";
|
||||
|
||||
import { Author } from "@/components/Post/Author";
|
||||
import * as mocks from "@/mocks";
|
||||
|
||||
const mockedStaticQuery = StaticQuery as jest.Mock;
|
||||
const mockedUseStaticQuery = useStaticQuery as jest.Mock;
|
||||
|
||||
describe("Author", () => {
|
||||
console.log(mockedStaticQuery);
|
||||
beforeEach(() => {
|
||||
mockedStaticQuery.mockImplementationOnce(({ render }) =>
|
||||
render(mocks.siteMetadata),
|
||||
);
|
||||
mockedUseStaticQuery.mockReturnValue(mocks.siteMetadata);
|
||||
});
|
||||
|
||||
it("renders correctly", () => {
|
||||
const tree = renderer.create(<Author />).toJSON();
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
28
src/components/Post/Author/Author.tsx
Normal file
28
src/components/Post/Author/Author.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import React from "react";
|
||||
|
||||
import { useSiteMetadata } from "@/hooks";
|
||||
import { getContactHref } from "@/utils";
|
||||
|
||||
import styles from "./Author.module.scss";
|
||||
|
||||
const Author = () => {
|
||||
const { author } = useSiteMetadata();
|
||||
|
||||
return (
|
||||
<div className={styles.author}>
|
||||
<p className={styles.author__bio}>
|
||||
{author.bio}
|
||||
<a
|
||||
className={styles["author__bio-twitter"]}
|
||||
href={getContactHref("twitter", author.contacts.twitter)}
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<strong>{author.name}</strong> on Twitter
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Author;
|
||||
@@ -7,7 +7,7 @@ exports[`Author renders correctly 1`] = `
|
||||
<p
|
||||
className="author__bio"
|
||||
>
|
||||
Test bio
|
||||
Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.
|
||||
<a
|
||||
className="author__bio-twitter"
|
||||
href="https://www.twitter.com/#"
|
||||
@@ -15,7 +15,7 @@ exports[`Author renders correctly 1`] = `
|
||||
target="_blank"
|
||||
>
|
||||
<strong>
|
||||
Test name
|
||||
John Doe
|
||||
</strong>
|
||||
on Twitter
|
||||
</a>
|
||||
@@ -1,2 +0,0 @@
|
||||
// @flow strict
|
||||
export { default } from './Author';
|
||||
1
src/components/Post/Author/index.ts
Normal file
1
src/components/Post/Author/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as Author } from "./Author";
|
||||
Reference in New Issue
Block a user