Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove injectI18n in management. #45876

Merged
merged 12 commits into from
Oct 8, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,28 @@

import React from 'react';
import { Header } from '../header';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';

describe('Header', () => {
it('should render normally', () => {
const component = shallowWithIntl(
<Header.WrappedComponent
isIncludingSystemIndices={true}
onChangeIncludingSystemIndices={() => {}}
/>
const component = shallowWithI18nProvider(
<Header isIncludingSystemIndices={true} onChangeIncludingSystemIndices={() => {}} />
);

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

it('should render without including system indices', () => {
const component = shallowWithIntl(
<Header.WrappedComponent
isIncludingSystemIndices={false}
onChangeIncludingSystemIndices={() => {}}
/>
const component = shallowWithI18nProvider(
<Header isIncludingSystemIndices={false} onChangeIncludingSystemIndices={() => {}} />
);

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

it('should render a different name, prompt, and beta tag if provided', () => {
const component = shallowWithIntl(
<Header.WrappedComponent
const component = shallowWithI18nProvider(
<Header
isIncludingSystemIndices={false}
onChangeIncludingSystemIndices={() => {}}
prompt={<div>Test prompt</div>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ import {
EuiSwitch,
} from '@elastic/eui';

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

const HeaderUi = ({
export const Header = ({
prompt,
indexPatternName,
showSystemIndices,
isIncludingSystemIndices,
onChangeIncludingSystemIndices,
isBeta,
intl
}) => (
<div>
<EuiTitle>
Expand All @@ -48,20 +48,19 @@ const HeaderUi = ({
id="kbn.management.createIndexPatternHeader"
defaultMessage="Create {indexPatternName}"
values={{
indexPatternName
indexPatternName,
}}
/>
{ isBeta ? (
{isBeta ? (
<Fragment>
{' '}
<EuiBetaBadge
label={intl.formatMessage({
id: 'kbn.management.createIndexPattern.betaLabel',
defaultMessage: 'Beta'
label={i18n.translate('kbn.management.createIndexPattern.betaLabel', {
defaultMessage: 'Beta',
})}
/>
</Fragment>
) : null }
) : null}
</h1>
</EuiTitle>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="flexEnd">
Expand All @@ -77,32 +76,28 @@ const HeaderUi = ({
</p>
</EuiText>
</EuiFlexItem>
{
showSystemIndices ? (
<EuiFlexItem grow={false}>
<EuiSwitch
label={<FormattedMessage
{showSystemIndices ? (
<EuiFlexItem grow={false}>
<EuiSwitch
label={
<FormattedMessage
id="kbn.management.createIndexPattern.includeSystemIndicesToggleSwitchLabel"
defaultMessage="Include system indices"
/>}
id="checkboxShowSystemIndices"
checked={isIncludingSystemIndices}
onChange={onChangeIncludingSystemIndices}
/>
</EuiFlexItem>
) : null
}
/>
}
id="checkboxShowSystemIndices"
checked={isIncludingSystemIndices}
onChange={onChangeIncludingSystemIndices}
/>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
{
prompt ? (
<Fragment>
<EuiSpacer size="s" />
{prompt}
</Fragment>
) : null
}
<EuiSpacer size="m"/>
{prompt ? (
<Fragment>
<EuiSpacer size="s" />
{prompt}
</Fragment>
) : null}
<EuiSpacer size="m" />
</div>
);

export const Header = injectI18n(HeaderUi);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
*/

import React from 'react';
import { StepIndexPatternComponent } from '../step_index_pattern';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { StepIndexPattern } from '../step_index_pattern';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { Header } from '../components/header';

jest.mock('../../../lib/ensure_minimum_time', () => ({
ensureMinimumTime: async (promises) => Array.isArray(promises) ? await Promise.all(promises) : await promises
ensureMinimumTime: async promises =>
Array.isArray(promises) ? await Promise.all(promises) : await promises,
}));
const mockIndexPatternCreationType = {
getIndexPatternType: () => 'default',
getIndexPatternName: () => 'name',
checkIndicesForErrors: () => false,
getShowSystemIndices: () => false
getShowSystemIndices: () => false,
};
// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype
// at Function.defineProperties`.
Expand All @@ -41,33 +42,29 @@ jest.mock('ui/chrome', () => ({
getUiSettingsClient: () => ({
get: () => '',
}),
addBasePath: () => { },
addBasePath: () => {},
}));

jest.mock('../../../lib/get_indices', () => ({
getIndices: (service, indexPatternCreationType, query) => {
if (query.startsWith('e')) {
return [
{ name: 'es' },
];
return [{ name: 'es' }];
}

return [
{ name: 'kibana' },
];
return [{ name: 'kibana' }];
},
}));

const allIndices = [{ name: 'kibana' }, { name: 'es' }];
const esService = {};
const savedObjectsClient = {
find: () => ({ savedObjects: [] })
find: () => ({ savedObjects: [] }),
};
const goToNextStep = () => { };
const goToNextStep = () => {};

const createComponent = props => {
return shallowWithIntl(
<StepIndexPatternComponent
return shallowWithI18nProvider(
<StepIndexPattern
allIndices={allIndices}
isIncludingSystemIndices={false}
esService={esService}
Expand All @@ -94,7 +91,9 @@ describe('StepIndexPattern', () => {
// Ensure the state changes are reflected
await component.update();

expect(component.find('[data-test-subj="createIndexPatternStep1IndicesList"]')).toMatchSnapshot();
expect(
component.find('[data-test-subj="createIndexPatternStep1IndicesList"]')
).toMatchSnapshot();
});

it('renders errors when input is invalid', async () => {
Expand All @@ -121,7 +120,9 @@ describe('StepIndexPattern', () => {
// Ensure the state changes are reflected
component.update();

expect(component.find('[data-test-subj="createIndexPatternStep1IndicesList"]')).toMatchSnapshot();
expect(
component.find('[data-test-subj="createIndexPatternStep1IndicesList"]')
).toMatchSnapshot();
});

it('appends a wildcard automatically to queries', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

import React from 'react';
import { HeaderComponent } from '../header';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { Header } from '../header';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';

describe('Header', () => {
it('should render normally', () => {
const component = shallowWithIntl(
<HeaderComponent
const component = shallowWithI18nProvider(
<Header
isInputInvalid={false}
errors={[]}
characterList={['%']}
Expand All @@ -39,8 +39,8 @@ describe('Header', () => {
});

it('should mark the input as invalid', () => {
const component = shallowWithIntl(
<HeaderComponent
const component = shallowWithI18nProvider(
<Header
isInputInvalid={true}
errors={['Input is invalid']}
characterList={['%']}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ import {
EuiFieldText,
} from '@elastic/eui';

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

export const HeaderComponent = ({
export const Header = ({
isInputInvalid,
errors,
characterList,
query,
onQueryChanged,
goToNextStep,
isNextStepDisabled,
intl,
...rest
}) => (
<div {...rest}>
Expand All @@ -52,17 +52,17 @@ export const HeaderComponent = ({
/>
</h2>
</EuiTitle>
<EuiSpacer size="m"/>
<EuiSpacer size="m" />
<EuiFlexGroup justifyContent="spaceBetween" alignItems="flexEnd">
<EuiFlexItem grow={false}>
<EuiForm
isInvalid={isInputInvalid}
>
<EuiForm isInvalid={isInputInvalid}>
<EuiFormRow
label={<FormattedMessage
id="kbn.management.createIndexPattern.step.indexPatternLabel"
defaultMessage="Index pattern"
/>}
label={
<FormattedMessage
id="kbn.management.createIndexPattern.step.indexPatternLabel"
defaultMessage="Index pattern"
/>
}
isInvalid={isInputInvalid}
error={errors}
helpText={
Expand All @@ -86,10 +86,12 @@ export const HeaderComponent = ({
>
<EuiFieldText
name="indexPattern"
placeholder={intl.formatMessage({
id: 'kbn.management.createIndexPattern.step.indexPatternPlaceholder',
defaultMessage: 'index-name-*'
})}
placeholder={i18n.translate(
'kbn.management.createIndexPattern.step.indexPatternPlaceholder',
{
defaultMessage: 'index-name-*',
}
)}
value={query}
isInvalid={isInputInvalid}
onChange={onQueryChanged}
Expand All @@ -114,5 +116,3 @@ export const HeaderComponent = ({
</EuiFlexGroup>
</div>
);

export const Header = injectI18n(HeaderComponent);
Loading