Skip to content

Commit

Permalink
[Lens] speed up functional test suite by setting the time picker via …
Browse files Browse the repository at this point in the history
…ui settings
  • Loading branch information
mbondyra committed Nov 7, 2024
1 parent 7c92a10 commit 37afb90
Show file tree
Hide file tree
Showing 36 changed files with 206 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@
* 2.0.
*/

import React, { useEffect } from 'react';
import { ReactWrapper } from 'enzyme';
import React from 'react';
import { screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { EditorFrame, EditorFrameProps } from './editor_frame';
import {
DatasourceMap,
DatasourcePublicAPI,
DatasourceSuggestion,
Visualization,
VisualizationMap,
} from '../../types';
import { act } from '@testing-library/react';
import { DatasourceMap, DatasourcePublicAPI, Visualization, VisualizationMap } from '../../types';
import { coreMock } from '@kbn/core/public/mocks';
import {
createMockVisualization,
Expand All @@ -29,30 +21,16 @@ import {
renderWithReduxStore,
} from '../../mocks';
import { inspectorPluginMock } from '@kbn/inspector-plugin/public/mocks';
import { Droppable, useDragDropContext } from '@kbn/dom-drag-drop';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { expressionsPluginMock } from '@kbn/expressions-plugin/public/mocks';
import { mockDataPlugin, mountWithProvider } from '../../mocks';
import { mockDataPlugin } from '../../mocks';
import { LensAppState, setState } from '../../state_management';
import { getLensInspectorService } from '../../lens_inspector_service';
import { createIndexPatternServiceMock } from '../../mocks/data_views_service_mock';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { EventAnnotationServiceType } from '@kbn/event-annotation-plugin/public';

function generateSuggestion(state = {}): DatasourceSuggestion {
return {
state,
table: {
columns: [],
isMultiRow: true,
layerId: 'first',
changeType: 'unchanged',
},
keptLayerIds: ['first'],
};
}

function wrapDataViewsContract() {
const dataViewsContract = dataViewPluginMocks.createStartContract();
return {
Expand Down Expand Up @@ -437,180 +415,5 @@ describe('editor_frame', () => {
})
);
});
describe('legacy tests', () => {
let instance: ReactWrapper;

afterEach(() => {
instance.unmount();
});

it('should use the currently selected visualization if possible on field drop', async () => {
mockDatasource.getLayers.mockReturnValue(['first', 'second', 'third']);
const suggestionVisState = {};
const props = {
...getDefaultProps(),
visualizationMap: {
testVis: {
...mockVisualization,
getSuggestions: () => [
{
score: 0.2,
state: {},
title: 'Suggestion1',
previewIcon: 'empty',
},
{
score: 0.6,
state: suggestionVisState,
title: 'Suggestion2',
previewIcon: 'empty',
},
],
},
testVis2: {
...mockVisualization2,
getSuggestions: () => [
{
score: 0.8,
state: {},
title: 'Suggestion3',
previewIcon: 'empty',
},
],
},
},
datasourceMap: {
testDatasource: {
...mockDatasource,
getDatasourceSuggestionsForField: () => [generateSuggestion()],
getDatasourceSuggestionsFromCurrentState: () => [generateSuggestion()],
getDatasourceSuggestionsForVisualizeField: () => [generateSuggestion()],
DataPanelComponent: jest.fn().mockImplementation(() => <div />),
},
},
} as EditorFrameProps;
instance = (
await mountWithProvider(<EditorFrame {...props} />, {
preloadedState: {
datasourceStates: {
testDatasource: {
isLoading: false,
state: {
internalState1: '',
},
},
},
},
})
).instance;

instance.update();

act(() => {
instance.find('[data-test-subj="mockVisA"]').find(Droppable).prop('onDrop')!(
{
indexPatternId: '1',
field: {},
id: '1',
humanData: { label: 'draggedField' },
},
'field_add'
);
});

expect(mockVisualization.getConfiguration).toHaveBeenCalledWith(
expect.objectContaining({
state: suggestionVisState,
})
);
});

it('should use the highest priority suggestion available', async () => {
mockDatasource.getLayers.mockReturnValue(['first', 'second', 'third']);
const suggestionVisState = {};
const mockVisualization3 = {
...createMockVisualization('testVis3', ['third']),
getSuggestions: () => [
{
score: 0.9,
state: suggestionVisState,
title: 'Suggestion3',
previewIcon: 'empty',
},
{
score: 0.7,
state: {},
title: 'Suggestion4',
previewIcon: 'empty',
},
],
};

const props = {
...getDefaultProps(),
visualizationMap: {
testVis: {
...mockVisualization,
// do not return suggestions for the currently active vis, otherwise it will be chosen
getSuggestions: () => [],
},
testVis2: {
...mockVisualization2,
getSuggestions: () => [],
},
testVis3: {
...mockVisualization3,
},
},
datasourceMap: {
testDatasource: {
...mockDatasource,
getDatasourceSuggestionsForField: () => [generateSuggestion()],
getDatasourceSuggestionsFromCurrentState: () => [generateSuggestion()],
getDatasourceSuggestionsForVisualizeField: () => [generateSuggestion()],
DataPanelComponent: jest.fn().mockImplementation(() => {
const [, dndDispatch] = useDragDropContext();
useEffect(() => {
dndDispatch({
type: 'startDragging',
payload: {
dragging: {
id: 'draggedField',
humanData: { label: '1' },
},
},
});
}, [dndDispatch]);
return <div />;
}),
},
},
} as EditorFrameProps;

instance = (await mountWithProvider(<EditorFrame {...props} />)).instance;

instance.update();

act(() => {
instance.find(Droppable).filter('[dataTestSubj="lnsWorkspace"]').prop('onDrop')!(
{
indexPatternId: '1',
field: {},
id: '1',
humanData: {
label: 'label',
},
},
'field_add'
);
});

expect(mockVisualization3.getConfiguration).toHaveBeenCalledWith(
expect.objectContaining({
state: suggestionVisState,
})
);
});
});
});
});
Loading

0 comments on commit 37afb90

Please sign in to comment.