diff --git a/jest/__fixtures__/projectImageFiles.json b/jest/__fixtures__/projectImageFiles.json new file mode 100644 index 0000000..4aa9d71 --- /dev/null +++ b/jest/__fixtures__/projectImageFiles.json @@ -0,0 +1,361 @@ +{ + "projectImageFiles": { + "edges": [ + { + "node": { + "name": "meta" + } + }, + { + "node": { + "name": "projects" + } + }, + { + "node": { + "name": "chartmogul-05" + } + }, + { + "node": { + "name": "ezeep-05" + } + }, + { + "node": { + "name": "ezeep-06" + } + }, + { + "node": { + "name": "ipixelpad-01" + } + }, + { + "node": { + "name": "allinnia-02" + } + }, + { + "node": { + "name": "ezeep-03" + } + }, + { + "node": { + "name": "ipdb-04" + } + }, + { + "node": { + "name": "allinnia-03" + } + }, + { + "node": { + "name": "ezeep-07" + } + }, + { + "node": { + "name": "unihalle-03" + } + }, + { + "node": { + "name": "oceanprotocol-05" + } + }, + { + "node": { + "name": "apertureloupe-01" + } + }, + { + "node": { + "name": "coffeecup-01" + } + }, + { + "node": { + "name": "ipdb-01" + } + }, + { + "node": { + "name": "ezeep-04" + } + }, + { + "node": { + "name": "mrreader-01" + } + }, + { + "node": { + "name": "mrreader-02" + } + }, + { + "node": { + "name": "unihalle-02" + } + }, + { + "node": { + "name": "chartmogul-02" + } + }, + { + "node": { + "name": "ipdb-03" + } + }, + { + "node": { + "name": "bigchaindb-02" + } + }, + { + "node": { + "name": "chartmogul-03" + } + }, + { + "node": { + "name": "ipdb-02" + } + }, + { + "node": { + "name": "oceanprotocol-02" + } + }, + { + "node": { + "name": "bigchaindb-03" + } + }, + { + "node": { + "name": "ezeep-08" + } + }, + { + "node": { + "name": "ezeep-02" + } + }, + { + "node": { + "name": "oceanprotocol-03" + } + }, + { + "node": { + "name": "outofwhaleoil-02" + } + }, + { + "node": { + "name": "bigchaindb-05" + } + }, + { + "node": { + "name": "oceanprotocol-04" + } + }, + { + "node": { + "name": "outofwhaleoil-01" + } + }, + { + "node": { + "name": "9984-02" + } + }, + { + "node": { + "name": "niepces-camera-obscura-01" + } + }, + { + "node": { + "name": "niepces-camera-obscura-02" + } + }, + { + "node": { + "name": "adiumeetie-01" + } + }, + { + "node": { + "name": "oceanprotocol-01" + } + }, + { + "node": { + "name": "outofwhaleoil-03" + } + }, + { + "node": { + "name": "unihalle-01" + } + }, + { + "node": { + "name": "ezeep-01" + } + }, + { + "node": { + "name": "chartmogul-01" + } + }, + { + "node": { + "name": "bigchaindb-04" + } + }, + { + "node": { + "name": "9984-01" + } + }, + { + "node": { + "name": "chartmogul-04" + } + }, + { + "node": { + "name": "mrreader-03" + } + }, + { + "node": { + "name": "bigchaindb-01" + } + }, + { + "node": { + "name": "projectpurple-01" + } + }, + { + "node": { + "name": "biv-01" + } + }, + { + "node": { + "name": "sharethemeal-01" + } + }, + { + "node": { + "name": "allinnia-01" + } + }, + { + "node": { + "name": "package" + } + }, + { + "node": { + "name": "day" + } + }, + { + "node": { + "name": "download" + } + }, + { + "node": { + "name": "blog" + } + }, + { + "node": { + "name": "dribbble" + } + }, + { + "node": { + "name": "email" + } + }, + { + "node": { + "name": "favicon" + } + }, + { + "node": { + "name": "github" + } + }, + { + "node": { + "name": "index" + } + }, + { + "node": { + "name": "info" + } + }, + { + "node": { + "name": "logo" + } + }, + { + "node": { + "name": "images" + } + }, + { + "node": { + "name": "night" + } + }, + { + "node": { + "name": "link" + } + }, + { + "node": { + "name": "twitter-card" + } + }, + { + "node": { + "name": "twitter" + } + }, + { + "node": { + "name": "styleguide" + } + }, + { + "node": { + "name": "github-header" + } + }, + { + "node": { + "name": "avatar" + } + } + ] + } +} diff --git a/src/components/atoms/Vcard.test.jsx b/src/components/atoms/Vcard.test.jsx index d346120..39bd2b4 100644 --- a/src/components/atoms/Vcard.test.jsx +++ b/src/components/atoms/Vcard.test.jsx @@ -1,5 +1,5 @@ import React from 'react' -import { render } from 'react-testing-library' +import { render, fireEvent, waitForElement } from 'react-testing-library' import { StaticQuery } from 'gatsby' import Vcard, { constructVcard, toDataURL, init } from './Vcard' import data from '../../../jest/__fixtures__/meta.json' @@ -16,6 +16,13 @@ describe('Vcard', () => { expect(container.firstChild).toBeInTheDocument() }) + it('Button click starts download', async () => { + const { container } = render() + fireEvent.click(container.firstChild) + await waitForElement(() => global.URL.createObjectURL) + expect(global.URL.createObjectURL).toHaveBeenCalledTimes(1) + }) + it('combined vCard download process finishes', async () => { await init(data.contentYaml) expect(global.URL.createObjectURL).toHaveBeenCalledTimes(1) diff --git a/src/components/molecules/ProjectTechstack.test.jsx b/src/components/molecules/ProjectTechstack.test.jsx new file mode 100644 index 0000000..66d9644 --- /dev/null +++ b/src/components/molecules/ProjectTechstack.test.jsx @@ -0,0 +1,14 @@ +import React from 'react' +import { render } from 'react-testing-library' +import ProjectTechstack from './ProjectTechstack' + +describe('ProjectTechstack', () => { + const techstack = ['CSS'] + + it('renders correctly', () => { + const { container } = render() + + expect(container.firstChild).toBeInTheDocument() + expect(container.querySelector('li').textContent).toBe('CSS') + }) +}) diff --git a/src/components/organisms/Header.test.jsx b/src/components/organisms/Header.test.jsx index 5c26c66..64f6416 100644 --- a/src/components/organisms/Header.test.jsx +++ b/src/components/organisms/Header.test.jsx @@ -19,4 +19,13 @@ describe('Header', () => { ) expect(container.firstChild).toBeInTheDocument() }) + + it('Availability can be hidden', () => { + const { container } = render( + null }}> +
+ + ) + expect(container.querySelector('.availability')).not.toBeInTheDocument() + }) }) diff --git a/src/pages/__tests__/index.test.jsx b/src/pages/__tests__/index.test.jsx new file mode 100644 index 0000000..a08e405 --- /dev/null +++ b/src/pages/__tests__/index.test.jsx @@ -0,0 +1,23 @@ +import React from 'react' +import { render } from 'react-testing-library' +import { StaticQuery } from 'gatsby' +import Home from '../index' +import meta from '../../../jest/__fixtures__/meta.json' +import projects from '../../../jest/__fixtures__/projects.json' +import projectImageFiles from '../../../jest/__fixtures__/projectImageFiles.json' + +beforeEach(() => { + StaticQuery.mockImplementation(({ render }) => render({ ...meta })) +}) + +describe('Home', () => { + const data = { + ...projects, + ...projectImageFiles + } + + it('renders correctly from data file values', () => { + const { container } = render() + expect(container.firstChild).toBeInTheDocument() + }) +})