-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 397] SEO title and description (#418)
* title and head in index
- Loading branch information
1 parent
7878dbe
commit ab6211e
Showing
4 changed files
with
74 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Head from "next/head"; | ||
|
||
type Props = { | ||
title: string; | ||
description: string; | ||
}; | ||
|
||
const PageSEO = ({ title, description }: Props) => { | ||
return ( | ||
<Head> | ||
<title>{title}</title> | ||
<meta property="og:title" content={title} key="title" /> | ||
<meta | ||
data-testid="meta-description" | ||
name="description" | ||
content={description} | ||
key="description" | ||
/> | ||
</Head> | ||
); | ||
}; | ||
|
||
export default PageSEO; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import PageSEO from "src/components/PageSEO"; | ||
|
||
jest.mock("next/head", () => { | ||
return { | ||
__esModule: true, | ||
default: ({ children }: { children: Array<React.ReactElement> }) => { | ||
return <>{children}</>; | ||
}, | ||
}; | ||
}); | ||
|
||
describe("PageSEO", () => { | ||
it("Renders title without errors", () => { | ||
const props = { title: "test title", description: "test description" }; | ||
render(<PageSEO {...props} />); | ||
const title = screen.getByText("test title"); | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
|
||
it("Renders meta description content without errors", () => { | ||
const props = { title: "test title", description: "test description" }; | ||
render(<PageSEO {...props} />); | ||
const description = screen.getByTestId("meta-description"); | ||
expect(description).toBeInTheDocument(); | ||
}); | ||
|
||
it("Renders the correct title after rerendering", () => { | ||
const initialProps = { | ||
title: "test title", | ||
description: "test description", | ||
}; | ||
const updatedProps = { | ||
title: "updated test title", | ||
description: "updated test description", | ||
}; | ||
const { rerender } = render(<PageSEO {...initialProps} />); | ||
const title = screen.getByText("test title"); | ||
expect(title).toBeInTheDocument(); | ||
rerender(<PageSEO {...updatedProps} />); | ||
const oldTitle = screen.queryByText("test title"); | ||
const updatedtitle = screen.getByText("updated test title"); | ||
expect(oldTitle).not.toBeInTheDocument(); | ||
expect(updatedtitle).toBeInTheDocument(); | ||
}); | ||
}); |