Commit 54b48f55 authored by Jeff Avallone's avatar Jeff Avallone

Improving test coverage

parent 52d378be
Pipeline #23532884 passed with stages
in 10 minutes and 28 seconds
......@@ -42,8 +42,13 @@ describe('Form', () => {
const component = shallow(
<Form t={ translate } syntaxes={ syntaxes } onSubmit={ onSubmit }/>
);
const exprInput = component.find('[name="expr"]');
const syntaxInput = component.find('[name="syntax"]');
exprInput.simulate('change', { target: { name: 'expr', value: 'Test expression' } });
syntaxInput.simulate('change', { target: { name: 'syntax', value: 'test' } });
const eventObj = { preventDefault: jest.fn() };
component.setState({ syntax: 'test', expr: 'Test expression' });
component.find('form').simulate('submit', eventObj);
expect(eventObj.preventDefault).toHaveBeenCalled();
......
......@@ -11,7 +11,20 @@ exports[`LocaleSwitcher rendering 1`] = `
<select
onChange={[Function]}
value="en"
/>
>
<option
key="en"
value="en"
>
/displayName
</option>
<option
key="fr"
value="fr"
>
/displayName
</option>
</select>
<SvgMock />
</div>
</label>
......
......@@ -26,8 +26,6 @@ class LocaleSwitcher extends React.PureComponent {
current: localeToAvailable(i18n.language || '', Object.keys(locales), 'en')
}
localeSelector = React.createRef()
componentDidMount() {
i18n.on('languageChanged', this.handleLanguageChange);
}
......@@ -36,8 +34,8 @@ class LocaleSwitcher extends React.PureComponent {
i18n.off('languageChanged', this.handleLanguageChange);
}
handleSelectChange = () => {
i18n.changeLanguage(this.localeSelector.current.value);
handleSelectChange = ({ target }) => {
i18n.changeLanguage(target.value);
}
handleLanguageChange = lang => {
......@@ -50,7 +48,7 @@ class LocaleSwitcher extends React.PureComponent {
return <label>
<Trans>Language</Trans>
<div className={ style.switcher }>
<select value={ current } ref={ this.localeSelector } onChange={ this.handleSelectChange }>
<select value={ current } onChange={ this.handleSelectChange }>
{ Object.keys(locales).map(locale => (
<option value={ locale } key={ locale }>{ i18n.getFixedT(locale)('/displayName') }</option>
)) }
......
jest.mock('components/SVG');
jest.mock('locales', () => ({
en: {},
fr: {}
}));
import React from 'react';
import { shallow } from 'enzyme';
......@@ -13,4 +17,15 @@ describe('LocaleSwitcher', () => {
);
expect(component).toMatchSnapshot();
});
test('changing language', () => {
const component = shallow(
<LocaleSwitcher t={ translate }/>
);
const selectInput = component.find('select');
selectInput.value = 'fr';
selectInput.simulate('change', { target: { value: 'fr' } });
expect(component.state('current')).toEqual('fr');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment