From 6e4f1ed4d95ed65639e1fa9ce023ffe56bd3b55a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 26 Jul 2023 05:50:41 -0400 Subject: [PATCH] [8.9] [SecuritySolution] Add dashboard controls (#162514) (#162548) # Backport This will backport the following commits from `main` to `8.9`: - [[SecuritySolution] Add dashboard controls (#162514)](https://github.com/elastic/kibana/pull/162514) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Angela Chuang <6295984+angorayc@users.noreply.github.com> --- .../components/dashboard_renderer.test.tsx | 35 +++++++++++++++---- .../components/dashboard_renderer.tsx | 1 + 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.test.tsx b/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.test.tsx index 9498a0f12713c..c01f07fa36653 100644 --- a/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.test.tsx @@ -6,6 +6,9 @@ */ import { render } from '@testing-library/react'; import React from 'react'; +import { ViewMode } from '@kbn/embeddable-plugin/public'; +import { DashboardRenderer as DashboardContainerRenderer } from '@kbn/dashboard-plugin/public'; + import { TestProviders } from '../../common/mock'; import { DashboardRenderer } from './dashboard_renderer'; @@ -13,9 +16,7 @@ jest.mock('@kbn/dashboard-plugin/public', () => { const actual = jest.requireActual('@kbn/dashboard-plugin/public'); return { ...actual, - DashboardRenderer: jest - .fn() - .mockImplementation(() =>
), + DashboardRenderer: jest.fn().mockReturnValue(
), }; }); @@ -40,19 +41,41 @@ describe('DashboardRenderer', () => { }, }; + beforeEach(() => { + jest.clearAllMocks(); + }); + it('renders', () => { const { queryByTestId } = render(, { wrapper: TestProviders }); expect(queryByTestId(`dashboardRenderer`)).toBeInTheDocument(); }); - it.skip('does not render when No Read Permission', () => { + it('renders with correct options', async () => { + render(, { wrapper: TestProviders }); + const options = await ( + DashboardContainerRenderer as unknown as jest.Mock + ).mock.calls[0][0].getCreationOptions(); + const input = options.getInitialInput(); + + expect(input).toEqual( + expect.objectContaining({ + timeRange: props.timeRange, + viewMode: ViewMode.VIEW, + query: undefined, + filters: undefined, + }) + ); + expect(options.useControlGroupIntegration).toEqual(true); + }); + + it('does not render when No Read Permission', () => { const testProps = { ...props, canReadDashboard: false, }; - const { queryByTestId } = render(, { + render(, { wrapper: TestProviders, }); - expect(queryByTestId(`dashboardRenderer`)).not.toBeInTheDocument(); + expect(DashboardContainerRenderer).not.toHaveBeenCalled(); }); }); diff --git a/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.tsx b/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.tsx index 9b6a6552bbb8f..aa51842a33c1e 100644 --- a/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.tsx +++ b/x-pack/plugins/security_solution/public/dashboards/components/dashboard_renderer.tsx @@ -45,6 +45,7 @@ const DashboardRendererComponent = ({ () => Promise.resolve({ getInitialInput: () => ({ timeRange, viewMode: ViewMode.VIEW, query, filters }), + useControlGroupIntegration: true, }), [filters, query, timeRange] );