Skip to content

Commit a8c3e9d

Browse files
committed
Update EngineOverviewHeader to disable button on prop
1 parent ad247dc commit a8c3e9d

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

Diff for: x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ErrorState: ReactFC<> = () => {
2525
<SendTelemetry action="error" metric="cannot_connect" />
2626

2727
<EuiPageBody>
28-
<EngineOverviewHeader />
28+
<EngineOverviewHeader isButtonDisabled />
2929
<EuiPageContent>
3030
<EuiEmptyPrompt
3131
iconType="alert"

Diff for: x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx

+18-39
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import '../../../__mocks__/shallow_usecontext.mock';
88

9-
import React, { useContext } from 'react';
9+
import React from 'react';
1010
import { shallow } from 'enzyme';
1111

1212
jest.mock('../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() }));
@@ -15,48 +15,27 @@ import { sendTelemetry } from '../../../shared/telemetry';
1515
import { EngineOverviewHeader } from '../engine_overview_header';
1616

1717
describe('EngineOverviewHeader', () => {
18-
describe('when enterpriseSearchUrl is set', () => {
19-
let button;
20-
21-
beforeAll(() => {
22-
useContext.mockImplementationOnce(() => ({ enterpriseSearchUrl: 'http://localhost:3002' }));
23-
const wrapper = shallow(<EngineOverviewHeader />);
24-
button = wrapper.find('[data-test-subj="launchButton"]');
25-
});
26-
27-
describe('the Launch App Search button', () => {
28-
it('should not be disabled', () => {
29-
expect(button.props().isDisabled).toBeFalsy();
30-
});
31-
32-
it('should use the enterpriseSearchUrl as the base path for its href', () => {
33-
expect(button.props().href).toBe('http://localhost:3002/as');
34-
});
35-
36-
it('should send telemetry when clicked', () => {
37-
button.simulate('click');
38-
expect(sendTelemetry).toHaveBeenCalled();
39-
});
40-
});
18+
it('renders', () => {
19+
const wrapper = shallow(<EngineOverviewHeader />);
20+
expect(wrapper.find('h1')).toHaveLength(1);
4121
});
4222

43-
describe('when enterpriseSearchUrl is not set', () => {
44-
let button;
23+
it('renders a launch app search button that sends telemetry on click', () => {
24+
const wrapper = shallow(<EngineOverviewHeader />);
25+
const button = wrapper.find('[data-test-subj="launchButton"]');
4526

46-
beforeAll(() => {
47-
useContext.mockImplementationOnce(() => ({ enterpriseSearchUrl: undefined }));
48-
const wrapper = shallow(<EngineOverviewHeader />);
49-
button = wrapper.find('[data-test-subj="launchButton"]');
50-
});
27+
expect(button.props().href).toBe('http://localhost:3002/as');
28+
expect(button.props().isDisabled).toBeFalsy();
5129

52-
describe('the Launch App Search button', () => {
53-
it('should be disabled', () => {
54-
expect(button.props().isDisabled).toBe(true);
55-
});
30+
button.simulate('click');
31+
expect(sendTelemetry).toHaveBeenCalled();
32+
});
33+
34+
it('renders a disabled button when isButtonDisabled is true', () => {
35+
const wrapper = shallow(<EngineOverviewHeader isButtonDisabled />);
36+
const button = wrapper.find('[data-test-subj="launchButton"]');
5637

57-
it('should not have an href', () => {
58-
expect(button.props().href).toBeUndefined();
59-
});
60-
});
38+
expect(button.props().isDisabled).toBe(true);
39+
expect(button.props().href).toBeUndefined();
6140
});
6241
});

Diff for: x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ import { FormattedMessage } from '@kbn/i18n/react';
1111
import { sendTelemetry } from '../../../shared/telemetry';
1212
import { KibanaContext, IKibanaContext } from '../../../index';
1313

14-
export const EngineOverviewHeader: React.FC<> = () => {
14+
interface IEngineOverviewHeaderProps {
15+
isButtonDisabled?: boolean;
16+
}
17+
18+
export const EngineOverviewHeader: React.FC<IEngineOverviewHeaderProps> = ({
19+
isButtonDisabled,
20+
}) => {
1521
const { enterpriseSearchUrl, http } = useContext(KibanaContext) as IKibanaContext;
1622

1723
const buttonProps = {
1824
fill: true,
1925
iconType: 'popout',
20-
['data-test-subj']: 'launchButton',
26+
'data-test-subj': 'launchButton',
2127
};
22-
if (enterpriseSearchUrl) {
28+
if (isButtonDisabled) {
29+
buttonProps.isDisabled = true;
30+
} else {
2331
buttonProps.href = `${enterpriseSearchUrl}/as`;
2432
buttonProps.target = '_blank';
2533
buttonProps.onClick = () =>
@@ -29,8 +37,6 @@ export const EngineOverviewHeader: React.FC<> = () => {
2937
action: 'clicked',
3038
metric: 'header_launch_button',
3139
});
32-
} else {
33-
buttonProps.isDisabled = true;
3440
}
3541

3642
return (

0 commit comments

Comments
 (0)