Skip to content

Commit

Permalink
[Lens] Prepare Lens for jest-environment-jsdom migration (#95327) (#9…
Browse files Browse the repository at this point in the history
…5530)

* 🐛 Fix activeElement issue with Jest

* 🏷️ Fix type issue

* 👌 Removed expect-errors directives

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Marco Liberati <[email protected]>
  • Loading branch information
kibanamachine and dej611 authored Mar 26, 2021
1 parent fe3a6e0 commit a0da4c9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/kbn-test/src/jest/utils/enzyme_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function mountWithIntl<T>(
childContextTypes,
...props
}: {
attachTo?: HTMLElement;
context?: any;
childContextTypes?: ValidationMap<any>;
} = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ import { generateId } from '../../../id_generator';

jest.mock('../../../id_generator');

let container: HTMLDivElement | undefined;

beforeEach(() => {
container = document.createElement('div');
container.id = 'lensContainer';
document.body.appendChild(container);
});

afterEach(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}

container = undefined;
});

describe('ConfigPanel', () => {
let mockVisualization: jest.Mocked<Visualization>;
let mockVisualization2: jest.Mocked<Visualization>;
Expand Down Expand Up @@ -105,7 +121,9 @@ describe('ConfigPanel', () => {

describe('focus behavior when adding or removing layers', () => {
it('should focus the only layer when resetting the layer', () => {
const component = mountWithIntl(<LayerPanels {...getDefaultProps()} />);
const component = mountWithIntl(<LayerPanels {...getDefaultProps()} />, {
attachTo: container,
});
const firstLayerFocusable = component
.find(LayerPanel)
.first()
Expand All @@ -126,7 +144,7 @@ describe('ConfigPanel', () => {
first: mockDatasource.publicAPIMock,
second: mockDatasource.publicAPIMock,
};
const component = mountWithIntl(<LayerPanels {...defaultProps} />);
const component = mountWithIntl(<LayerPanels {...defaultProps} />, { attachTo: container });
const secondLayerFocusable = component
.find(LayerPanel)
.at(1)
Expand All @@ -147,7 +165,7 @@ describe('ConfigPanel', () => {
first: mockDatasource.publicAPIMock,
second: mockDatasource.publicAPIMock,
};
const component = mountWithIntl(<LayerPanels {...defaultProps} />);
const component = mountWithIntl(<LayerPanels {...defaultProps} />, { attachTo: container });
const firstLayerFocusable = component
.find(LayerPanel)
.first()
Expand All @@ -169,7 +187,9 @@ describe('ConfigPanel', () => {
}
});

const component = mountWithIntl(<LayerPanels {...getDefaultProps()} dispatch={dispatch} />);
const component = mountWithIntl(<LayerPanels {...getDefaultProps()} dispatch={dispatch} />, {
attachTo: container,
});
act(() => {
component.find('[data-test-subj="lnsLayerAddButton"]').first().simulate('click');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,38 @@

import React from 'react';
import { act } from 'react-dom/test-utils';
import { EuiFormRow } from '@elastic/eui';
import { mountWithIntl } from '@kbn/test/jest';
import { Visualization } from '../../../types';
import { LayerPanel } from './layer_panel';
import { ChildDragDropProvider, DragDrop } from '../../../drag_drop';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { generateId } from '../../../id_generator';
import {
createMockVisualization,
createMockFramePublicAPI,
createMockDatasource,
DatasourceMock,
} from '../../mocks';
import { ChildDragDropProvider, DragDrop } from '../../../drag_drop';
import { EuiFormRow } from '@elastic/eui';
import { mountWithIntl } from '@kbn/test/jest';
import { Visualization } from '../../../types';
import { LayerPanel } from './layer_panel';
import { coreMock } from 'src/core/public/mocks';
import { generateId } from '../../../id_generator';

jest.mock('../../../id_generator');

let container: HTMLDivElement | undefined;

beforeEach(() => {
container = document.createElement('div');
container.id = 'lensContainer';
document.body.appendChild(container);
});

afterEach(() => {
if (container && container.parentNode) {
container.parentNode.removeChild(container);
}

container = undefined;
});

const defaultContext = {
dragging: undefined,
setDragging: jest.fn(),
Expand Down Expand Up @@ -642,7 +658,8 @@ describe('LayerPanel', () => {
const component = mountWithIntl(
<ChildDragDropProvider {...defaultContext} dragging={draggingOperation}>
<LayerPanel {...getDefaultProps()} />
</ChildDragDropProvider>
</ChildDragDropProvider>,
{ attachTo: container }
);
act(() => {
component.find(DragDrop).at(1).prop('onDrop')!(draggingOperation, 'reorder');
Expand Down

0 comments on commit a0da4c9

Please sign in to comment.