mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-10-31 23:35:29 +01:00
fix tests
This commit is contained in:
parent
fda8949627
commit
7d72375fab
@ -1,5 +1,5 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React from 'react'
|
||||||
import { StaticQuery, graphql } from 'gatsby'
|
import { graphql, useStaticQuery } from 'gatsby'
|
||||||
import saveAs from 'file-saver'
|
import saveAs from 'file-saver'
|
||||||
import vCard from 'vcf'
|
import vCard from 'vcf'
|
||||||
|
|
||||||
@ -31,33 +31,24 @@ const query = graphql`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
export default class Vcard extends PureComponent {
|
export default function Vcard() {
|
||||||
render() {
|
const { metaYaml } = useStaticQuery(query)
|
||||||
return (
|
|
||||||
<StaticQuery
|
|
||||||
query={query}
|
|
||||||
render={data => {
|
|
||||||
const meta = data.metaYaml
|
|
||||||
|
|
||||||
const handleAddressbookClick = e => {
|
const handleAddressbookClick = e => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
init(meta)
|
init(metaYaml)
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
// href is kinda fake, only there for usability
|
|
||||||
// so user knows what to expect when hovering the link before clicking
|
|
||||||
href={meta.addressbook}
|
|
||||||
onClick={handleAddressbookClick}
|
|
||||||
>
|
|
||||||
Add to addressbook
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
// href is kinda fake, only there for usability
|
||||||
|
// so user knows what to expect when hovering the link before clicking
|
||||||
|
href={metaYaml.addressbook}
|
||||||
|
onClick={handleAddressbookClick}
|
||||||
|
>
|
||||||
|
Add to addressbook
|
||||||
|
</a>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const init = async meta => {
|
export const init = async meta => {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render, fireEvent, waitForElement } from '@testing-library/react'
|
import { render, fireEvent, waitForElement } from '@testing-library/react'
|
||||||
import { StaticQuery } from 'gatsby'
|
import { useStaticQuery } from 'gatsby'
|
||||||
import Vcard, { constructVcard, toDataURL, init } from './Vcard'
|
import Vcard, { constructVcard, toDataURL, init } from './Vcard'
|
||||||
import data from '../../../jest/__fixtures__/meta.json'
|
import data from '../../../jest/__fixtures__/meta.json'
|
||||||
|
|
||||||
describe('Vcard', () => {
|
describe('Vcard', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
StaticQuery.mockImplementationOnce(({ render }) => render({ ...data }))
|
useStaticQuery.mockImplementationOnce(() => {
|
||||||
|
return {
|
||||||
|
...data
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
global.URL.createObjectURL = jest.fn()
|
global.URL.createObjectURL = jest.fn()
|
||||||
})
|
})
|
||||||
|
@ -21,8 +21,8 @@ LogoUnit.propTypes = {
|
|||||||
|
|
||||||
export default function LogoUnit({ minimal }) {
|
export default function LogoUnit({ minimal }) {
|
||||||
const data = useStaticQuery(query)
|
const data = useStaticQuery(query)
|
||||||
const Animation = posed.div(moveInBottom)
|
|
||||||
const { title, tagline } = data.metaYaml
|
const { title, tagline } = data.metaYaml
|
||||||
|
const Animation = posed.div(moveInBottom)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animation>
|
<Animation>
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import { render } from '@testing-library/react'
|
||||||
import { StaticQuery } from 'gatsby'
|
import { useStaticQuery } from 'gatsby'
|
||||||
import LogoUnit from './LogoUnit'
|
import LogoUnit from './LogoUnit'
|
||||||
import data from '../../../jest/__fixtures__/meta.json'
|
import data from '../../../jest/__fixtures__/meta.json'
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
StaticQuery.mockImplementationOnce(({ render }) => render({ ...data }))
|
useStaticQuery.mockImplementationOnce(() => {
|
||||||
|
return {
|
||||||
|
...data
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('LogoUnit', () => {
|
describe('LogoUnit', () => {
|
||||||
@ -26,8 +30,6 @@ describe('LogoUnit', () => {
|
|||||||
const { container } = render(<LogoUnit minimal={true} />)
|
const { container } = render(<LogoUnit minimal={true} />)
|
||||||
|
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
expect(container.querySelector('.logounit').className).toMatch(
|
expect(container.querySelector('.minimal')).toBeInTheDocument()
|
||||||
/logounit minimal/
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,11 @@ import Networks from './Networks'
|
|||||||
import data from '../../../jest/__fixtures__/meta.json'
|
import data from '../../../jest/__fixtures__/meta.json'
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
useStaticQuery.mockImplementationOnce(() => ({ ...data }))
|
useStaticQuery.mockImplementationOnce(() => {
|
||||||
|
return {
|
||||||
|
...data
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Networks', () => {
|
describe('Networks', () => {
|
||||||
@ -26,7 +30,7 @@ describe('Networks', () => {
|
|||||||
const { container } = render(<Networks small={true} />)
|
const { container } = render(<Networks small={true} />)
|
||||||
|
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
expect(container.firstChild.className).toMatch(/networks small/)
|
expect(container.querySelector('.small')).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can be hidden', () => {
|
it('can be hidden', () => {
|
||||||
|
@ -52,10 +52,8 @@ FooterMarkup.propTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Footer() {
|
export default function Footer() {
|
||||||
const data = useStaticQuery(query)
|
const { metaYaml, portfolioJson } = useStaticQuery(query)
|
||||||
const pkg = data.portfolioJson
|
|
||||||
const meta = data.metaYaml
|
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear()
|
||||||
|
|
||||||
return <FooterMarkup year={year} pkg={pkg} meta={meta} />
|
return <FooterMarkup year={year} pkg={portfolioJson} meta={metaYaml} />
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import { render } from '@testing-library/react'
|
||||||
import { StaticQuery, useStaticQuery } from 'gatsby'
|
import { useStaticQuery } from 'gatsby'
|
||||||
import Footer from './Footer'
|
import Footer from './Footer'
|
||||||
import data from '../../../jest/__fixtures__/meta.json'
|
import data from '../../../jest/__fixtures__/meta.json'
|
||||||
|
|
||||||
describe('Header', () => {
|
describe('Footer', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
StaticQuery.mockImplementation(({ render }) =>
|
useStaticQuery.mockImplementation(() => {
|
||||||
render({
|
return {
|
||||||
...data,
|
...data,
|
||||||
portfolioJson: { bugs: '' }
|
portfolioJson: { bugs: '' }
|
||||||
})
|
}
|
||||||
)
|
})
|
||||||
useStaticQuery.mockImplementation(() => ({ ...data }))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { render } from '@testing-library/react'
|
import { render } from '@testing-library/react'
|
||||||
import { StaticQuery, useStaticQuery } from 'gatsby'
|
import { useStaticQuery } from 'gatsby'
|
||||||
import Header from './Header'
|
import Header from './Header'
|
||||||
import Context from '../../store/createContext'
|
import Context from '../../store/createContext'
|
||||||
import data from '../../../jest/__fixtures__/meta.json'
|
import data from '../../../jest/__fixtures__/meta.json'
|
||||||
|
|
||||||
describe('Header', () => {
|
describe('Header', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
StaticQuery.mockImplementation(({ render }) => render({ ...data }))
|
useStaticQuery.mockImplementation(() => {
|
||||||
useStaticQuery.mockImplementation(() => ({ ...data }))
|
return {
|
||||||
|
...data
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user