-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* link hero to instagram. * hero and header links. * improve test coverage.
- Loading branch information
1 parent
f460366
commit 874f389
Showing
7 changed files
with
84 additions
and
10 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,25 @@ | ||
import {Link as GatsbyLink} from "gatsby" | ||
import PropTypes from "prop-types" | ||
|
||
const Link = ({to, children, ...props}) => { | ||
if (to.startsWith("/")) { | ||
return ( | ||
<GatsbyLink to={to} {...props}> | ||
{children} | ||
</GatsbyLink> | ||
) | ||
} | ||
|
||
return ( | ||
<a href={to} target="_blank" rel="noopener noreferrer" {...props}> | ||
{children} | ||
</a> | ||
) | ||
} | ||
|
||
Link.propTypes = { | ||
to: PropTypes.string.isRequired, | ||
children: PropTypes.node, | ||
} | ||
|
||
export default Link |
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,20 @@ | ||
import Link from "components/Link" | ||
import {render, screen} from "test-utils/render" | ||
|
||
test("shows html link", () => { | ||
render(<Link to="https://example.com">Example</Link>) | ||
|
||
expect(screen.getByText("Example")).toHaveAttribute("target", "_blank") | ||
|
||
expect(screen.getByText("Example")).toHaveAttribute( | ||
"rel", | ||
"noopener noreferrer", | ||
) | ||
}) | ||
|
||
test("shows gatsby link", () => { | ||
render(<Link to="/example">Example</Link>) | ||
|
||
expect(screen.getByText("Example")).not.toHaveAttribute("target", "_blank") | ||
expect(screen.getByText("Example")).not.toHaveAttribute("rel") | ||
}) |
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 @@ | ||
export {default} from "./Link" |
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 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