mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-01-03 18:35:00 +01:00
add some tests
This commit is contained in:
parent
7f3a94d921
commit
09a119f78c
@ -27,3 +27,8 @@ typekitID: dtg3zui
|
||||
# Analytics tools
|
||||
matomoUrl: https://analytics.kremalicious.com
|
||||
matomoSite: 2
|
||||
|
||||
allowedHosts:
|
||||
- matthiaskretschmann.com
|
||||
- beta.matthiaskretschmann.com
|
||||
- localhost
|
||||
|
@ -35,6 +35,11 @@
|
||||
"addressbook": "/matthias-kretschmann.vcf",
|
||||
"typekitID": "dtg3zui",
|
||||
"matomoUrl": "https://analytics.kremalicious.com",
|
||||
"matomoSite": 2
|
||||
"matomoSite": 2,
|
||||
"allowedHosts": [
|
||||
"matthiaskretschmann.com",
|
||||
"beta.matthiaskretschmann.com",
|
||||
"localhost"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import posed, { PoseGroup } from 'react-pose'
|
||||
import { StaticQuery, graphql } from 'gatsby'
|
||||
import { fadeIn } from './atoms/Transitions'
|
||||
import Typekit from './atoms/Typekit'
|
||||
import HostnameCheck from './atoms/HostnameCheck'
|
||||
@ -16,20 +17,18 @@ import styles from './Layout.module.scss'
|
||||
const timeout = 250
|
||||
const RoutesContainer = posed.div(fadeIn)
|
||||
|
||||
export default class Layout extends PureComponent {
|
||||
static propTypes = {
|
||||
children: PropTypes.any.isRequired,
|
||||
location: PropTypes.object.isRequired
|
||||
const query = graphql`
|
||||
query {
|
||||
contentYaml {
|
||||
allowedHosts
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
render() {
|
||||
const { children, location } = this.props
|
||||
const isHomepage = location.pathname === '/'
|
||||
|
||||
return (
|
||||
const LayoutMarkup = ({ children, isHomepage, allowedHosts }) => (
|
||||
<>
|
||||
<Typekit />
|
||||
<HostnameCheck />
|
||||
<HostnameCheck allowedHosts={allowedHosts} />
|
||||
|
||||
<PoseGroup animateOnMount={true}>
|
||||
<RoutesContainer
|
||||
@ -45,5 +44,41 @@ export default class Layout extends PureComponent {
|
||||
<Footer />
|
||||
</>
|
||||
)
|
||||
|
||||
LayoutMarkup.propTypes = {
|
||||
children: PropTypes.any.isRequired,
|
||||
isHomepage: PropTypes.bool.isRequired,
|
||||
allowedHosts: PropTypes.array.isRequired,
|
||||
location: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
export default class Layout extends PureComponent {
|
||||
static propTypes = {
|
||||
children: PropTypes.any.isRequired,
|
||||
location: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
render() {
|
||||
const { children, location } = this.props
|
||||
const isHomepage = location.pathname === '/'
|
||||
|
||||
return (
|
||||
<StaticQuery
|
||||
query={query}
|
||||
render={data => {
|
||||
const { allowedHosts } = data.contentYaml
|
||||
|
||||
return (
|
||||
<LayoutMarkup
|
||||
isHomepage={isHomepage}
|
||||
allowedHosts={allowedHosts}
|
||||
location={location}
|
||||
>
|
||||
{children}
|
||||
</LayoutMarkup>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import Helmet from 'react-helmet'
|
||||
import styles from './HostnameCheck.module.scss'
|
||||
|
||||
const allowedHosts = [
|
||||
'matthiaskretschmann.com',
|
||||
'beta.matthiaskretschmann.com',
|
||||
'localhost'
|
||||
]
|
||||
export default class HostnameCheck extends PureComponent {
|
||||
static propTypes = {
|
||||
allowedHosts: PropTypes.array.isRequired
|
||||
}
|
||||
|
||||
export default class HostnameInfo extends PureComponent {
|
||||
checkAllowedHost = () => {
|
||||
if (typeof window !== 'undefined' && window.location) {
|
||||
return allowedHosts.includes(window.location.hostname)
|
||||
return this.props.allowedHosts.includes(window.location.hostname)
|
||||
}
|
||||
}
|
||||
|
||||
|
22
src/components/atoms/HostnameCheck.test.jsx
Normal file
22
src/components/atoms/HostnameCheck.test.jsx
Normal file
@ -0,0 +1,22 @@
|
||||
import React from 'react'
|
||||
import { render } from 'react-testing-library'
|
||||
import HostnameCheck from './HostnameCheck'
|
||||
|
||||
describe('HostnameCheck', () => {
|
||||
it('can access window.location', () => {
|
||||
expect(window).not.toBe(undefined)
|
||||
expect(window.location).not.toBe(undefined)
|
||||
})
|
||||
|
||||
it('renders correctly', () => {
|
||||
const allowedHosts = ['hello.com']
|
||||
const { container } = render(<HostnameCheck allowedHosts={allowedHosts} />)
|
||||
expect(container.firstChild).toHaveTextContent('do a remix')
|
||||
})
|
||||
|
||||
it('does not render if on correct hostname', () => {
|
||||
const allowedHosts = ['localhost']
|
||||
const { container } = render(<HostnameCheck allowedHosts={allowedHosts} />)
|
||||
expect(container.firstChild).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user