Skip to content

Commit

Permalink
Tests and PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 16, 2018
1 parent 6199b38 commit b74921a
Show file tree
Hide file tree
Showing 23 changed files with 1,334 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`StepIndexPattern should render normally 1`] = `
<EuiPanel
grow={true}
hasShadow={false}
paddingSize="l"
>
<Header
characterList="\\\\, /, ?, \\", <, >, |"
errors={Array []}
goToNextStep={[Function]}
isInputInvalid={false}
isNextStepDisabled={true}
onQueryChanged={[Function]}
query="k"
/>
<EuiSpacer
size="s"
/>
<StatusMessage
matchedIndices={
Object {
"allIndices": Array [
Object {
"name": "kibana",
},
Object {
"name": "es",
},
],
"exactMatchedIndices": Array [],
"partialMatchedIndices": Array [],
"visibleIndices": Array [
Object {
"name": "kibana",
},
Object {
"name": "es",
},
],
}
}
query="k"
/>
<EuiSpacer
size="s"
/>
<IndicesList
indices={
Array [
Object {
"name": "kibana",
},
Object {
"name": "es",
},
]
}
/>
</EuiPanel>
`;
exports[`StepIndexPattern should render some indices 1`] = `
<EuiPanel
grow={true}
hasShadow={false}
paddingSize="l"
>
<Header
characterList="\\\\, /, ?, \\", <, >, |"
errors={Array []}
goToNextStep={[Function]}
isInputInvalid={false}
isNextStepDisabled={false}
onQueryChanged={[Function]}
query="k*"
/>
<EuiSpacer
size="s"
/>
<StatusMessage
matchedIndices={
Object {
"allIndices": Array [
Object {
"name": "kibana",
},
Object {
"name": "es",
},
],
"exactMatchedIndices": Array [
Object {
"name": "kibana",
},
],
"partialMatchedIndices": Array [
Object {
"name": "kibana",
},
],
"visibleIndices": Array [
Object {
"name": "kibana",
},
],
}
}
query="k*"
/>
<EuiSpacer
size="s"
/>
<IndicesList
indices={
Array [
Object {
"name": "kibana",
},
]
}
/>
</EuiPanel>
`;
exports[`StepIndexPattern should render the loading state 1`] = `
<EuiPanel
grow={true}
hasShadow={false}
paddingSize="l"
>
<Header
characterList="\\\\, /, ?, \\", <, >, |"
errors={Array []}
goToNextStep={[Function]}
isInputInvalid={false}
isNextStepDisabled={true}
onQueryChanged={[Function]}
query="k"
/>
<EuiSpacer
size="s"
/>
<LoadingIndices />
<EuiSpacer
size="s"
/>
</EuiPanel>
`;
exports[`StepIndexPattern should show errors 1`] = `
<EuiPanel
grow={true}
hasShadow={false}
paddingSize="l"
>
<Header
characterList="\\\\, /, ?, \\", <, >, |"
errors={
Array [
"Your input contains invalid characters or spaces. Please omit: \\\\, /, ?, \\", <, >, |",
]
}
goToNextStep={[Function]}
isInputInvalid={true}
isNextStepDisabled={true}
onQueryChanged={[Function]}
query="?"
/>
<EuiSpacer
size="s"
/>
<StatusMessage
matchedIndices={
Object {
"allIndices": Array [
Object {
"name": "kibana",
},
Object {
"name": "es",
},
],
"exactMatchedIndices": Array [],
"partialMatchedIndices": Array [
Object {
"name": "kibana",
},
],
"visibleIndices": Array [
Object {
"name": "kibana",
},
],
}
}
query="?"
/>
<EuiSpacer
size="s"
/>
<IndicesList
indices={
Array [
Object {
"name": "kibana",
},
]
}
/>
</EuiPanel>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react';
import { shallow } from 'enzyme';

import { StepIndexPattern } from '../step_index_pattern';

jest.mock('../components/indices_list', () => ({ IndicesList: 'IndicesList' }));
jest.mock('../components/loading_indices', () => ({ LoadingIndices: 'LoadingIndices' }));
jest.mock('../components/status_message', () => ({ StatusMessage: 'StatusMessage' }));
jest.mock('../components/header', () => ({ Header: 'Header' }));
jest.mock('../../../lib/create_reasonable_wait', () => ({ createReasonableWait: fn => fn() }));
jest.mock('../../../lib/get_indices', () => ({
getIndices: () => {
return [
{ name: 'kibana' },
];
},
}));

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

describe('StepIndexPattern', () => {
it('should render normally', () => {
const component = shallow(
<StepIndexPattern
allIndices={allIndices}
isIncludingSystemIndices={false}
esService={esService}
goToNextStep={goToNextStep}
initialQuery={'k'}
/>
);

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

it('should render the loading state', () => {
const component = shallow(
<StepIndexPattern
allIndices={allIndices}
isIncludingSystemIndices={false}
esService={esService}
goToNextStep={goToNextStep}
/>
);

component.setState({ query: 'k', isLoadingIndices: true });

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

it('should render some indices', async () => {
const component = shallow(
<StepIndexPattern
allIndices={allIndices}
isIncludingSystemIndices={false}
esService={esService}
goToNextStep={goToNextStep}
/>
);

const instance = component.instance();

await instance.onQueryChanged({
nativeEvent: { data: 'k' },
target: { value: 'k' }
});

component.update();

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

it('should show errors', async () => {
const component = shallow(
<StepIndexPattern
allIndices={allIndices}
isIncludingSystemIndices={false}
esService={esService}
goToNextStep={goToNextStep}
/>
);

const instance = component.instance();

await instance.onQueryChanged({
nativeEvent: { data: '?' },
target: { value: '?' }
});

component.update();

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

0 comments on commit b74921a

Please sign in to comment.