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 (#199479)

1. Speeds up functional test suite by setting the time picker via ui
settings
2. removes legacy tests from editor frame (replaced by adding some
conditions to drag_drop functional tests) as they were not the best
tests anyway
  • Loading branch information
mbondyra authored Nov 12, 2024
1 parent fd5b40d commit 13e9b99
Show file tree
Hide file tree
Showing 53 changed files with 69 additions and 388 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('input control options', () => {
before(async () => {
await visualize.initTests();
await timePicker.resetDefaultAbsoluteRangeViaUiSettings();
await common.navigateToApp('visualize');
await visualize.loadSavedVisualization('input control options', {
navigateToVisualize: false,
Expand Down
2 changes: 2 additions & 0 deletions test/functional/page_objects/visualize_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class VisualizePageObject extends FtrService {
private readonly elasticChart = this.ctx.getService('elasticChart');
private readonly common = this.ctx.getPageObject('common');
private readonly header = this.ctx.getPageObject('header');
private readonly timePicker = this.ctx.getPageObject('timePicker');
private readonly visChart = this.ctx.getPageObject('visChart');
private readonly toasts = this.ctx.getService('toasts');

Expand All @@ -63,6 +64,7 @@ export class VisualizePageObject extends FtrService {
[FORMATS_UI_SETTINGS.FORMAT_BYTES_DEFAULT_PATTERN]: '0,0.[000]b',
'visualization:visualize:legacyHeatmapChartsLibrary': isLegacyChart,
'histogram:maxBars': 100,
'timepicker:timeDefaults': `{ "from": "${this.timePicker.defaultStartTimeUTC}", "to": "${this.timePicker.defaultEndTimeUTC}"}`,
});
}

Expand Down
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 13e9b99

Please sign in to comment.