-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #603 from CalCorbin/next-head
chore: Try Next Head component
- Loading branch information
Showing
5 changed files
with
52 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { cleanup, render } from '@testing-library/react'; | ||
import MetaDataTags from './MetaDataTags'; | ||
|
||
describe('MetaDataTags', () => { | ||
const initialProps = { | ||
title: 'The Hobbit', | ||
description: 'A book about a hobbit', | ||
image: 'image/ring/one-ring.jpg', | ||
url: 'https://www.example.com', | ||
}; | ||
|
||
const prepareComponent = (props = initialProps) => | ||
render(<MetaDataTags {...props} />); | ||
|
||
afterEach(cleanup); | ||
|
||
it.skip('should render expected props', () => { | ||
prepareComponent(); | ||
|
||
expect(document.title).toBe(initialProps.title); | ||
expect( | ||
document | ||
.querySelector('meta[property="og:title"]') | ||
?.getAttribute('content') | ||
).toBe(initialProps.title); | ||
expect( | ||
document | ||
.querySelector('meta[property="og:description"]') | ||
?.getAttribute('content') | ||
).toBe(initialProps.description); | ||
expect( | ||
document | ||
.querySelector('meta[property="og:image"]') | ||
?.getAttribute('content') | ||
).toBe(initialProps.image); | ||
expect( | ||
document.querySelector('meta[property="og:url"]')?.getAttribute('content') | ||
).toBe(initialProps.url); | ||
}); | ||
}); |
17 changes: 10 additions & 7 deletions
17
src/components/HelmetData/HelmetData.tsx → src/components/MetaDataTags/MetaDataTags.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
import { Helmet } from 'react-helmet'; | ||
import Head from 'next/head'; | ||
|
||
interface PortfolioHelmetProps { | ||
interface MetaDataTagsProps { | ||
title: string; | ||
description: string; | ||
image: string; | ||
url: string; | ||
} | ||
|
||
const PortfolioHelmet = ({ | ||
const MetaDataTags = ({ | ||
title, | ||
description, | ||
image, | ||
url, | ||
}: PortfolioHelmetProps) => { | ||
}: MetaDataTagsProps) => { | ||
return ( | ||
<Helmet> | ||
<Head> | ||
<meta name="description" content={description} /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta charSet="UTF-8" /> | ||
<title>{title}</title> | ||
<meta property="og:title" content={title} /> | ||
<meta property="og:description" content={description} /> | ||
<meta property="og:image" content={image} /> | ||
<meta property="og:url" content={url} /> | ||
<meta property="og:type" content="website" /> | ||
</Helmet> | ||
</Head> | ||
); | ||
}; | ||
|
||
export default PortfolioHelmet; | ||
export default MetaDataTags; |