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

unskip jest tests due to unhandled promise rejections #149648

Merged
merged 6 commits into from
Jan 30, 2023
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 @@ -10,24 +10,39 @@
import sizeMe from 'react-sizeme';
import React from 'react';

import {
ContactCardEmbeddableFactory,
CONTACT_CARD_EMBEDDABLE,
} from '@kbn/embeddable-plugin/public/lib/test_samples/embeddables';
import { CONTACT_CARD_EMBEDDABLE } from '@kbn/embeddable-plugin/public/lib/test_samples/embeddables';
import { mountWithIntl } from '@kbn/test-jest-helpers';

import { pluginServices } from '../../../services/plugin_services';
import { DashboardGrid } from './dashboard_grid';
import { getSampleDashboardInput, mockDashboardReduxEmbeddableTools } from '../../../mocks';
import { DashboardContainer } from '../../embeddable/dashboard_container';
import { getSampleDashboardInput } from '../../../mocks';
import type { Props as DashboardGridItemProps } from './dashboard_grid_item';

const DashboardServicesProvider = pluginServices.getContextProvider();
jest.mock('./dashboard_grid_item', () => {
return {
// eslint-disable-next-line @typescript-eslint/no-var-requires
DashboardGridItem: require('react').forwardRef(
(props: DashboardGridItemProps, ref: HTMLDivElement) => {
const className =
props.expandedPanelId === undefined
? 'regularPanel'
: props.expandedPanelId === props.id
? 'expandedPanel'
: 'hiddenPanel';
return (
<div className={className} id={`mockDashboardGridItem_${props.id}`}>
mockDashboardGridItem
</div>
);
}
),
};
});

async function prepare() {
const embeddableFactory = new ContactCardEmbeddableFactory((() => null) as any, {} as any);
pluginServices.getServices().embeddable.getEmbeddableFactory = jest
.fn()
.mockReturnValue(embeddableFactory);
const DashboardServicesProvider = pluginServices.getContextProvider();

async function getDashboardContainer() {
const initialInput = getSampleDashboardInput({
panels: {
'1': {
Expand All @@ -42,12 +57,9 @@ async function prepare() {
},
},
});
const dashboardMock = await mockDashboardReduxEmbeddableTools({ explicitInput: initialInput });
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for figuring out what was going wrong here with the two redux stores!


return {
tools: dashboardMock.tools,
dashboardContainer: dashboardMock.dashboardContainer,
};
const dashboardContainer = new DashboardContainer(initialInput);
await dashboardContainer.untilInitialized();
return dashboardContainer;
}

beforeAll(() => {
Expand All @@ -60,45 +72,47 @@ afterAll(() => {
sizeMe.noPlaceholders = false;
});

// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
test.skip('renders DashboardGrid', async () => {
const { tools } = await prepare();
test('renders DashboardGrid', async () => {
const dashboardContainer = await getDashboardContainer();
const { Wrapper: DashboardReduxWrapper } = dashboardContainer.getReduxEmbeddableTools();

const component = mountWithIntl(
<DashboardServicesProvider>
<tools.Wrapper>
<DashboardReduxWrapper>
<DashboardGrid />
</tools.Wrapper>
</DashboardReduxWrapper>
</DashboardServicesProvider>
);
const panelElements = component.find('EmbeddableChildPanel');
const panelElements = component.find('GridItem');
expect(panelElements.length).toBe(2);
});

// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
test.skip('renders DashboardGrid with no visualizations', async () => {
const { tools, dashboardContainer } = await prepare();
test('renders DashboardGrid with no visualizations', async () => {
const dashboardContainer = await getDashboardContainer();
const { Wrapper: DashboardReduxWrapper } = dashboardContainer.getReduxEmbeddableTools();

const component = mountWithIntl(
<DashboardServicesProvider>
<tools.Wrapper>
<DashboardReduxWrapper>
<DashboardGrid />
</tools.Wrapper>
</DashboardReduxWrapper>
</DashboardServicesProvider>
);

dashboardContainer.updateInput({ panels: {} });
component.update();
expect(component.find('EmbeddableChildPanel').length).toBe(0);
expect(component.find('GridItem').length).toBe(0);
});

// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
test.skip('DashboardGrid removes panel when removed from container', async () => {
const { tools, dashboardContainer } = await prepare();
test('DashboardGrid removes panel when removed from container', async () => {
const dashboardContainer = await getDashboardContainer();
const { Wrapper: DashboardReduxWrapper } = dashboardContainer.getReduxEmbeddableTools();

const component = mountWithIntl(
<DashboardServicesProvider>
<tools.Wrapper>
<DashboardReduxWrapper>
<DashboardGrid />
</tools.Wrapper>
</DashboardReduxWrapper>
</DashboardServicesProvider>
);

Expand All @@ -107,35 +121,34 @@ test.skip('DashboardGrid removes panel when removed from container', async () =>
delete filteredPanels['1'];
dashboardContainer.updateInput({ panels: filteredPanels });
component.update();
const panelElements = component.find('EmbeddableChildPanel');
const panelElements = component.find('GridItem');
expect(panelElements.length).toBe(1);
});

// unhandled promise rejection: https://github.com/elastic/kibana/issues/112699
test.skip('DashboardGrid renders expanded panel', async () => {
const { tools, dashboardContainer } = await prepare();
test('DashboardGrid renders expanded panel', async () => {
const dashboardContainer = await getDashboardContainer();
const { Wrapper: DashboardReduxWrapper } = dashboardContainer.getReduxEmbeddableTools();

const component = mountWithIntl(
<DashboardServicesProvider>
<tools.Wrapper>
<DashboardReduxWrapper>
<DashboardGrid />
</tools.Wrapper>
</DashboardReduxWrapper>
</DashboardServicesProvider>
);

dashboardContainer.setExpandedPanelId('1');
component.update();
// Both panels should still exist in the dom, so nothing needs to be re-fetched once minimized.
expect(component.find('EmbeddableChildPanel').length).toBe(2);
expect(component.find('GridItem').length).toBe(2);

expect(
(component.find('DashboardGridUi').state() as { expandedPanelId?: string }).expandedPanelId
).toBe('1');
expect(component.find('#mockDashboardGridItem_1').hasClass('expandedPanel')).toBe(true);
expect(component.find('#mockDashboardGridItem_2').hasClass('hiddenPanel')).toBe(true);

dashboardContainer.setExpandedPanelId();
component.update();
expect(component.find('EmbeddableChildPanel').length).toBe(2);
expect(component.find('GridItem').length).toBe(2);

expect(
(component.find('DashboardGridUi').state() as { expandedPanelId?: string }).expandedPanelId
).toBeUndefined();
expect(component.find('#mockDashboardGridItem_1').hasClass('regularPanel')).toBe(true);
expect(component.find('#mockDashboardGridItem_2').hasClass('regularPanel')).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useDashboardContainerContext } from '../../dashboard_container_renderer

type DivProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'className' | 'style' | 'children'>;

interface Props extends DivProps {
export interface Props extends DivProps {
id: DashboardPanelState['explicitInput']['id'];
index?: number;
type: DashboardPanelState['type'];
Expand Down