mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-10 12:57:46 +00:00
Added post list tests for blog profile page
This commit is contained in:
15
__mocks__/modules/gatsby-plugin-google-analytics.js
Normal file
15
__mocks__/modules/gatsby-plugin-google-analytics.js
Normal file
@@ -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) => <div onClick={onLinkClick}>{props.children}</div>,
|
||||||
|
onLinkClick
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import './gatsby';
|
import './gatsby';
|
||||||
import './gatsby-image';
|
import './gatsby-image';
|
||||||
import './disqus-react';
|
import './disqus-react';
|
||||||
|
import './gatsby-plugin-google-analytics'
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import React from "react"
|
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 { siteMetadata } from "../../__mocks__/data/mock-site-metadata"
|
||||||
import { MockPost } from "../../__mocks__/data/mock-post"
|
import { MockPost } from "../../__mocks__/data/mock-post"
|
||||||
import { useStaticQuery } from "gatsby"
|
import { useStaticQuery } from "gatsby"
|
||||||
import { MockUnicorn } from "../../__mocks__/data/mock-unicorn"
|
import { MockUnicorn } from "../../__mocks__/data/mock-unicorn"
|
||||||
import BlogProfile from "./blog-profile"
|
import BlogProfile from "./blog-profile"
|
||||||
|
import {onLinkClick as onAnalyticsLinkClick} from 'gatsby-plugin-google-analytics';
|
||||||
|
import {onLinkClick as onGarsbyLinkClick} from 'gatsby';
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
useStaticQuery.mockImplementation(() => ({
|
useStaticQuery.mockImplementation(() => ({
|
||||||
@@ -19,7 +21,7 @@ afterAll(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test("Blog profile page renders", async () => {
|
test("Blog profile page renders", async () => {
|
||||||
const { baseElement } = render(
|
const { baseElement, findByText, findByTestId } = render(
|
||||||
<BlogProfile
|
<BlogProfile
|
||||||
data={{
|
data={{
|
||||||
site: {
|
site: {
|
||||||
@@ -39,5 +41,33 @@ test("Blog profile page renders", async () => {
|
|||||||
/>)
|
/>)
|
||||||
|
|
||||||
expect(baseElement).toBeInTheDocument();
|
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);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user