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

[7.x] Use EuiThemeProvider in lists plugin tests and stories (#96129) #97027

Merged
merged 3 commits into from
Apr 15, 2021
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
13 changes: 0 additions & 13 deletions x-pack/plugins/lists/public/common/test_utils/kibana_react.mock.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,17 @@
* 2.0.
*/

import { Story, addDecorator } from '@storybook/react';
import { Story } from '@storybook/react';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import { getMockTheme } from '../../../common/test_utils/kibana_react.mock';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';

import { AndOrBadge, AndOrBadgeProps } from '.';

const sampleText =
'Doggo ipsum i am bekom fat snoot wow such tempt waggy wags floofs, ruff heckin good boys and girls mlem. Ruff heckin good boys and girls mlem stop it fren borkf borking doggo very hand that feed shibe, you are doing me the shock big ol heck smol borking doggo with a long snoot for pats heckin good boys. You are doing me the shock smol borking doggo with a long snoot for pats wow very biscit, length boy. Doggo ipsum i am bekom fat snoot wow such tempt waggy wags floofs, ruff heckin good boys and girls mlem. Ruff heckin good boys and girls mlem stop it fren borkf borking doggo very hand that feed shibe, you are doing me the shock big ol heck smol borking doggo with a long snoot for pats heckin good boys.';

const mockTheme = getMockTheme({
darkMode: false,
eui: euiLightVars,
});

addDecorator((storyFn) => <ThemeProvider theme={mockTheme}>{storyFn()}</ThemeProvider>);

export default {
argTypes: {
includeAntennas: {
Expand Down Expand Up @@ -58,6 +49,13 @@ export default {
},
},
component: AndOrBadge,
decorators: [
(DecoratorStory: React.ComponentClass): React.ReactNode => (
<EuiThemeProvider>
<DecoratorStory />
</EuiThemeProvider>
),
],
title: 'AndOrBadge',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
*/

import React from 'react';
import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';

import { getMockTheme } from '../../../common/test_utils/kibana_react.mock';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';

import { AndOrBadge } from './';

const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });

describe('AndOrBadge', () => {
test('it renders top and bottom antenna bars when "includeAntennas" is true', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<AndOrBadge includeAntennas type="and" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('AND');
Expand All @@ -30,9 +27,9 @@ describe('AndOrBadge', () => {

test('it does not render top and bottom antenna bars when "includeAntennas" is false', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<AndOrBadge type="or" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('OR');
Expand All @@ -42,19 +39,19 @@ describe('AndOrBadge', () => {

test('it renders "and" when "type" is "and"', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<AndOrBadge type="and" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('AND');
});

test('it renders "or" when "type" is "or"', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<AndOrBadge type="or" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('OR');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
*/

import React from 'react';
import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';

import { getMockTheme } from '../../../common/test_utils/kibana_react.mock';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';

import { RoundedBadgeAntenna } from './rounded_badge_antenna';

const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });

describe('RoundedBadgeAntenna', () => {
test('it renders top and bottom antenna bars', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<RoundedBadgeAntenna type="and" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('AND');
Expand All @@ -30,19 +27,19 @@ describe('RoundedBadgeAntenna', () => {

test('it renders "and" when "type" is "and"', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<RoundedBadgeAntenna type="and" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('AND');
});

test('it renders "or" when "type" is "or"', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<RoundedBadgeAntenna type="or" />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="and-or-badge"]').at(0).text()).toEqual('OR');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@
*/

import React from 'react';
import { ThemeProvider } from 'styled-components';
import { mount } from 'enzyme';

import { getMockTheme } from '../../../common/test_utils/kibana_react.mock';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';

import { BuilderAndBadgeComponent } from './and_badge';

const mockTheme = getMockTheme({ eui: { euiColorLightShade: '#ece' } });

describe('BuilderAndBadgeComponent', () => {
test('it renders exceptionItemEntryFirstRowAndBadge for very first exception item in builder', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<BuilderAndBadgeComponent entriesLength={2} exceptionItemIndex={0} />
</ThemeProvider>
</EuiThemeProvider>
);

expect(
Expand All @@ -30,9 +27,9 @@ describe('BuilderAndBadgeComponent', () => {

test('it renders exceptionItemEntryInvisibleAndBadge if "entriesLength" is 1 or less', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<BuilderAndBadgeComponent entriesLength={1} exceptionItemIndex={0} />
</ThemeProvider>
</EuiThemeProvider>
);

expect(
Expand All @@ -42,9 +39,9 @@ describe('BuilderAndBadgeComponent', () => {

test('it renders regular "and" badge if exception item is not the first one and includes more than one entry', () => {
const wrapper = mount(
<ThemeProvider theme={mockTheme}>
<EuiThemeProvider>
<BuilderAndBadgeComponent entriesLength={2} exceptionItemIndex={1} />
</ThemeProvider>
</EuiThemeProvider>
);

expect(wrapper.find('[data-test-subj="exceptionItemEntryAndBadge"]').exists()).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

import { Story, addDecorator } from '@storybook/react';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
import { HttpStart } from 'kibana/public';

import { AutocompleteStart } from '../../../../../../../src/plugins/data/public';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';
import {
fields,
getField,
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
import { getMockTheme } from '../../../common/test_utils/kibana_react.mock';
import { getEntryMatchAnyMock } from '../../../../common/schemas/types/entry_match_any.mock';
import { getEntryMatchMock } from '../../../../common/schemas/types/entry_match.mock';
import { getEntryExistsMock } from '../../../../common/schemas/types/entry_exists.mock';
Expand All @@ -35,10 +33,6 @@ import {
OnChangeProps,
} from './exception_items_renderer';

const mockTheme = getMockTheme({
darkMode: false,
eui: euiLightVars,
});
const mockHttpService: HttpStart = ({
addLoadingCountSource: (): void => {},
anonymousPaths: {
Expand Down Expand Up @@ -76,7 +70,7 @@ const mockAutocompleteService = ({
}),
} as unknown) as AutocompleteStart;

addDecorator((storyFn) => <ThemeProvider theme={mockTheme}>{storyFn()}</ThemeProvider>);
addDecorator((storyFn) => <EuiThemeProvider>{storyFn()}</EuiThemeProvider>);

export default {
argTypes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
* 2.0.
*/

import { Story, addDecorator } from '@storybook/react';
import { Story } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
import { HttpStart } from 'kibana/public';

import { OperatorEnum, OperatorTypeEnum } from '../../../../common';
import { AutocompleteStart } from '../../../../../../../src/plugins/data/public';
import { fields } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
import { getMockTheme } from '../../../common/test_utils/kibana_react.mock';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';

import { BuilderEntryItem, EntryItemProps } from './entry_renderer';

const mockTheme = getMockTheme({
darkMode: false,
eui: euiLightVars,
});
const mockAutocompleteService = ({
getValueSuggestions: () =>
new Promise((resolve) => {
Expand Down Expand Up @@ -59,8 +53,6 @@ const mockAutocompleteService = ({
}),
} as unknown) as AutocompleteStart;

addDecorator((storyFn) => <ThemeProvider theme={mockTheme}>{storyFn()}</ThemeProvider>);

export default {
argTypes: {
allowLargeValueLists: {
Expand Down Expand Up @@ -163,6 +155,13 @@ export default {
},
},
component: BuilderEntryItem,
decorators: [
(DecoratorStory: React.ComponentClass): React.ReactNode => (
<EuiThemeProvider>
<DecoratorStory />
</EuiThemeProvider>
),
],
title: 'BuilderEntryItem',
};

Expand Down
Loading