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

Form tests - Phase 2 #207

Merged
merged 4 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,52 @@ exports[`EuiFormControlLayout is rendered 1`] = `
<input />
</div>
`;

exports[`EuiFormControlLayout props fullWidth is rendered 1`] = `
<div
class="euiFormControlLayout euiFormControlLayout--fullWidth"
/>
`;

exports[`EuiFormControlLayout props icon is rendered 1`] = `
<div
class="euiFormControlLayout"
>
<eui_icon
class="euiFormControlLayout__icon"
type="alert"
/>
</div>
`;

exports[`EuiFormControlLayout props iconSide left is rendered 1`] = `
<div
class="euiFormControlLayout"
>
<eui_icon
class="euiFormControlLayout__icon"
type="alert"
/>
</div>
`;

exports[`EuiFormControlLayout props iconSide right is rendered 1`] = `
<div
class="euiFormControlLayout"
>
<eui_icon
class="euiFormControlLayout__icon euiFormControlLayout__icon--right"
type="alert"
/>
</div>
`;

exports[`EuiFormControlLayout props isLoading is rendered 1`] = `
<div
class="euiFormControlLayout"
>
<eui_loading_spinner
class="euiFormControlLayout__loading"
/>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export const EuiFormControlLayout = ({ children, icon, fullWidth, iconSide, isLo
EuiFormControlLayout.propTypes = {
children: PropTypes.node,
icon: PropTypes.string,
fullWidth: PropTypes.bool,
iconSide: PropTypes.oneOf(ICON_SIDES),
isLoading: PropTypes.bool,
className: PropTypes.string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catches!

};

EuiFormControlLayout.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import { render } from 'enzyme';

import { EuiFormControlLayout } from './form_control_layout';
import {
EuiFormControlLayout,
ICON_SIDES,
} from './form_control_layout';

jest.mock('../../', () => ({ EuiIcon: 'eui_icon', EuiLoadingSpinner: 'eui_loading_spinner' }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm learning a lot from your use of mocks.


describe('EuiFormControlLayout', () => {
test('is rendered', () => {
Expand All @@ -14,4 +19,46 @@ describe('EuiFormControlLayout', () => {
expect(component)
.toMatchSnapshot();
});

describe('props', () => {
test('icon is rendered', () => {
const component = render(
<EuiFormControlLayout icon="alert"/>
);

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

describe('iconSide', () => {
ICON_SIDES.forEach(side => {
test(`${side} is rendered`, () => {
const component = render(
<EuiFormControlLayout icon="alert" iconSide={side}/>
);

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

test('isLoading is rendered', () => {
const component = render(
<EuiFormControlLayout isLoading/>
);

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

test('fullWidth is rendered', () => {
const component = render(
<EuiFormControlLayout fullWidth/>
);

expect(component)
.toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ exports[`EuiFormErrorText is rendered 1`] = `
aria-label="aria-label"
class="euiFormErrorText testClass1 testClass2"
data-test-subj="test subject string"
/>
>
This is an error.
</div>
`;
4 changes: 3 additions & 1 deletion src/components/form/form_error_text/form_error_text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { EuiFormErrorText } from './form_error_text';
describe('EuiFormErrorText', () => {
test('is rendered', () => {
const component = render(
<EuiFormErrorText {...requiredProps} />
<EuiFormErrorText {...requiredProps}>
This is an error.
</EuiFormErrorText>
);

expect(component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ exports[`EuiFormHelpText is rendered 1`] = `
aria-label="aria-label"
class="euiFormHelpText testClass1 testClass2"
data-test-subj="test subject string"
/>
>
This is help text.
</div>
`;
4 changes: 3 additions & 1 deletion src/components/form/form_help_text/form_help_text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { EuiFormHelpText } from './form_help_text';
describe('EuiFormHelpText', () => {
test('is rendered', () => {
const component = render(
<EuiFormHelpText {...requiredProps} />
<EuiFormHelpText {...requiredProps}>
This is help text.
</EuiFormHelpText>
);

expect(component)
Expand Down