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

[Emotion] Fix/regression test more css props #6248

Merged
merged 10 commits into from
Sep 20, 2022
7 changes: 3 additions & 4 deletions src/components/accordion/accordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ let id = 0;
const getId = () => `${id++}`;

describe('EuiAccordion', () => {
shouldRenderCustomStyles(<EuiAccordion id="styles" />, [
'buttonProps',
'arrowProps',
]);
shouldRenderCustomStyles(<EuiAccordion id="styles" />, {
childProps: ['buttonProps', 'arrowProps'],
});

test('is rendered', () => {
const component = render(<EuiAccordion id={getId()} {...requiredProps} />);
Expand Down
9 changes: 8 additions & 1 deletion src/components/badge/badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ import { shouldRenderCustomStyles } from '../../test/internal';
import { EuiBadge, COLORS, ICON_SIDES } from './badge';

describe('EuiBadge', () => {
shouldRenderCustomStyles(<EuiBadge {...requiredProps} />);
shouldRenderCustomStyles(
<EuiBadge
iconType="cross"
iconOnClick={() => {}}
iconOnClickAriaLabel="Close"
/>,
{ childProps: ['closeButtonProps'] }
);

test('is rendered', () => {
const component = render(<EuiBadge {...requiredProps}>Content</EuiBadge>);
Expand Down
6 changes: 6 additions & 0 deletions src/components/badge/beta_badge/beta_badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiBetaBadge, COLORS, SIZES } from './beta_badge';

describe('EuiBetaBadge', () => {
shouldRenderCustomStyles(
<EuiBetaBadge label="Hello" tooltipContent="World" />,
{ childProps: ['anchorProps'] }
);

test('is rendered', () => {
const component = render(<EuiBetaBadge label="Beta" {...requiredProps} />);

Expand Down
5 changes: 5 additions & 0 deletions src/components/button/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { shouldRenderCustomStyles } from '../../test/internal';

import { EuiButton, COLORS, SIZES } from './button';

Expand All @@ -18,6 +19,10 @@ import {
} from './button_display/_button_display_content';

describe('EuiButton', () => {
shouldRenderCustomStyles(<EuiButton>Content</EuiButton>, {
childProps: ['contentProps'],
});

test('is rendered', () => {
const component = render(<EuiButton {...requiredProps}>Content</EuiButton>);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiButtonDisplay renders 1`] = `
<button
aria-label="aria-label"
class="testClass1 testClass2 emotion-euiButtonDisplay-m-m"
data-test-subj="test subject string"
type="button"
>
<span
class="emotion-euiButtonDisplayContent"
>
<span
class="eui-textTruncate"
>
Content
</span>
</span>
</button>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiButtonDisplayContent renders 1`] = `
<span
aria-label="aria-label"
class="testClass1 testClass2 emotion-euiButtonDisplayContent"
data-test-subj="test subject string"
>
<span
class="eui-textTruncate"
>
Content
</span>
</span>
`;
28 changes: 28 additions & 0 deletions src/components/button/button_display/_button_display.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { render } from '@testing-library/react';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiButtonDisplay } from './_button_display';

describe('EuiButtonDisplay', () => {
shouldRenderCustomStyles(<EuiButtonDisplay>Text</EuiButtonDisplay>, {
childProps: ['textProps'],
});

it('renders', () => {
const { container } = render(
<EuiButtonDisplay {...requiredProps}>Content</EuiButtonDisplay>
);

expect(container.firstChild).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { render } from '@testing-library/react';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiButtonDisplayContent } from './_button_display_content';

describe('EuiButtonDisplayContent', () => {
shouldRenderCustomStyles(
<EuiButtonDisplayContent>Text</EuiButtonDisplayContent>,
{ childProps: ['textProps'] }
);

it('renders', () => {
const { container } = render(
<EuiButtonDisplayContent {...requiredProps}>
Content
</EuiButtonDisplayContent>
);

expect(container.firstChild).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const EuiButtonDisplayContent: FunctionComponent<
const isText = typeof children === 'string';

return (
<span {...contentProps} css={cssStyles}>
<span css={cssStyles} {...contentProps}>
{icon}
{isText ? (
<span
Expand Down
8 changes: 4 additions & 4 deletions src/components/button/button_empty/button_empty.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { ICON_SIDES } from '../_button_content_deprecated';
import { BUTTON_COLORS } from '../../../themes/amsterdam/global_styling/mixins';

describe('EuiButtonEmpty', () => {
shouldRenderCustomStyles(<EuiButtonEmpty>Content</EuiButtonEmpty>, {
childProps: ['contentProps'],
});

test('is rendered', () => {
const component = render(
<EuiButtonEmpty {...requiredProps}>Content</EuiButtonEmpty>
Expand All @@ -24,10 +28,6 @@ describe('EuiButtonEmpty', () => {
expect(component).toMatchSnapshot();
});

shouldRenderCustomStyles(
<EuiButtonEmpty {...requiredProps}>Content</EuiButtonEmpty>
);

describe('props', () => {
describe('isDisabled', () => {
it('is rendered', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/card/card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ describe('EuiCard', () => {
expect(component).toMatchSnapshot();
});

shouldRenderCustomStyles(<EuiCard title="Card title" />);
shouldRenderCustomStyles(
<EuiCard title="Card title" betaBadgeProps={{ label: 'beta' }} />,
{ childProps: ['betaBadgeProps'] }
);

describe('props', () => {
test('icon', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiCollapsibleNavGroup, BACKGROUNDS } from './collapsible_nav_group';

describe('EuiCollapsibleNavGroup', () => {
shouldRenderCustomStyles(
<EuiCollapsibleNavGroup iconType="logoElastic" title="Test" />,
{ childProps: ['iconProps'] }
);

test('is rendered', () => {
const component = render(
<EuiCollapsibleNavGroup id="id" {...requiredProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('EuiDescriptionList', () => {
<EuiDescriptionList
listItems={[{ title: 'hello', description: 'world' }]}
/>,
['titleProps', 'descriptionProps']
{ childProps: ['titleProps', 'descriptionProps'] }
);

test('is rendered', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/expression/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EuiExpression, COLORS } from './expression';
describe('EuiExpression', () => {
shouldRenderCustomStyles(
<EuiExpression description="the answer is" value="42" />,
['descriptionProps', 'valueProps']
{ childProps: ['descriptionProps', 'valueProps'] }
);

test('renders', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/flyout/flyout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { requiredProps, takeMountedSnapshot } from '../../test';
import { shouldRenderCustomStyles } from '../../test/internal';

import { EuiFlyout, SIZES, PADDING_SIZES, SIDES } from './flyout';

Expand All @@ -23,6 +24,11 @@ jest.mock('../portal', () => ({
}));

describe('EuiFlyout', () => {
shouldRenderCustomStyles(
<EuiFlyout {...requiredProps} onClose={() => {}} />,
{ childProps: ['closeButtonProps', 'maskProps'] }
);

test('is rendered', () => {
const component = mount(
<EuiFlyout {...requiredProps} onClose={() => {}} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/flyout/flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ export const EuiFlyout = forwardRef(
{...focusTrapProps}
>
<Element
css={cssStyles}
{...(rest as ComponentPropsWithRef<T>)}
role={role}
className={classes}
tabIndex={-1}
style={newStyle}
ref={setRef}
css={cssStyles}
>
{closeButton}
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import { requiredProps } from '../../../test';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiFormRow } from '../form_row';
import { EuiDescribedFormGroup } from './described_form_group';
Expand All @@ -19,6 +20,10 @@ describe('EuiDescribedFormGroup', () => {
description: 'Test description',
};

shouldRenderCustomStyles(<EuiDescribedFormGroup {...props} />, {
childProps: ['descriptionFlexItemProps', 'fieldFlexItemProps'],
});

test('is rendered', () => {
const component = shallow(
<EuiDescribedFormGroup {...requiredProps} {...props}>
Expand Down
5 changes: 5 additions & 0 deletions src/components/form/field_password/field_password.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { render, mount } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiFieldPassword, EuiFieldPasswordProps } from './field_password';

Expand All @@ -23,6 +24,10 @@ const TYPES: Array<EuiFieldPasswordProps['type']> = [
];

describe('EuiFieldPassword', () => {
shouldRenderCustomStyles(<EuiFieldPassword type="dual" />, {
childProps: ['dualToggleProps'],
});

test('is rendered', () => {
const component = render(
<EuiFieldPassword
Expand Down
6 changes: 6 additions & 0 deletions src/components/form/radio/radio.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiRadio } from './radio';

describe('EuiRadio', () => {
shouldRenderCustomStyles(
<EuiRadio onChange={() => {}} id="id" label="test" />,
{ childProps: ['labelProps'] }
);

test('is rendered', () => {
const component = render(
<EuiRadio id="id" onChange={() => {}} {...requiredProps} />
Expand Down
6 changes: 6 additions & 0 deletions src/components/form/super_select/super_select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { mount, render } from 'enzyme';
import { requiredProps, takeMountedSnapshot } from '../../../test';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiSuperSelect } from './super_select';

Expand All @@ -22,6 +23,11 @@ const options = [
];

describe('EuiSuperSelect', () => {
shouldRenderCustomStyles(
<EuiSuperSelect options={options} onChange={() => {}} />,
{ childProps: ['popoverProps'] }
);

test('is rendered', () => {
const component = render(
<EuiSuperSelect
Expand Down
4 changes: 3 additions & 1 deletion src/components/image/image.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ describe('EuiImage', () => {
src: '/cat.jpg',
};

shouldRenderCustomStyles(<EuiImage {...requiredProps} />, ['wrapperProps']);
shouldRenderCustomStyles(<EuiImage {...requiredProps} />, {
childProps: ['wrapperProps'],
});

test('is rendered', () => {
const component = render(<EuiImage {...requiredProps} />);
Expand Down
12 changes: 12 additions & 0 deletions src/components/markdown_editor/markdown_editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
import React from 'react';
import { render, mount, ReactWrapper } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { shouldRenderCustomStyles } from '../../test/internal';

import { EuiMarkdownEditor } from './markdown_editor';
import * as MarkdownTooltip from './plugins/markdown_tooltip';
import MarkdownActions from './markdown_actions';
import { getDefaultEuiMarkdownPlugins } from './plugins/markdown_default_plugins';

describe('EuiMarkdownEditor', () => {
shouldRenderCustomStyles(
<EuiMarkdownEditor
{...requiredProps}
onChange={() => {}}
value="Test"
initialViewMode="viewing"
/>,
{ childProps: ['markdownFormatProps'] }
);

test('is rendered', () => {
const component = render(
<EuiMarkdownEditor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`EuiNotificationEvent is rendered 1`] = `
<article
aria-label="aria-label"
aria-labelledby="generated-id"
class="euiNotificationEvent className"
class="euiNotificationEvent testClass1 testClass2"
data-test-subj="test subject string"
>
<div
Expand Down
Loading