From 95a6709ec02e42c1bcaa871186a411e52da17f58 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 11 Feb 2018 07:28:34 -0500 Subject: [PATCH] Pulling most of the page template into a component --- src/components/PageTemplate.js | 57 +++++++ src/components/PageTemplate.test.js | 24 +++ .../__snapshots__/PageTemplate.test.js.snap | 156 ++++++++++++++++++ src/template.js | 60 ++----- 4 files changed, 247 insertions(+), 50 deletions(-) create mode 100644 src/components/PageTemplate.js create mode 100644 src/components/PageTemplate.test.js create mode 100644 src/components/__snapshots__/PageTemplate.test.js.snap diff --git a/src/components/PageTemplate.js b/src/components/PageTemplate.js new file mode 100644 index 0000000..ad00123 --- /dev/null +++ b/src/components/PageTemplate.js @@ -0,0 +1,57 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import pkg from '../../package.json'; + +import GithubIcon from 'feather-icons/dist/icons/github.svg'; + +const PageTemplate = ({ title, children }) => ( + + + + + + + + + Regexper{ title && (' - ' + title) } + + +
+

+ Regexper +

+ + +
+ + { children } + + + + +); + +PageTemplate.propTypes = { + title: PropTypes.string, + children: PropTypes.element +}; + +export default PageTemplate; diff --git a/src/components/PageTemplate.test.js b/src/components/PageTemplate.test.js new file mode 100644 index 0000000..8b272de --- /dev/null +++ b/src/components/PageTemplate.test.js @@ -0,0 +1,24 @@ +import React from 'react'; +import renderer from 'react-test-renderer'; + +import PageTemplate from './PageTemplate'; + +test('PageTemplate rendering', () => { + const component = renderer.create( + +

Content

+
+ ); + let tree = component.toJSON(); + expect(tree).toMatchSnapshot(); +}); + +test('PageTemplate rendering with title', () => { + const component = renderer.create( + +

Content

+
+ ); + let tree = component.toJSON(); + expect(tree).toMatchSnapshot(); +}); diff --git a/src/components/__snapshots__/PageTemplate.test.js.snap b/src/components/__snapshots__/PageTemplate.test.js.snap new file mode 100644 index 0000000..aa7bb7e --- /dev/null +++ b/src/components/__snapshots__/PageTemplate.test.js.snap @@ -0,0 +1,156 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`PageTemplate rendering 1`] = ` + + + + + + + + Regexper + + + +
+

+ + Regexper + +

+ +
+

+ Content +

+ + + +`; + +exports[`PageTemplate rendering with title 1`] = ` + + + + + + + + Regexper + - Example + + + +
+

+ + Regexper + +

+ +
+

+ Content +

+ + + +`; diff --git a/src/template.js b/src/template.js index efc2517..2928159 100644 --- a/src/template.js +++ b/src/template.js @@ -2,59 +2,19 @@ import 'babel-register'; import React from 'react'; import ReactDOMServer from 'react-dom/server'; -import pkg from '../package.json'; - +import PageTemplate from './components/PageTemplate'; import Message from './components/Message'; import AlertIcon from 'feather-icons/dist/icons/alert-octagon.svg'; -import GithubIcon from 'feather-icons/dist/icons/github.svg'; module.exports = '' + ReactDOMServer.renderToString( - - - - - + + - - - Regexper - - -
-

- Regexper -

- - -
- - - -
- - - - +
+
);