diff --git a/__mocks__/modules/gatsby-plugin-google-analytics.js b/__mocks__/modules/gatsby-plugin-google-analytics.js
new file mode 100644
index 000000000..14cb2220a
--- /dev/null
+++ b/__mocks__/modules/gatsby-plugin-google-analytics.js
@@ -0,0 +1,15 @@
+import React from 'react'
+import {onLinkClick} from 'gatsby-plugin-google-analytics';
+
+afterEach(() => {
+ onLinkClick.mockReset();
+})
+
+jest.mock('gatsby-plugin-google-analytics', () => {
+ const onLinkClick = jest.fn();
+
+ return {
+ OutboundLink: (props) =>
{props.children}
,
+ onLinkClick
+ }
+});
diff --git a/__mocks__/modules/index.js b/__mocks__/modules/index.js
index 8f357b900..7b05f34b1 100644
--- a/__mocks__/modules/index.js
+++ b/__mocks__/modules/index.js
@@ -1,4 +1,4 @@
import './gatsby';
import './gatsby-image';
import './disqus-react';
-
+import './gatsby-plugin-google-analytics'
diff --git a/src/templates/blog-profile.test.js b/src/templates/blog-profile.test.js
index 908d9f0d2..5d7f66ef5 100644
--- a/src/templates/blog-profile.test.js
+++ b/src/templates/blog-profile.test.js
@@ -1,10 +1,12 @@
import React from "react"
-import { render } from "@testing-library/react"
+import { fireEvent, render } from "@testing-library/react"
import { siteMetadata } from "../../__mocks__/data/mock-site-metadata"
import { MockPost } from "../../__mocks__/data/mock-post"
import { useStaticQuery } from "gatsby"
import { MockUnicorn } from "../../__mocks__/data/mock-unicorn"
import BlogProfile from "./blog-profile"
+import {onLinkClick as onAnalyticsLinkClick} from 'gatsby-plugin-google-analytics';
+import {onLinkClick as onGarsbyLinkClick} from 'gatsby';
beforeAll(() => {
useStaticQuery.mockImplementation(() => ({
@@ -19,7 +21,7 @@ afterAll(() => {
})
test("Blog profile page renders", async () => {
- const { baseElement } = render(
+ const { baseElement, findByText, findByTestId } = render(
{
/>)
expect(baseElement).toBeInTheDocument();
+ expect(await findByText('Joe')).toBeInTheDocument();
+ expect(await findByText('Exists')).toBeInTheDocument();
+ const TwitterEl = await findByText('Twitter')
+ expect(TwitterEl).toBeInTheDocument();
+ fireEvent.click(TwitterEl);
+ expect(onAnalyticsLinkClick).toHaveBeenCalledTimes(1)
+ const GitHubEl = await findByText('GitHub')
+ expect(GitHubEl).toBeInTheDocument();
+ fireEvent.click(GitHubEl);
+ expect(onAnalyticsLinkClick).toHaveBeenCalledTimes(2)
+ const WebsiteEl = await findByText('Website')
+ expect(WebsiteEl).toBeInTheDocument();
+ fireEvent.click(WebsiteEl);
+ expect(onAnalyticsLinkClick).toHaveBeenCalledTimes(3)
+ expect(await findByText('1 Articles')).toBeInTheDocument();
+ expect(await findByText('10000 Words')).toBeInTheDocument();
+
+ // Post cards
+ expect(await findByText("by Joe")).toBeInTheDocument();
+ expect(await findByText('10-10-2010')).toBeInTheDocument();
+ expect(await findByText('This is a short description dunno why this would be this short')).toBeInTheDocument();
+
+ fireEvent.click(await findByText("Post title"));
+ expect(onGarsbyLinkClick).toHaveBeenCalledTimes(2);
+
+ fireEvent.click(await findByTestId("authorPic"));
+ expect(onGarsbyLinkClick).toHaveBeenCalledTimes(4);
+
})