diff --git a/x-pack/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/plugins/lens/public/app_plugin/app.test.tsx index 01244f963e0a6..a2c7c67e1fc77 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.test.tsx @@ -98,9 +98,11 @@ describe('Lens App', () => { }; } + const makeDefaultServicesForApp = () => makeDefaultServices(sessionIdSubject, 'sessionId-1'); + async function mountWith({ props = makeDefaultProps(), - services = makeDefaultServices(sessionIdSubject, 'sessionId-1'), + services = makeDefaultServicesForApp(), preloadedState, }: { props?: jest.Mocked; @@ -150,7 +152,7 @@ describe('Lens App', () => { }); it('updates global filters with store state', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); const indexPattern = { id: 'index1' } as unknown as IndexPattern; const pinnedField = { name: 'pinnedField' } as unknown as FieldSpec; const pinnedFilter = esFilters.buildExistsFilter(pinnedField, indexPattern); @@ -222,7 +224,7 @@ describe('Lens App', () => { it('sets originatingApp breadcrumb when the document title changes', async () => { const props = makeDefaultProps(); - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); props.incomingState = { originatingApp: 'coolContainer' }; services.getOriginatingAppName = jest.fn(() => 'The Coolest Container Ever Made'); @@ -268,7 +270,7 @@ describe('Lens App', () => { describe('TopNavMenu#showDatePicker', () => { it('shows date picker if any used index pattern isTimeBased', async () => { - const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const customServices = makeDefaultServicesForApp(); customServices.data.indexPatterns.get = jest .fn() .mockImplementation((id) => @@ -281,7 +283,7 @@ describe('Lens App', () => { ); }); it('shows date picker if active datasource isTimeBased', async () => { - const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const customServices = makeDefaultServicesForApp(); customServices.data.indexPatterns.get = jest .fn() .mockImplementation((id) => @@ -296,7 +298,7 @@ describe('Lens App', () => { ); }); it('does not show date picker if index pattern nor active datasource is not time based', async () => { - const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const customServices = makeDefaultServicesForApp(); customServices.data.indexPatterns.get = jest .fn() .mockImplementation((id) => @@ -343,7 +345,7 @@ describe('Lens App', () => { ); }); it('handles rejected index pattern', async () => { - const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const customServices = makeDefaultServicesForApp(); customServices.data.indexPatterns.get = jest .fn() .mockImplementation((id) => Promise.reject({ reason: 'Could not locate that data view' })); @@ -391,7 +393,7 @@ describe('Lens App', () => { : undefined, }; - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.attributeService.wrapAttributes = jest .fn() .mockImplementation(async ({ savedObjectId }) => ({ @@ -425,7 +427,7 @@ describe('Lens App', () => { } it('shows a disabled save button when the user does not have permissions', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.application = { ...services.application, capabilities: { @@ -475,7 +477,7 @@ describe('Lens App', () => { it('Shows Save and Return and Save As buttons in create by value mode with originating app', async () => { const props = makeDefaultProps(); - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.dashboardFeatureFlag = { allowByValueEmbeddables: true }; props.incomingState = { originatingApp: 'ultraDashboard', @@ -624,7 +626,7 @@ describe('Lens App', () => { const mockedConsoleDir = jest.spyOn(console, 'dir'); // mocked console.dir to avoid messages in the console when running tests mockedConsoleDir.mockImplementation(() => {}); - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.attributeService.wrapAttributes = jest .fn() .mockRejectedValue({ message: 'failed' }); @@ -698,7 +700,7 @@ describe('Lens App', () => { }); it('checks for duplicate title before saving', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.attributeService.wrapAttributes = jest .fn() .mockReturnValue(Promise.resolve({ savedObjectId: '123' })); @@ -765,7 +767,7 @@ describe('Lens App', () => { }); it('should still be enabled even if the user is missing save permissions', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.application = { ...services.application, capabilities: { @@ -805,7 +807,7 @@ describe('Lens App', () => { }); it('should open inspect panel', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); const { instance } = await mountWith({ services, preloadedState: { isSaveable: true } }); await runInspect(instance); @@ -949,7 +951,7 @@ describe('Lens App', () => { describe('saved query handling', () => { it('does not allow saving when the user is missing the saveQuery permission', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.application = { ...services.application, capabilities: { @@ -1186,7 +1188,7 @@ describe('Lens App', () => { }); it('does not confirm if the user is missing save permissions', async () => { - const services = makeDefaultServices(sessionIdSubject, 'sessionId-1'); + const services = makeDefaultServicesForApp(); services.application = { ...services.application, capabilities: { diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts index 7329e0e037c51..7f1e4aa58dba3 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts @@ -176,7 +176,7 @@ export function getVisualizeFieldSuggestions({ datasourceMap, datasourceStates, visualizationMap, - activeVisualization: visualizationMap?.[Object.keys(visualizationMap)[0]] || null, + activeVisualization, visualizationState: undefined, visualizeTriggerFieldContext, });