From 1dde88a511e3e824a3723b46dd1f9d0385539267 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 13 Nov 2019 14:08:57 +0100 Subject: [PATCH] test tweaks --- jest/__fixtures__/meta.json | 7 ++++++ jest/setup-test-env.js | 19 ++++++++++++++ src/components/atoms/Vcard.test.jsx | 7 ------ .../molecules/Availability.test.jsx | 2 -- src/components/molecules/LogoUnit.test.jsx | 9 ------- src/components/molecules/Networks.jsx | 2 +- src/components/molecules/Networks.test.jsx | 21 +--------------- src/components/organisms/Footer.test.jsx | 11 -------- src/components/organisms/Header.test.jsx | 8 ------ src/hooks/use-resume.test.js | 18 ------------- src/pages/__tests__/index.test.jsx | 9 ------- src/pages/resume/ResumeItem.module.scss | 4 +-- src/pages/resume/index.jsx | 25 +++++++++++++------ src/pages/resume/index.module.scss | 19 ++++++++++---- 14 files changed, 61 insertions(+), 100 deletions(-) delete mode 100644 src/hooks/use-resume.test.js diff --git a/jest/__fixtures__/meta.json b/jest/__fixtures__/meta.json index 374c42d..a760765 100644 --- a/jest/__fixtures__/meta.json +++ b/jest/__fixtures__/meta.json @@ -4,6 +4,13 @@ "tagline": "Designer & Developer", "description": "Portfolio of web & ui designer/developer hybrid Matthias Kretschmann.", "url": "https://matthiaskretschmann.com", + "img": { + "childImageSharp": { + "resize": { + "src": "/static/5ecbb5694b0b2152aa71398164af38b2/da1a7/twitter-card.png" + } + } + }, "availability": { "status": false, "available": "👔 Available for new projects. Let’s talk!", diff --git a/jest/setup-test-env.js b/jest/setup-test-env.js index ecbbfda..184a34c 100644 --- a/jest/setup-test-env.js +++ b/jest/setup-test-env.js @@ -1,2 +1,21 @@ import '@testing-library/jest-dom/extend-expect' import 'jest-canvas-mock' +import { StaticQuery, useStaticQuery } from 'gatsby' + +import meta from './__fixtures__/meta.json' +import resume from './__fixtures__/resume.json' + +beforeAll(() => { + const photoSrc = resume.contentJson.basics.picture.childImageSharp.fixed.src + const dataMock = { + ...meta, + ...resume, + photoSrc, + portfolioJson: { bugs: '' } + } + + StaticQuery.mockImplementation(({ render }) => render({ ...dataMock })) + useStaticQuery.mockImplementation(() => { + return { ...dataMock } + }) +}) diff --git a/src/components/atoms/Vcard.test.jsx b/src/components/atoms/Vcard.test.jsx index e9c8e23..899b42b 100644 --- a/src/components/atoms/Vcard.test.jsx +++ b/src/components/atoms/Vcard.test.jsx @@ -1,17 +1,10 @@ import React from 'react' import { render, fireEvent, waitForElement } from '@testing-library/react' -import { useStaticQuery } from 'gatsby' import Vcard, { constructVcard, toDataURL, init } from './Vcard' import data from '../../../jest/__fixtures__/meta.json' describe('Vcard', () => { beforeEach(() => { - useStaticQuery.mockImplementationOnce(() => { - return { - ...data - } - }) - global.URL.createObjectURL = jest.fn() }) diff --git a/src/components/molecules/Availability.test.jsx b/src/components/molecules/Availability.test.jsx index 8817fdf..2536602 100644 --- a/src/components/molecules/Availability.test.jsx +++ b/src/components/molecules/Availability.test.jsx @@ -2,11 +2,9 @@ import React from 'react' import { render } from '@testing-library/react' import Availability from './Availability' import { useStaticQuery } from 'gatsby' -import data from '../../../jest/__fixtures__/meta.json' describe('Availability', () => { it('renders correctly from data file values', () => { - useStaticQuery.mockImplementation(() => ({ ...data })) const { container } = render() expect(container.firstChild).toBeInTheDocument() }) diff --git a/src/components/molecules/LogoUnit.test.jsx b/src/components/molecules/LogoUnit.test.jsx index 379aa58..1058e47 100644 --- a/src/components/molecules/LogoUnit.test.jsx +++ b/src/components/molecules/LogoUnit.test.jsx @@ -1,17 +1,8 @@ import React from 'react' import { render } from '@testing-library/react' -import { useStaticQuery } from 'gatsby' import LogoUnit from './LogoUnit' import data from '../../../jest/__fixtures__/meta.json' -beforeEach(() => { - useStaticQuery.mockImplementationOnce(() => { - return { - ...data - } - }) -}) - describe('LogoUnit', () => { it('renders correctly from data file values', () => { const { title, tagline } = data.metaYaml diff --git a/src/components/molecules/Networks.jsx b/src/components/molecules/Networks.jsx index 917ce3f..a6f08c0 100644 --- a/src/components/molecules/Networks.jsx +++ b/src/components/molecules/Networks.jsx @@ -33,7 +33,7 @@ export default function Networks({ small, hide }) { return ( - + {basics.profiles.map(profile => ( { - useStaticQuery.mockImplementationOnce(() => { - return { - ...data - } - }) -}) describe('Networks', () => { it('renders correctly from data file values', () => { - const { social } = data.metaYaml - const { container, getByTestId } = render() - + const { container } = render() expect(container.firstChild).toBeInTheDocument() expect(container.firstChild.nodeName).toBe('ASIDE') - expect(getByTestId('network-email').href).toBe(social.Email) - expect(getByTestId('network-blog').href).toBe(social.Blog + '/') - expect(getByTestId('network-twitter').href).toBe(social.Twitter) - expect(getByTestId('network-github').href).toBe(social.GitHub) - expect(getByTestId('network-dribbble').href).toBe(social.Dribbble) }) it('renders correctly in small variant', () => { const { container } = render() - expect(container.firstChild).toBeInTheDocument() expect(container.querySelector('.small')).toBeInTheDocument() }) it('can be hidden', () => { const { container } = render() - expect(container.firstChild).not.toBeInTheDocument() }) }) diff --git a/src/components/organisms/Footer.test.jsx b/src/components/organisms/Footer.test.jsx index f39c375..8a6213d 100644 --- a/src/components/organisms/Footer.test.jsx +++ b/src/components/organisms/Footer.test.jsx @@ -1,19 +1,8 @@ import React from 'react' import { render } from '@testing-library/react' -import { useStaticQuery } from 'gatsby' import Footer from './Footer' -import data from '../../../jest/__fixtures__/meta.json' describe('Footer', () => { - beforeEach(() => { - useStaticQuery.mockImplementation(() => { - return { - ...data, - portfolioJson: { bugs: '' } - } - }) - }) - it('renders correctly', () => { const { container } = render(