Skip to content

Commit

Permalink
Remove injectI18n usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Dec 1, 2020
1 parent 90caae9 commit 28a107d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import React from 'react';
import { shallowWithIntl, mountWithIntl } from '@kbn/test/jest';
import { findTestSubject } from '@elastic/eui/lib/test';
import { getDepsMock, getIndexPatternMock } from '../../test_utils';
import ControlsTab, { ControlsTabUiProps } from './controls_tab';
import ControlsTab, { ControlsTabProps } from './controls_tab';
import { Vis } from '../../../../visualizations/public';

const indexPatternsMock = {
get: getIndexPatternMock,
};
let props: ControlsTabUiProps;
let props: ControlsTabProps;

beforeEach(() => {
props = ({
Expand Down Expand Up @@ -78,18 +78,18 @@ beforeEach(() => {
},
setValue: jest.fn(),
intl: null as any,
} as unknown) as ControlsTabUiProps;
} as unknown) as ControlsTabProps;
});

test('renders ControlsTab', () => {
const component = shallowWithIntl(<ControlsTab.WrappedComponent {...props} />);
const component = shallowWithIntl(<ControlsTab {...props} />);

expect(component).toMatchSnapshot();
});

describe('behavior', () => {
test('add control button', () => {
const component = mountWithIntl(<ControlsTab.WrappedComponent {...props} />);
const component = mountWithIntl(<ControlsTab {...props} />);

findTestSubject(component, 'inputControlEditorAddBtn').simulate('click');

Expand All @@ -102,7 +102,7 @@ describe('behavior', () => {
});

test('remove control button', () => {
const component = mountWithIntl(<ControlsTab.WrappedComponent {...props} />);
const component = mountWithIntl(<ControlsTab {...props} />);
findTestSubject(component, 'inputControlEditorRemoveControl0').simulate('click');
const expectedParams = [
'controls',
Expand All @@ -125,7 +125,7 @@ describe('behavior', () => {
});

test('move down control button', () => {
const component = mountWithIntl(<ControlsTab.WrappedComponent {...props} />);
const component = mountWithIntl(<ControlsTab {...props} />);
findTestSubject(component, 'inputControlEditorMoveDownControl0').simulate('click');
const expectedParams = [
'controls',
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('behavior', () => {
});

test('move up control button', () => {
const component = mountWithIntl(<ControlsTab.WrappedComponent {...props} />);
const component = mountWithIntl(<ControlsTab {...props} />);
findTestSubject(component, 'inputControlEditorMoveUpControl1').simulate('click');
const expectedParams = [
'controls',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import React, { PureComponent } from 'react';
import { injectI18n, FormattedMessage, InjectedIntlProps } from '@kbn/i18n/react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

import {
EuiButton,
Expand Down Expand Up @@ -50,12 +51,11 @@ interface ControlsTabUiState {
type: CONTROL_TYPES;
}

export type ControlsTabUiProps = InjectedIntlProps &
VisOptionsProps<InputControlVisParams> & {
deps: InputControlVisDependencies;
};
export type ControlsTabProps = VisOptionsProps<InputControlVisParams> & {
deps: InputControlVisDependencies;
};

class ControlsTabUi extends PureComponent<ControlsTabUiProps, ControlsTabUiState> {
class ControlsTab extends PureComponent<ControlsTabProps, ControlsTabUiState> {
state = {
type: CONTROL_TYPES.LIST,
};
Expand Down Expand Up @@ -157,8 +157,6 @@ class ControlsTabUi extends PureComponent<ControlsTabUiProps, ControlsTabUiState
}

render() {
const { intl } = this.props;

return (
<div>
{this.renderControls()}
Expand All @@ -172,25 +170,31 @@ class ControlsTabUi extends PureComponent<ControlsTabUiProps, ControlsTabUiState
options={[
{
value: CONTROL_TYPES.RANGE,
text: intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.rangeDropDownOptionLabel',
defaultMessage: 'Range slider',
}),
text: i18n.translate(
'inputControl.editor.controlsTab.select.rangeDropDownOptionLabel',
{
defaultMessage: 'Range slider',
}
),
},
{
value: CONTROL_TYPES.LIST,
text: intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.listDropDownOptionLabel',
defaultMessage: 'Options list',
}),
text: i18n.translate(
'inputControl.editor.controlsTab.select.listDropDownOptionLabel',
{
defaultMessage: 'Options list',
}
),
},
]}
value={this.state.type}
onChange={(event) => this.setState({ type: event.target.value as CONTROL_TYPES })}
aria-label={intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.controlTypeAriaLabel',
defaultMessage: 'Select control type',
})}
aria-label={i18n.translate(
'inputControl.editor.controlsTab.select.controlTypeAriaLabel',
{
defaultMessage: 'Select control type',
}
)}
/>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -201,10 +205,12 @@ class ControlsTabUi extends PureComponent<ControlsTabUiProps, ControlsTabUiState
onClick={this.handleAddControl}
iconType="plusInCircle"
data-test-subj="inputControlEditorAddBtn"
aria-label={intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.addControlAriaLabel',
defaultMessage: 'Add control',
})}
aria-label={i18n.translate(
'inputControl.editor.controlsTab.select.addControlAriaLabel',
{
defaultMessage: 'Add control',
}
)}
>
<FormattedMessage
id="inputControl.editor.controlsTab.addButtonLabel"
Expand All @@ -220,7 +226,6 @@ class ControlsTabUi extends PureComponent<ControlsTabUiProps, ControlsTabUiState
}
}

const ControlsTab = injectI18n(ControlsTabUi);
// default export required for React.Lazy
// eslint-disable-next-line import/no-default-export
export { ControlsTab as default };

0 comments on commit 28a107d

Please sign in to comment.