Applying Layout component in gatsby-browser

This commit is contained in:
Jeff Avallone 2019-01-05 20:16:29 -05:00
parent 837b8d77df
commit 7d7916baf0
14 changed files with 684 additions and 649 deletions

View File

@ -1,8 +1,16 @@
import React from 'react';
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import Layout from 'components/Layout';
import 'site.css'; import 'site.css';
export const onClientEntry = () => { export const onClientEntry = () => {
Sentry.getCurrentHub().getClient().getOptions().enabled = Sentry.getCurrentHub().getClient().getOptions().enabled =
(navigator.doNotTrack !== '1' && window.doNotTrack !== '1'); (navigator.doNotTrack !== '1' && window.doNotTrack !== '1');
}; };
// eslint-disable-next-line react/prop-types
export const wrapPageElement = ({ element }) => {
return <Layout>{ element }</Layout>;
};

8
gatsby-ssr.js Normal file
View File

@ -0,0 +1,8 @@
import React from 'react';
import Layout from 'components/Layout';
// eslint-disable-next-line react/prop-types
export const wrapPageElement = ({ element }) => {
return <Layout>{ element }</Layout>;
};

View File

@ -20,14 +20,6 @@ ShallowWrapper {
"nodeType": "class", "nodeType": "class",
"props": Object { "props": Object {
"children": Array [ "children": Array [
<HelmetWrapper
defer={true}
encodeSpecialCharacters={true}
>
<title>
Regexper
</title>
</HelmetWrapper>,
<Header />, <Header />,
<SentryBoundary> <SentryBoundary>
Example content Example content
@ -37,31 +29,6 @@ ShallowWrapper {
}, },
"ref": null, "ref": null,
"rendered": Array [ "rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper",
},
"ref": null,
"rendered": "Regexper",
"type": "title",
},
"type": [Function],
},
Object { Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
@ -101,14 +68,6 @@ ShallowWrapper {
"nodeType": "class", "nodeType": "class",
"props": Object { "props": Object {
"children": Array [ "children": Array [
<HelmetWrapper
defer={true}
encodeSpecialCharacters={true}
>
<title>
Regexper
</title>
</HelmetWrapper>,
<Header />, <Header />,
<SentryBoundary> <SentryBoundary>
Example content Example content
@ -118,229 +77,6 @@ ShallowWrapper {
}, },
"ref": null, "ref": null,
"rendered": Array [ "rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper",
},
"ref": null,
"rendered": "Regexper",
"type": "title",
},
"type": [Function],
},
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": "Example content",
},
"ref": null,
"rendered": "Example content",
"type": [Function],
},
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
],
"type": [Function],
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
"lifecycles": Object {
"componentDidUpdate": Object {
"onSetState": true,
},
"getDerivedStateFromProps": true,
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
},
},
},
},
},
}
`;
exports[`Layout rendering with a title 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Layout
title="Testing"
>
Example content
</Layout>,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateError": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": Array [
<HelmetWrapper
defer={true}
encodeSpecialCharacters={true}
>
<title>
Regexper - Testing
</title>
</HelmetWrapper>,
<Header />,
<SentryBoundary>
Example content
</SentryBoundary>,
<Footer />,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper - Testing
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper - Testing",
},
"ref": null,
"rendered": "Regexper - Testing",
"type": "title",
},
"type": [Function],
},
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": "Example content",
},
"ref": null,
"rendered": "Example content",
"type": [Function],
},
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
],
"type": [Function],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": Array [
<HelmetWrapper
defer={true}
encodeSpecialCharacters={true}
>
<title>
Regexper - Testing
</title>
</HelmetWrapper>,
<Header />,
<SentryBoundary>
Example content
</SentryBoundary>,
<Footer />,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper - Testing
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper - Testing",
},
"ref": null,
"rendered": "Regexper - Testing",
"type": "title",
},
"type": [Function],
},
Object { Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,

View File

@ -1,15 +1,11 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
import SentryBoundary from 'components/SentryBoundary'; import SentryBoundary from 'components/SentryBoundary';
import Header from 'components/Header'; import Header from 'components/Header';
import Footer from 'components/Footer'; import Footer from 'components/Footer';
const Layout = ({ title, children }) => <SentryBoundary> const Layout = ({ children }) => <SentryBoundary>
<Helmet>
<title>{ title ? `Regexper - ${ title }` : 'Regexper' }</title>
</Helmet>
<Header /> <Header />
<SentryBoundary> <SentryBoundary>
{ children } { children }
@ -18,7 +14,6 @@ const Layout = ({ title, children }) => <SentryBoundary>
</SentryBoundary>; </SentryBoundary>;
Layout.propTypes = { Layout.propTypes = {
title: PropTypes.string,
children: PropTypes.oneOfType([ children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node), PropTypes.arrayOf(PropTypes.node),
PropTypes.node PropTypes.node

View File

@ -12,13 +12,4 @@ describe('Layout', () => {
); );
expect(component).toMatchSnapshot(); expect(component).toMatchSnapshot();
}); });
test('rendering with a title', () => {
const component = shallow(
<Layout title="Testing">
Example content
</Layout>
);
expect(component).toMatchSnapshot();
});
}); });

View File

@ -0,0 +1,171 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Metadata rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Metadata />,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateError": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper",
},
"ref": null,
"rendered": "Regexper",
"type": "title",
},
"type": [Function],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper",
},
"ref": null,
"rendered": "Regexper",
"type": "title",
},
"type": [Function],
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
"lifecycles": Object {
"componentDidUpdate": Object {
"onSetState": true,
},
"getDerivedStateFromProps": true,
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
},
},
},
},
},
}
`;
exports[`Metadata rendering with a title 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Metadata
title="Testing"
/>,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateError": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper - Testing
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper - Testing",
},
"ref": null,
"rendered": "Regexper - Testing",
"type": "title",
},
"type": [Function],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <title>
Regexper - Testing
</title>,
"defer": true,
"encodeSpecialCharacters": true,
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "Regexper - Testing",
},
"ref": null,
"rendered": "Regexper - Testing",
"type": "title",
},
"type": [Function],
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
"lifecycles": Object {
"componentDidUpdate": Object {
"onSetState": true,
},
"getDerivedStateFromProps": true,
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
},
},
},
},
},
}
`;

View File

@ -0,0 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
const Metadata = ({ title }) => (
<Helmet>
<title>{ title ? `Regexper - ${ title }` : 'Regexper' }</title>
</Helmet>
);
Metadata.propTypes = {
title: PropTypes.string
};
export default Metadata;

View File

@ -0,0 +1,20 @@
import React from 'react';
import { shallow } from 'enzyme';
import Metadata from 'components/Metadata';
describe('Metadata', () => {
test('rendering', () => {
const component = shallow(
<Metadata />
);
expect(component).toMatchSnapshot();
});
test('rendering with a title', () => {
const component = shallow(
<Metadata title="Testing" />
);
expect(component).toMatchSnapshot();
});
});

View File

@ -1,12 +1,13 @@
import React from 'react'; import React from 'react';
import Layout from 'components/Layout'; import Metadata from 'components/Metadata';
import Message from 'components/Message'; import Message from 'components/Message';
const ErrorPage = () => <Layout title="Page Not Found"> const ErrorPage = () => <>
<Metadata title="Page Not Found" />
<Message type="error" heading="404 Page Not Found"> <Message type="error" heading="404 Page Not Found">
<p>The page you have requrested could not be found.</p> <p>The page you have requrested could not be found.</p>
</Message> </Message>
</Layout>; </>;
export default ErrorPage; export default ErrorPage;

View File

@ -17,7 +17,11 @@ ShallowWrapper {
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
"props": Object { "props": Object {
"children": <Message "children": Array [
<Metadata
title="Page Not Found"
/>,
<Message
heading="404 Page Not Found" heading="404 Page Not Found"
type="error" type="error"
> >
@ -25,10 +29,22 @@ ShallowWrapper {
The page you have requrested could not be found. The page you have requrested could not be found.
</p> </p>
</Message>, </Message>,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"title": "Page Not Found", "title": "Page Not Found",
}, },
"ref": null, "ref": null,
"rendered": Object { "rendered": null,
"type": [Function],
},
Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
@ -53,7 +69,8 @@ ShallowWrapper {
}, },
"type": [Function], "type": [Function],
}, },
"type": [Function], ],
"type": Symbol(react.fragment),
}, },
Symbol(enzyme.__nodes__): Array [ Symbol(enzyme.__nodes__): Array [
Object { Object {
@ -61,7 +78,11 @@ ShallowWrapper {
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
"props": Object { "props": Object {
"children": <Message "children": Array [
<Metadata
title="Page Not Found"
/>,
<Message
heading="404 Page Not Found" heading="404 Page Not Found"
type="error" type="error"
> >
@ -69,10 +90,22 @@ ShallowWrapper {
The page you have requrested could not be found. The page you have requrested could not be found.
</p> </p>
</Message>, </Message>,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"title": "Page Not Found", "title": "Page Not Found",
}, },
"ref": null, "ref": null,
"rendered": Object { "rendered": null,
"type": [Function],
},
Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
@ -97,7 +130,8 @@ ShallowWrapper {
}, },
"type": [Function], "type": [Function],
}, },
"type": [Function], ],
"type": Symbol(react.fragment),
}, },
], ],
Symbol(enzyme.__options__): Object { Symbol(enzyme.__options__): Object {

View File

@ -18,6 +18,7 @@ ShallowWrapper {
"nodeType": "function", "nodeType": "function",
"props": Object { "props": Object {
"children": Array [ "children": Array [
<Metadata />,
<noscript> <noscript>
<Message <Message
heading="JavaScript Required" heading="JavaScript Required"
@ -44,6 +45,15 @@ ShallowWrapper {
}, },
"ref": null, "ref": null,
"rendered": Array [ "rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
Object { Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
@ -154,7 +164,7 @@ ShallowWrapper {
"type": "div", "type": "div",
}, },
], ],
"type": [Function], "type": Symbol(react.fragment),
}, },
Symbol(enzyme.__nodes__): Array [ Symbol(enzyme.__nodes__): Array [
Object { Object {
@ -163,6 +173,7 @@ ShallowWrapper {
"nodeType": "function", "nodeType": "function",
"props": Object { "props": Object {
"children": Array [ "children": Array [
<Metadata />,
<noscript> <noscript>
<Message <Message
heading="JavaScript Required" heading="JavaScript Required"
@ -189,6 +200,15 @@ ShallowWrapper {
}, },
"ref": null, "ref": null,
"rendered": Array [ "rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
Object { Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
@ -299,7 +319,7 @@ ShallowWrapper {
"type": "div", "type": "div",
}, },
], ],
"type": [Function], "type": Symbol(react.fragment),
}, },
], ],
Symbol(enzyme.__options__): Object { Symbol(enzyme.__options__): Object {

View File

@ -17,7 +17,11 @@ ShallowWrapper {
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
"props": Object { "props": Object {
"children": <Message "children": Array [
<Metadata
title="Privacy Policy"
/>,
<Message
heading="Privacy Policy" heading="Privacy Policy"
type="info" type="info"
> >
@ -64,10 +68,22 @@ ShallowWrapper {
Regexper is not supported by ad revenue or sales of any kind. Regexper is not supported by ad revenue or sales of any kind.
</p> </p>
</Message>, </Message>,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"title": "Privacy Policy", "title": "Privacy Policy",
}, },
"ref": null, "ref": null,
"rendered": Object { "rendered": null,
"type": [Function],
},
Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
@ -314,7 +330,8 @@ ShallowWrapper {
], ],
"type": [Function], "type": [Function],
}, },
"type": [Function], ],
"type": Symbol(react.fragment),
}, },
Symbol(enzyme.__nodes__): Array [ Symbol(enzyme.__nodes__): Array [
Object { Object {
@ -322,7 +339,11 @@ ShallowWrapper {
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
"props": Object { "props": Object {
"children": <Message "children": Array [
<Metadata
title="Privacy Policy"
/>,
<Message
heading="Privacy Policy" heading="Privacy Policy"
type="info" type="info"
> >
@ -369,10 +390,22 @@ ShallowWrapper {
Regexper is not supported by ad revenue or sales of any kind. Regexper is not supported by ad revenue or sales of any kind.
</p> </p>
</Message>, </Message>,
],
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"title": "Privacy Policy", "title": "Privacy Policy",
}, },
"ref": null, "ref": null,
"rendered": Object { "rendered": null,
"type": [Function],
},
Object {
"instance": null, "instance": null,
"key": undefined, "key": undefined,
"nodeType": "function", "nodeType": "function",
@ -619,7 +652,8 @@ ShallowWrapper {
], ],
"type": [Function], "type": [Function],
}, },
"type": [Function], ],
"type": Symbol(react.fragment),
}, },
], ],
Symbol(enzyme.__options__): Object { Symbol(enzyme.__options__): Object {

View File

@ -1,10 +1,11 @@
import React from 'react'; import React from 'react';
import { Link } from 'gatsby'; import { Link } from 'gatsby';
import Layout from 'components/Layout'; import Metadata from 'components/Metadata';
import Message from 'components/Message'; import Message from 'components/Message';
const IndexPage = () => <Layout> const IndexPage = () => <>
<Metadata/>
<noscript> <noscript>
<Message type="error" heading="JavaScript Required"> <Message type="error" heading="JavaScript Required">
<p>You need JavaScript to use Regexper.</p> <p>You need JavaScript to use Regexper.</p>
@ -13,6 +14,6 @@ const IndexPage = () => <Layout>
</Message> </Message>
</noscript> </noscript>
<div>Hello world</div> <div>Hello world</div>
</Layout>; </>;
export default IndexPage; export default IndexPage;

View File

@ -1,9 +1,10 @@
import React from 'react'; import React from 'react';
import Layout from 'components/Layout'; import Metadata from 'components/Metadata';
import Message from 'components/Message'; import Message from 'components/Message';
const PrivacyPage = () => <Layout title="Privacy Policy"> const PrivacyPage = () => <>
<Metadata title="Privacy Policy" />
<Message type="info" heading="Privacy Policy"> <Message type="info" heading="Privacy Policy">
<p> <p>
Regexper and the tools used to create it are all open source. If you are Regexper and the tools used to create it are all open source. If you are
@ -41,6 +42,6 @@ const PrivacyPage = () => <Layout title="Privacy Policy">
Regexper is not supported by ad revenue or sales of any kind. Regexper is not supported by ad revenue or sales of any kind.
</p> </p>
</Message> </Message>
</Layout>; </>;
export default PrivacyPage; export default PrivacyPage;