Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Set i18n of alert dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Sep 29, 2017
1 parent db28683 commit 35d2e5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/actions/dialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import actionTypes from '../constants/actions';
import i18next from 'i18next';
import Alert from '../components/dialog/alert';
import actionTypes from '../constants/actions';

/**
* An action to dispatch to display a dialog
Expand Down Expand Up @@ -28,7 +29,7 @@ export const alertDialogDisplayed = data => dialogDisplayed({
*
*/
export const successAlertDialogDisplayed = data => alertDialogDisplayed({
title: 'Success',
title: i18next.t('Success'),
text: data.text,
type: 'success',
});
Expand All @@ -38,7 +39,7 @@ export const successAlertDialogDisplayed = data => alertDialogDisplayed({
*
*/
export const errorAlertDialogDisplayed = data => alertDialogDisplayed({
title: 'Error',
title: i18next.t('Error'),
text: data.text,
type: 'error',
});
Expand Down
11 changes: 6 additions & 5 deletions src/components/dialog/alert.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react';
import { translate } from 'react-i18next';
import Button from 'react-toolbox/lib/button';
import React from 'react';
import grid from 'flexboxgrid/dist/flexboxgrid.css';


const Alert = props => (
const Alert = ({ text, closeDialog, t }) => (
<div>
<p>{props.text}</p>
<p>{text}</p>
<br />
<section className={`${grid.row} ${grid['between-xs']}`}>
<span />
<Button label='Ok' onClick={props.closeDialog} className='ok-button'/>
<Button label={t('Ok')} onClick={closeDialog} className='ok-button'/>
</section>
</div>
);

export default Alert;
export default translate()(Alert);
10 changes: 9 additions & 1 deletion src/components/dialog/alert.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import PropTypes from 'prop-types';
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import Alert from './alert';
import i18n from '../../i18n';


describe('Alert', () => {
let wrapper;
let closeSpy;
const text = 'some random text';
const options = {
context: { i18n },
childContextTypes: {
i18n: PropTypes.object.isRequired,
},
};

beforeEach(() => {
closeSpy = sinon.spy();
wrapper = mount(<Alert text={text} closeDialog={closeSpy} />);
wrapper = mount(<Alert text={text} closeDialog={closeSpy} />, options);
});

it('renders paragraph with props.text', () => {
Expand Down

0 comments on commit 35d2e5a

Please sign in to comment.