Reworking internal component naming for clarity

This commit is contained in:
Jeff Avallone 2019-01-06 13:25:33 -05:00
parent 618b21bb93
commit bf35f26d5b
22 changed files with 79 additions and 243 deletions

View File

@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Footer rendering implementation 1`] = `
exports[`Footer rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <FooterImpl
Symbol(enzyme.__unrendered__): <Footer
site={
Object {
"siteMetadata": Object {
@ -488,77 +488,3 @@ ShallowWrapper {
},
}
`;
exports[`Footer rendering with query 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Footer />,
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": "function",
"props": Object {
"query": "
query FooterQuery {
site {
siteMetadata {
buildId
}
}
}
",
"render": [Function],
},
"ref": null,
"rendered": null,
"type": [MockFunction],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"query": "
query FooterQuery {
site {
siteMetadata {
buildId
}
}
}
",
"render": [Function],
},
"ref": null,
"rendered": null,
"type": [MockFunction],
},
],
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

@ -15,7 +15,7 @@ const query = graphql`
}
`;
export const FooterImpl = ({ t, site: { siteMetadata } }) => (
export const Footer = ({ t, site: { siteMetadata } }) => (
<footer className={ style.footer }>
<ul className={ style.list }>
<li>
@ -38,7 +38,7 @@ export const FooterImpl = ({ t, site: { siteMetadata } }) => (
</footer>
);
FooterImpl.propTypes = {
Footer.propTypes = {
t: PropTypes.func.isRequired,
site: PropTypes.shape({
siteMetadata: PropTypes.shape({
@ -47,9 +47,8 @@ FooterImpl.propTypes = {
}).isRequired
};
const TranslatedFooter = withNamespaces()(FooterImpl);
const Footer = () => <StaticQuery query={ query } render={ data => (
<TranslatedFooter { ...data } />
) } />;
export default Footer;
export default withNamespaces()(props => (
<StaticQuery query={ query } render={ data => (
<Footer { ...props } { ...data } />
) } />
));

View File

@ -2,19 +2,12 @@ import React from 'react';
import { shallow } from 'enzyme';
import { mockT } from 'i18n';
import Footer, { FooterImpl } from 'components/Footer';
import { Footer } from 'components/Footer';
describe('Footer', () => {
test('rendering with query', () => {
test('rendering', () => {
const component = shallow(
<Footer />
);
expect(component).toMatchSnapshot();
});
test('rendering implementation', () => {
const component = shallow(
<FooterImpl site={{ siteMetadata: { buildId: 'abc-123' } }} t={ mockT } />
<Footer site={{ siteMetadata: { buildId: 'abc-123' } }} t={ mockT } />
);
expect(component).toMatchSnapshot();
});

View File

@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Header rendering implementation 1`] = `
exports[`Header rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <HeaderImpl
Symbol(enzyme.__unrendered__): <Header
site={
Object {
"siteMetadata": Object {
@ -61,7 +61,7 @@ ShallowWrapper {
</mockConstructor>
</li>
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>
</ul>,
],
@ -127,7 +127,7 @@ ShallowWrapper {
</mockConstructor>
</li>,
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>,
],
"className": "list",
@ -247,7 +247,7 @@ ShallowWrapper {
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <LoadNamespace(LocaleSwitcherImpl) />,
"children": <LoadNamespace(LocaleSwitcher) />,
},
"ref": null,
"rendered": Object {
@ -309,7 +309,7 @@ ShallowWrapper {
</mockConstructor>
</li>
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>
</ul>,
],
@ -375,7 +375,7 @@ ShallowWrapper {
</mockConstructor>
</li>,
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>,
],
"className": "list",
@ -495,7 +495,7 @@ ShallowWrapper {
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <LoadNamespace(LocaleSwitcherImpl) />,
"children": <LoadNamespace(LocaleSwitcher) />,
},
"ref": null,
"rendered": Object {
@ -536,10 +536,10 @@ ShallowWrapper {
}
`;
exports[`Header rendering implementation with no banner 1`] = `
exports[`Header rendering with no banner 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <HeaderImpl
Symbol(enzyme.__unrendered__): <Header
site={
Object {
"siteMetadata": Object {
@ -597,7 +597,7 @@ ShallowWrapper {
</mockConstructor>
</li>
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>
</ul>,
],
@ -663,7 +663,7 @@ ShallowWrapper {
</mockConstructor>
</li>,
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>,
],
"className": "list",
@ -783,7 +783,7 @@ ShallowWrapper {
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <LoadNamespace(LocaleSwitcherImpl) />,
"children": <LoadNamespace(LocaleSwitcher) />,
},
"ref": null,
"rendered": Object {
@ -845,7 +845,7 @@ ShallowWrapper {
</mockConstructor>
</li>
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>
</ul>,
],
@ -911,7 +911,7 @@ ShallowWrapper {
</mockConstructor>
</li>,
<li>
<LoadNamespace(LocaleSwitcherImpl) />
<LoadNamespace(LocaleSwitcher) />
</li>,
],
"className": "list",
@ -1031,7 +1031,7 @@ ShallowWrapper {
"key": undefined,
"nodeType": "host",
"props": Object {
"children": <LoadNamespace(LocaleSwitcherImpl) />,
"children": <LoadNamespace(LocaleSwitcher) />,
},
"ref": null,
"rendered": Object {
@ -1071,77 +1071,3 @@ ShallowWrapper {
},
}
`;
exports[`Header rendering with query 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Header />,
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": "function",
"props": Object {
"query": "
query HeaderQuery {
site {
siteMetadata {
banner
}
}
}
",
"render": [Function],
},
"ref": null,
"rendered": null,
"type": [MockFunction],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"query": "
query HeaderQuery {
site {
siteMetadata {
banner
}
}
}
",
"render": [Function],
},
"ref": null,
"rendered": null,
"type": [MockFunction],
},
],
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

@ -19,7 +19,7 @@ const query = graphql`
}
`;
export const HeaderImpl = ({ site: { siteMetadata } }) => (
export const Header = ({ site: { siteMetadata } }) => (
<header
className={ style.header }
data-banner={ siteMetadata.banner || null }>
@ -48,7 +48,7 @@ export const HeaderImpl = ({ site: { siteMetadata } }) => (
</header>
);
HeaderImpl.propTypes = {
Header.propTypes = {
site: PropTypes.shape({
siteMetadata: PropTypes.shape({
banner: PropTypes.oneOfType([
@ -59,9 +59,8 @@ HeaderImpl.propTypes = {
}).isRequired
};
const TranslatedHeader = withNamespaces()(HeaderImpl);
const Header = () => <StaticQuery query={ query } render={ data => (
<TranslatedHeader { ...data } />
) } />;
export default Header;
export default withNamespaces()(props => (
<StaticQuery query={ query } render={ data => (
<Header { ...props } { ...data } />
) } />
));

View File

@ -1,26 +1,19 @@
import React from 'react';
import { shallow } from 'enzyme';
import Header, { HeaderImpl } from 'components/Header';
import { Header } from 'components/Header';
describe('Header', () => {
test('rendering with query', () => {
test('rendering', () => {
const component = shallow(
<Header />
<Header site={{ siteMetadata: { banner: 'testing' } }} />
);
expect(component).toMatchSnapshot();
});
test('rendering implementation', () => {
test('rendering with no banner', () => {
const component = shallow(
<HeaderImpl site={{ siteMetadata: { banner: 'testing' } }} />
);
expect(component).toMatchSnapshot();
});
test('rendering implementation with no banner', () => {
const component = shallow(
<HeaderImpl site={{ siteMetadata: { banner: false } }} />
<Header site={{ siteMetadata: { banner: false } }} />
);
expect(component).toMatchSnapshot();
});

View File

@ -20,11 +20,11 @@ ShallowWrapper {
"nodeType": "class",
"props": Object {
"children": Array [
<Header />,
<LoadNamespace(Component) />,
<SentryBoundary>
Example content
</SentryBoundary>,
<Footer />,
<LoadNamespace(Component) />,
],
},
"ref": null,
@ -32,7 +32,7 @@ ShallowWrapper {
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
@ -52,7 +52,7 @@ ShallowWrapper {
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
@ -68,11 +68,11 @@ ShallowWrapper {
"nodeType": "class",
"props": Object {
"children": Array [
<Header />,
<LoadNamespace(Component) />,
<SentryBoundary>
Example content
</SentryBoundary>,
<Footer />,
<LoadNamespace(Component) />,
],
},
"ref": null,
@ -80,7 +80,7 @@ ShallowWrapper {
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
@ -100,7 +100,7 @@ ShallowWrapper {
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,

View File

@ -3,7 +3,7 @@
exports[`LocaleSwitcher rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <LocaleSwitcherImpl />,
Symbol(enzyme.__unrendered__): <LocaleSwitcher />,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],

View File

@ -21,7 +21,7 @@ const localeToAvailable = (locale, available, defaultLocale) => {
return defaultLocale;
};
export class LocaleSwitcherImpl extends React.PureComponent {
export class LocaleSwitcher extends React.PureComponent {
state = {
current: localeToAvailable(
i18n.language || '',
@ -64,4 +64,4 @@ export class LocaleSwitcherImpl extends React.PureComponent {
}
}
export default withNamespaces()(LocaleSwitcherImpl);
export default withNamespaces()(LocaleSwitcher);

View File

@ -2,12 +2,12 @@ import React from 'react';
import { shallow } from 'enzyme';
import i18n from 'i18n';
import { LocaleSwitcherImpl } from 'components/LocaleSwitcher';
import { LocaleSwitcher } from 'components/LocaleSwitcher';
describe('LocaleSwitcher', () => {
test('rendering', () => {
const component = shallow(
<LocaleSwitcherImpl />
<LocaleSwitcher />
);
expect(component).toMatchSnapshot();
});
@ -16,7 +16,7 @@ describe('LocaleSwitcher', () => {
jest.spyOn(i18n, 'changeLanguage');
const component = shallow(
<LocaleSwitcherImpl />
<LocaleSwitcher />
);
const selectInput = component.find('select');
selectInput.value = 'other';

View File

@ -3,7 +3,7 @@
exports[`SentryError rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <SentryErrorImpl
Symbol(enzyme.__unrendered__): <SentryError
t={[Function]}
/>,
Symbol(enzyme.__renderer__): Object {

View File

@ -5,7 +5,7 @@ import { withNamespaces, Trans } from 'react-i18next';
import Message from 'components/Message';
export class SentryErrorImpl extends React.Component {
export class SentryError extends React.Component {
reportError = event => {
event.preventDefault();
@ -26,8 +26,8 @@ export class SentryErrorImpl extends React.Component {
}
}
SentryErrorImpl.propTypes = {
SentryError.propTypes = {
t: PropTypes.func.isRequired
};
export default withNamespaces()(SentryErrorImpl);
export default withNamespaces()(SentryError);

View File

@ -5,12 +5,12 @@ import { shallow } from 'enzyme';
import * as Sentry from '@sentry/browser';
import { mockT } from 'i18n';
import { SentryErrorImpl } from 'components/SentryError';
import { SentryError } from 'components/SentryError';
describe('SentryError', () => {
test('rendering', () => {
const component = shallow(
<SentryErrorImpl t={ mockT }/>
<SentryError t={ mockT }/>
);
expect(component).toMatchSnapshot();
});
@ -19,7 +19,7 @@ describe('SentryError', () => {
test('fill out a report when an event has been logged', () => {
Sentry.lastEventId.mockReturnValue(1);
const component = shallow(
<SentryErrorImpl t={ mockT } />
<SentryError t={ mockT } />
);
const eventObj = { preventDefault: jest.fn() };
component.find('a').simulate('click', eventObj);
@ -31,7 +31,7 @@ describe('SentryError', () => {
test('fill out a report when an event has not been logged', () => {
Sentry.lastEventId.mockReturnValue(false);
const component = shallow(
<SentryErrorImpl t={ mockT } />
<SentryError t={ mockT } />
);
const eventObj = { preventDefault: jest.fn() };
component.find('a').simulate('click', eventObj);

View File

@ -5,15 +5,15 @@ import { withNamespaces, Trans } from 'react-i18next';
import Metadata from 'components/Metadata';
import Message from 'components/Message';
export const ErrorPageImpl = ({ t }) => <>
export const ErrorPage = ({ t }) => <>
<Metadata title={ t('Page Not Found') } />
<Message type="error" heading={ t('404 Page Not Found') }>
<p><Trans>The page you have requested could not be found.</Trans></p>
</Message>
</>;
ErrorPageImpl.propTypes = {
ErrorPage.propTypes = {
t: PropTypes.func.isRequired
};
export default withNamespaces()(ErrorPageImpl);
export default withNamespaces()(ErrorPage);

View File

@ -2,12 +2,12 @@ import React from 'react';
import { shallow } from 'enzyme';
import { mockT } from 'i18n';
import { ErrorPageImpl } from 'pages/404';
import { ErrorPage } from 'pages/404';
describe('Error Page', () => {
test('rendering', () => {
const component = shallow(
<ErrorPageImpl t={ mockT } />
<ErrorPage t={ mockT } />
);
expect(component).toMatchSnapshot();
});

View File

@ -3,7 +3,7 @@
exports[`Error Page rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <ErrorPageImpl
Symbol(enzyme.__unrendered__): <ErrorPage
t={[Function]}
/>,
Symbol(enzyme.__renderer__): Object {

View File

@ -3,7 +3,7 @@
exports[`Index Page rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <IndexPageImpl />,
Symbol(enzyme.__unrendered__): <IndexPage />,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],

View File

@ -3,7 +3,7 @@
exports[`Privacy Page rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <PrivacyPageImpl
Symbol(enzyme.__unrendered__): <PrivacyPage
t={[Function]}
/>,
Symbol(enzyme.__renderer__): Object {

View File

@ -5,7 +5,7 @@ import { withNamespaces, Trans } from 'react-i18next';
import Metadata from 'components/Metadata';
import Message from 'components/Message';
export const IndexPageImpl = () => <>
export const IndexPage = () => <>
<Metadata/>
<noscript>
<Message type="error" heading="JavaScript Required">
@ -17,4 +17,4 @@ export const IndexPageImpl = () => <>
<div><Trans>Hello world</Trans></div>
</>;
export default withNamespaces()(IndexPageImpl);
export default withNamespaces()(IndexPage);

View File

@ -1,12 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import { IndexPageImpl } from 'pages/index';
import { IndexPage } from 'pages/index';
describe('Index Page', () => {
test('rendering', () => {
const component = shallow(
<IndexPageImpl />
<IndexPage />
);
expect(component).toMatchSnapshot();
});

View File

@ -5,7 +5,7 @@ import { withNamespaces, Trans } from 'react-i18next';
import Metadata from 'components/Metadata';
import Message from 'components/Message';
export const PrivacyPageImpl = ({ t }) => <>
export const PrivacyPage = ({ t }) => <>
<Metadata title={ t('Privacy Policy') } />
<Message type="info" heading={ t('Privacy Policy') }>
<Trans i18nKey="Privacy policy copy">
@ -49,8 +49,8 @@ export const PrivacyPageImpl = ({ t }) => <>
</Message>
</>;
PrivacyPageImpl.propTypes = {
PrivacyPage.propTypes = {
t: PropTypes.func.isRequired
};
export default withNamespaces()(PrivacyPageImpl);
export default withNamespaces()(PrivacyPage);

View File

@ -2,12 +2,12 @@ import React from 'react';
import { shallow } from 'enzyme';
import { mockT } from 'i18n';
import { PrivacyPageImpl } from 'pages/privacy';
import { PrivacyPage } from 'pages/privacy';
describe('Privacy Page', () => {
test('rendering', () => {
const component = shallow(
<PrivacyPageImpl t={ mockT } />
<PrivacyPage t={ mockT } />
);
expect(component).toMatchSnapshot();
});