Skip to content

Commit

Permalink
Added tests for EuiButtonContent
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos committed Jul 14, 2020
1 parent dd949b8 commit d9b751e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 6 deletions.
68 changes: 68 additions & 0 deletions src/components/button/__snapshots__/button_content.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,71 @@ exports[`EuiButtonContent is rendered 1`] = `
<span />
</span>
`;

exports[`EuiButtonContent props children is rendered 1`] = `
<span
class=""
>
<span>
Content
</span>
</span>
`;

exports[`EuiButtonContent props iconSide is rendered 1`] = `
<span
class="euiButtonContent--iconRight"
>
<div
class="euiButtonContent__icon"
data-euiicon-type="bolt"
/>
<span />
</span>
`;

exports[`EuiButtonContent props iconType is rendered 1`] = `
<span
class=""
>
<div
class="euiButtonContent__icon"
data-euiicon-type="bolt"
/>
<span />
</span>
`;

exports[`EuiButtonContent props isLoading is rendered 1`] = `
<span
class=""
>
<span
class="euiLoadingSpinner euiLoadingSpinner--medium euiButtonContent__spinner"
/>
<span />
</span>
`;

exports[`EuiButtonContent props isLoading replaces iconType with spinner 1`] = `
<span
class=""
>
<span
class="euiLoadingSpinner euiLoadingSpinner--medium euiButtonContent__spinner"
/>
<span />
</span>
`;

exports[`EuiButtonContent props textProps is rendered 1`] = `
<span
class=""
>
<span
aria-label="aria-label"
class="testClass1 testClass2"
data-test-subj="test subject string"
/>
</span>
`;
4 changes: 2 additions & 2 deletions src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export interface EuiButtonDisplayProps extends EuiButtonProps {
}

/**
*
* *INTERNAL ONLY* Component for displaying any element as a button
* *INTERNAL ONLY*
* Component for displaying any element as a button
* EuiButton is largely responsible for providing relevant props
* and the logic for element-specific attributes
*/
Expand Down
40 changes: 40 additions & 0 deletions src/components/button/button_content.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,44 @@ describe('EuiButtonContent', () => {

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

describe('props', () => {
test('children is rendered', () => {
const component = render(<EuiButtonContent>Content</EuiButtonContent>);

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

test('iconType is rendered', () => {
const component = render(<EuiButtonContent iconType="bolt" />);

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

test('iconSide is rendered', () => {
const component = render(
<EuiButtonContent iconSide="right" iconType="bolt" />
);

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

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

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

test('isLoading replaces iconType with spinner', () => {
const component = render(<EuiButtonContent isLoading iconType="bolt" />);

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

test('textProps is rendered', () => {
const component = render(<EuiButtonContent textProps={requiredProps} />);

expect(component).toMatchSnapshot();
});
});
});
8 changes: 4 additions & 4 deletions src/components/button/button_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
* under the License.
*/

/**
* This component is simply a helper component for reuse within other button components
*/

import React, { HTMLAttributes, FunctionComponent } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';
Expand All @@ -36,6 +32,10 @@ const iconSideToClassNameMap: { [side in ButtonIconSide]: string | null } = {

export const ICON_SIDES = keysOf(iconSideToClassNameMap);

/**
* *INTERNAL ONLY*
* This component is simply a helper component for reuse within other button components
*/
export type EuiButtonContentProps = HTMLAttributes<HTMLSpanElement> &
CommonProps & {
iconType?: IconType;
Expand Down

0 comments on commit d9b751e

Please sign in to comment.