From 5510aaf950f576a2962717906c3717d146b29c43 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Mon, 18 May 2020 11:59:55 -0700 Subject: [PATCH] Update EngineOverviewHeader to disable button on prop --- .../components/empty_states/error_state.tsx | 2 +- .../engine_overview_header.test.tsx | 57 ++++++------------- .../engine_overview_header.tsx | 16 ++++-- 3 files changed, 30 insertions(+), 45 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx index 0725d3650054e81..039e645a271268a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx @@ -25,7 +25,7 @@ export const ErrorState: ReactFC<> = () => { - + ({ sendTelemetry: jest.fn() })); @@ -15,48 +15,27 @@ import { sendTelemetry } from '../../../shared/telemetry'; import { EngineOverviewHeader } from '../engine_overview_header'; describe('EngineOverviewHeader', () => { - describe('when enterpriseSearchUrl is set', () => { - let button; - - beforeAll(() => { - useContext.mockImplementationOnce(() => ({ enterpriseSearchUrl: 'http://localhost:3002' })); - const wrapper = shallow(); - button = wrapper.find('[data-test-subj="launchButton"]'); - }); - - describe('the Launch App Search button', () => { - it('should not be disabled', () => { - expect(button.props().isDisabled).toBeFalsy(); - }); - - it('should use the enterpriseSearchUrl as the base path for its href', () => { - expect(button.props().href).toBe('http://localhost:3002/as'); - }); - - it('should send telemetry when clicked', () => { - button.simulate('click'); - expect(sendTelemetry).toHaveBeenCalled(); - }); - }); + it('renders', () => { + const wrapper = shallow(); + expect(wrapper.find('h1')).toHaveLength(1); }); - describe('when enterpriseSearchUrl is not set', () => { - let button; + it('renders a launch app search button that sends telemetry on click', () => { + const wrapper = shallow(); + const button = wrapper.find('[data-test-subj="launchButton"]'); - beforeAll(() => { - useContext.mockImplementationOnce(() => ({ enterpriseSearchUrl: undefined })); - const wrapper = shallow(); - button = wrapper.find('[data-test-subj="launchButton"]'); - }); + expect(button.props().href).toBe('http://localhost:3002/as'); + expect(button.props().isDisabled).toBeFalsy(); - describe('the Launch App Search button', () => { - it('should be disabled', () => { - expect(button.props().isDisabled).toBe(true); - }); + button.simulate('click'); + expect(sendTelemetry).toHaveBeenCalled(); + }); + + it('renders a disabled button when isButtonDisabled is true', () => { + const wrapper = shallow(); + const button = wrapper.find('[data-test-subj="launchButton"]'); - it('should not have an href', () => { - expect(button.props().href).toBeUndefined(); - }); - }); + expect(button.props().isDisabled).toBe(true); + expect(button.props().href).toBeUndefined(); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx index 20ad3ce5ad27279..650a864f5e615ee 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx @@ -11,15 +11,23 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { sendTelemetry } from '../../../shared/telemetry'; import { KibanaContext, IKibanaContext } from '../../../index'; -export const EngineOverviewHeader: React.FC<> = () => { +interface IEngineOverviewHeaderProps { + isButtonDisabled?: boolean; +} + +export const EngineOverviewHeader: React.FC = ({ + isButtonDisabled, +}) => { const { enterpriseSearchUrl, http } = useContext(KibanaContext) as IKibanaContext; const buttonProps = { fill: true, iconType: 'popout', - ['data-test-subj']: 'launchButton', + 'data-test-subj': 'launchButton', }; - if (enterpriseSearchUrl) { + if (isButtonDisabled) { + buttonProps.isDisabled = true; + } else { buttonProps.href = `${enterpriseSearchUrl}/as`; buttonProps.target = '_blank'; buttonProps.onClick = () => @@ -29,8 +37,6 @@ export const EngineOverviewHeader: React.FC<> = () => { action: 'clicked', metric: 'header_launch_button', }); - } else { - buttonProps.isDisabled = true; } return (