Translating FormActions component

This commit is contained in:
Jeff Avallone 2019-01-15 21:46:23 -05:00
parent c4a74ad244
commit d48b48bffc
6 changed files with 49 additions and 23 deletions

View File

@ -19,7 +19,7 @@ exports[`App removing rendered expression 1`] = `
] ]
} }
> >
<FormActions /> <LoadNamespace(FormActions) />
</LoadNamespace(Form)> </LoadNamespace(Form)>
<RenderJS <RenderJS
expr="test expression" expr="test expression"
@ -136,7 +136,7 @@ exports[`App rendering an expression 3`] = `
] ]
} }
> >
<FormActions /> <LoadNamespace(FormActions) />
</LoadNamespace(Form)> </LoadNamespace(Form)>
<RenderJS <RenderJS
expr="test expression" expr="test expression"
@ -164,7 +164,7 @@ exports[`App rendering image details 1`] = `
] ]
} }
> >
<FormActions /> <LoadNamespace(FormActions) />
</LoadNamespace(Form)> </LoadNamespace(Form)>
<RenderJS <RenderJS
expr="test expression" expr="test expression"
@ -192,7 +192,7 @@ exports[`App rendering image details 2`] = `
] ]
} }
> >
<FormActions <LoadNamespace(FormActions)
imageDetails={ imageDetails={
Object { Object {
"svg": "test svg content", "svg": "test svg content",

View File

@ -20,7 +20,7 @@ exports[`FormActions rendering download links 1`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
Example PNG Link TRANSLATE(Example PNG Link)
</a> </a>
</li> </li>
<li> <li>
@ -33,7 +33,7 @@ exports[`FormActions rendering download links 1`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
Example SVG Link TRANSLATE(Example SVG Link)
</a> </a>
</li> </li>
</ul> </ul>
@ -51,7 +51,9 @@ exports[`FormActions rendering download links with data after mounting 1`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
<WithMergedOptions(TransComponent)>
Permalink Permalink
</WithMergedOptions(TransComponent)>
</a> </a>
</li> </li>
</ul> </ul>
@ -71,7 +73,7 @@ exports[`FormActions rendering download links with data after mounting 2`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
Example PNG Link TRANSLATE(Example PNG Link)
</a> </a>
</li> </li>
<li> <li>
@ -84,7 +86,7 @@ exports[`FormActions rendering download links with data after mounting 2`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
Example SVG Link TRANSLATE(Example SVG Link)
</a> </a>
</li> </li>
<li> <li>
@ -95,7 +97,9 @@ exports[`FormActions rendering download links with data after mounting 2`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
<WithMergedOptions(TransComponent)>
Permalink Permalink
</WithMergedOptions(TransComponent)>
</a> </a>
</li> </li>
</ul> </ul>
@ -115,7 +119,7 @@ exports[`FormActions rendering download links with data after mounting 3`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
Example PNG Link TRANSLATE(Example PNG Link)
</a> </a>
</li> </li>
<li> <li>
@ -128,7 +132,7 @@ exports[`FormActions rendering download links with data after mounting 3`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
Example SVG Link TRANSLATE(Example SVG Link)
</a> </a>
</li> </li>
<li> <li>
@ -139,7 +143,9 @@ exports[`FormActions rendering download links with data after mounting 3`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
<WithMergedOptions(TransComponent)>
Permalink Permalink
</WithMergedOptions(TransComponent)>
</a> </a>
</li> </li>
</ul> </ul>
@ -157,7 +163,9 @@ exports[`FormActions rendering with a permalink 1`] = `
color="currentColor" color="currentColor"
size="24" size="24"
/> />
<WithMergedOptions(TransComponent)>
Permalink Permalink
</WithMergedOptions(TransComponent)>
</a> </a>
</li> </li>
</ul> </ul>

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { withNamespaces, Trans } from 'react-i18next';
import DownloadIcon from 'react-feather/dist/icons/download'; import DownloadIcon from 'react-feather/dist/icons/download';
import LinkIcon from 'react-feather/dist/icons/link'; import LinkIcon from 'react-feather/dist/icons/link';
@ -15,7 +16,8 @@ class FormActions extends React.PureComponent {
svg: PropTypes.string, svg: PropTypes.string,
width: PropTypes.number, width: PropTypes.number,
height: PropTypes.number height: PropTypes.number
}) }),
t: PropTypes.func.isRequired
} }
state = { state = {
@ -63,9 +65,11 @@ class FormActions extends React.PureComponent {
} }
downloadLink({ url, filename, type, label }) { downloadLink({ url, filename, type, label }) {
const { t } = this.props;
return <li> return <li>
<a href={ url } download={ filename } type={ type }> <a href={ url } download={ filename } type={ type }>
<DownloadIcon />{ label } <DownloadIcon />{ t(label) }
</a> </a>
</li>; </li>;
} }
@ -83,10 +87,11 @@ class FormActions extends React.PureComponent {
{ pngLink && this.downloadLink(pngLink) } { pngLink && this.downloadLink(pngLink) }
{ svgLink && this.downloadLink(svgLink) } { svgLink && this.downloadLink(svgLink) }
{ permalinkUrl && <li> { permalinkUrl && <li>
<a href={ permalinkUrl }><LinkIcon />Permalink</a> <a href={ permalinkUrl }><LinkIcon /><Trans>Permalink</Trans></a>
</li> } </li> }
</ul>; </ul>;
} }
} }
export default FormActions; export { FormActions };
export default withNamespaces()(FormActions);

View File

@ -3,7 +3,8 @@ jest.mock('./links');
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import FormActions from 'components/FormActions'; import { mockT } from 'i18n';
import { FormActions } from 'components/FormActions';
import { createPngLink, createSvgLink } from './links'; import { createPngLink, createSvgLink } from './links';
createPngLink.mockResolvedValue({ createPngLink.mockResolvedValue({
@ -22,14 +23,14 @@ createSvgLink.mockResolvedValue({
describe('FormActions', () => { describe('FormActions', () => {
test('rendering', () => { test('rendering', () => {
const component = shallow( const component = shallow(
<FormActions /> <FormActions t={ mockT } />
); );
expect(component).toMatchSnapshot(); expect(component).toMatchSnapshot();
}); });
test('rendering with a permalink', () => { test('rendering with a permalink', () => {
const component = shallow( const component = shallow(
<FormActions permalinkUrl="http://example.com" /> <FormActions permalinkUrl="http://example.com" t={ mockT } />
); );
expect(component).toMatchSnapshot(); expect(component).toMatchSnapshot();
}); });
@ -42,7 +43,7 @@ describe('FormActions', () => {
}; };
const component = shallow( const component = shallow(
<FormActions imageDetails={ imageDetails }/> <FormActions imageDetails={ imageDetails } t={ mockT } />
); );
// Give a beat for mocked promises to resolve // Give a beat for mocked promises to resolve
@ -53,7 +54,7 @@ describe('FormActions', () => {
test('rendering download links with data after mounting', async () => { test('rendering download links with data after mounting', async () => {
const component = shallow( const component = shallow(
<FormActions /> <FormActions t={ mockT } />
); );
component.setProps({ permalinkUrl: 'http://example.com' }); component.setProps({ permalinkUrl: 'http://example.com' });

View File

@ -57,3 +57,9 @@
JAVASCRIPT JAVASCRIPT
"PCRE": | "PCRE": |
PCRE PCRE
"Permalink": |
PERMALINK
"Download SVG": |
DOWNLOAD SVG
"Download PNG": |
DOWNLOAD PNG

View File

@ -57,3 +57,9 @@
JavaScript JavaScript
"PCRE": | "PCRE": |
PCRE PCRE
"Permalink": |
Permalink
"Download SVG": |
Download SVG
"Download PNG": |
Download PNG