From da4881b347a921a9df2172a7bde519f15b5e5d88 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 23 Apr 2020 07:35:50 -0400 Subject: [PATCH 01/10] application.test.ts --- .../public/application.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/application.test.ts diff --git a/x-pack/plugins/enterprise_search/public/application.test.ts b/x-pack/plugins/enterprise_search/public/application.test.ts new file mode 100644 index 00000000000000..b9133b83d7d3f4 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/application.test.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { coreMock } from 'src/core/public/mocks'; +import { renderApp } from './applications'; + +describe('renderApp', () => { + it('mounts and unmounts UI', () => { + const params = coreMock.createAppMountParamters(); + const core = coreMock.createStart(); + + const unmount = renderApp(core, params, {}); + expect(params.element.querySelector('.setup-guide')).not.toBeNull(); + unmount(); + expect(params.element.innerHTML).toEqual(''); + }); +}); From 8beb29b027a9eb8dae77d47bb4034ab4e4cad4c6 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Fri, 24 Apr 2020 13:30:39 -0400 Subject: [PATCH 02/10] Added Unit Test for EngineOverviewHeader --- .../engine_overview_header.test.tsx | 75 +++++++++++++++++++ .../engine_overview_header.tsx | 1 + 2 files changed, 76 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx new file mode 100644 index 00000000000000..2b135cc71c508e --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx @@ -0,0 +1,75 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { mount } from 'enzyme'; + +import { EngineOverviewHeader } from '../engine_overview_header'; +import { KibanaContext } from '../../..'; + +describe('EngineOverviewHeader', () => { + let enterpriseSearchUrl; + + afterEach(() => { + enterpriseSearchUrl = undefined; + }); + + const render = () => { + return mount( + + + + ); + }; + + describe('when enterpriseSearchUrl is set', () => { + let wrapper; + + beforeEach(() => { + enterpriseSearchUrl = 'http://localhost:3002'; + wrapper = render(); + }); + + describe('the Launch App Search button', () => { + const subject = () => wrapper.find('EuiButton[data-test-subj="launch_button"]'); + + it('should not be disabled', () => { + expect(subject().props().isDisabled).toBeFalsy(); + }); + + it('should use the enterpriseSearchUrl as the base path for its href', () => { + expect(subject().props().href).toBe('http://localhost:3002/as'); + }); + }); + }); + + describe('when enterpriseSearchUrl is not set', () => { + let wrapper; + + beforeEach(() => { + enterpriseSearchUrl = undefined; + wrapper = render(); + }); + + describe('the Launch App Search button', () => { + const subject = () => wrapper.find('EuiButton[data-test-subj="launch_button"]'); + + it('should be disabled', () => { + expect(subject().props().isDisabled).toBe(true); + }); + + it('should not have an href', () => { + expect(subject().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 14b2d00668c0dc..eb50f83d46db44 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 @@ -15,6 +15,7 @@ export const EngineOverviewHeader: React.FC<> = () => { const buttonProps = { fill: true, iconType: 'popout', + ['data-test-subj']: 'launch_button', }; if (enterpriseSearchUrl) { buttonProps.href = `${enterpriseSearchUrl}/as`; From 2a17c11c9ced25dd10adc4bd9d3017d5cca2a0a1 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Fri, 24 Apr 2020 14:15:56 -0400 Subject: [PATCH 03/10] Added Unit Test for generate_breadcrumbs --- .../generate_breadcrumbs.test.ts | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts new file mode 100644 index 00000000000000..5947b8d7e4f2ab --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts @@ -0,0 +1,151 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { appSearchBreadcrumbs, enterpriseSearchBreadcrumbs } from '../kibana_breadcrumbs'; + +jest.mock('../react_router_helpers', () => ({ + letBrowserHandleEvent: () => false, +})); + +describe('appSearchBreadcrumbs', () => { + const historyMock = { + createHref: jest.fn(), + push: jest.fn(), + }; + + const breadCrumbs = [ + { + text: 'Page 1', + path: '/page1', + }, + { + text: 'Page 2', + path: '/page2', + }, + ]; + + afterEach(() => { + jest.clearAllMocks(); + }); + + const subject = () => appSearchBreadcrumbs(historyMock)(breadCrumbs); + + it('Builds a chain of breadcrumbs with Enterprise Search and App Search at the root', () => { + expect(subject()).toEqual([ + { + href: undefined, + onClick: expect.any(Function), + text: 'Enterprise Search', + }, + { + href: undefined, + onClick: expect.any(Function), + text: 'App Search', + }, + { + href: undefined, + onClick: expect.any(Function), + text: 'Page 1', + }, + { + href: undefined, + onClick: expect.any(Function), + text: 'Page 2', + }, + ]); + }); + + describe('links', () => { + const eventMock = { + preventDefault: jest.fn(), + }; + + it('has a link to Enterprise Search Home page first', () => { + subject()[0].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/'); + }); + + it('has a link to App Search second', () => { + subject()[1].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/app_search'); + }); + + it('has a link to our custom page third', () => { + subject()[2].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/page1'); + }); + + it('has a link to our second custom page last', () => { + subject()[3].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/page2'); + }); + }); +}); + +describe('enterpriseSearchBreadcrumbs', () => { + const historyMock = { + createHref: jest.fn(), + push: jest.fn(), + }; + + const breadCrumbs = [ + { + text: 'Page 1', + path: '/page1', + }, + { + text: 'Page 2', + path: '/page2', + }, + ]; + + afterEach(() => { + jest.clearAllMocks(); + }); + + const subject = () => enterpriseSearchBreadcrumbs(historyMock)(breadCrumbs); + + it('Builds a chain of breadcrumbs with Enterprise Search at the root', () => { + expect(subject()).toEqual([ + { + href: undefined, + onClick: expect.any(Function), + text: 'Enterprise Search', + }, + { + href: undefined, + onClick: expect.any(Function), + text: 'Page 1', + }, + { + href: undefined, + onClick: expect.any(Function), + text: 'Page 2', + }, + ]); + }); + + describe('links', () => { + const eventMock = { + preventDefault: jest.fn(), + }; + + it('has a link to Enterprise Search Home page first', () => { + subject()[0].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/'); + }); + + it('has a link to our custom page third', () => { + subject()[1].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/page1'); + }); + + it('has a link to our second custom page last', () => { + subject()[2].onClick(eventMock); + expect(historyMock.push).toHaveBeenCalledWith('/page2'); + }); + }); +}); From 922ddef5b9c406b264b38c6ec3352bf4b09b06d1 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Fri, 24 Apr 2020 15:04:33 -0400 Subject: [PATCH 04/10] Added Unit Test for set_breadcrumb.tsx --- .../set_breadcrumbs.test.tsx | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx new file mode 100644 index 00000000000000..10e8f922df5afe --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx @@ -0,0 +1,82 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { SetAppSearchBreadcrumbs } from '../kibana_breadcrumbs'; +import { mount } from 'enzyme'; + +jest.mock('./generate_breadcrumbs', () => ({ + appSearchBreadcrumbs: jest.fn(), +})); +import { appSearchBreadcrumbs } from './generate_breadcrumbs'; + +jest.mock('react-router-dom', () => ({ + useHistory: () => ({ + createHref: jest.fn(), + push: jest.fn(), + location: { + pathname: '/current-path', + }, + }), +})); + +import { KibanaContext } from '../..'; + +describe('SetAppSearchBreadcrumbs', () => { + const setBreadcrumbs = jest.fn(); + const builtBreadcrumbs = []; + const appSearchBreadCrumbsInnerCall = jest.fn().mockReturnValue(builtBreadcrumbs); + const appSearchBreadCrumbsOuterCall = jest.fn().mockReturnValue(appSearchBreadCrumbsInnerCall); + appSearchBreadcrumbs.mockImplementation(appSearchBreadCrumbsOuterCall); + + afterEach(() => { + jest.clearAllMocks(); + }); + + const render = props => { + return mount( + + + + ); + }; + + describe('when isRoot is false', () => { + const subject = () => render({ text: 'Page 1', isRoot: false }); + + it('calls appSearchBreadcrumbs to build breadcrumbs, then registers them with Kibana', () => { + subject(); + + // calls appSearchBreadcrumbs to build breadcrumbs with the target page and current location + expect(appSearchBreadCrumbsInnerCall).toHaveBeenCalledWith([ + { text: 'Page 1', path: '/current-path' }, + ]); + + // then registers them with Kibana + expect(setBreadcrumbs).toHaveBeenCalledWith(builtBreadcrumbs); + }); + }); + + describe('when isRoot is true', () => { + const subject = () => render({ text: 'Page 1', isRoot: true }); + + it('calls appSearchBreadcrumbs to build breadcrumbs with an empty breadcrumb, then registers them with Kibana', () => { + subject(); + + // uses an empty bredcrumb + expect(appSearchBreadCrumbsInnerCall).toHaveBeenCalledWith([]); + + // then registers them with Kibana + expect(setBreadcrumbs).toHaveBeenCalledWith(builtBreadcrumbs); + }); + }); +}); From 232ba40166cfb6042d4a8d465a57a54435a16ceb Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Fri, 24 Apr 2020 16:22:00 -0400 Subject: [PATCH 05/10] Added a unit test for link_events - Also changed link_events.tsx to link_events.ts since it's just TS, no React - Modified letBrowserHandleEvent so it will still return a false boolean when target is blank --- .../react_router_helpers/link_events.test.ts | 102 ++++++++++++++++++ .../{link_events.tsx => link_events.ts} | 2 +- 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts rename x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/{link_events.tsx => link_events.ts} (95%) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts new file mode 100644 index 00000000000000..49ab5ed920e365 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts @@ -0,0 +1,102 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { letBrowserHandleEvent } from '../react_router_helpers'; + +describe('letBrowserHandleEvent', () => { + const event = { + defaultPrevented: false, + metaKey: false, + altKey: false, + ctrlKey: false, + shiftKey: false, + button: 0, + target: { + getAttribute: () => '_self', + }, + }; + + describe('the browser should handle the link when', () => { + it('default is prevented', () => { + expect(letBrowserHandleEvent({ ...event, defaultPrevented: true })).toBe(true); + }); + + it('is modified with metaKey', () => { + expect(letBrowserHandleEvent({ ...event, metaKey: true })).toBe(true); + }); + + it('is modified with altKey', () => { + expect(letBrowserHandleEvent({ ...event, altKey: true })).toBe(true); + }); + + it('is modified with ctrlKey', () => { + expect(letBrowserHandleEvent({ ...event, ctrlKey: true })).toBe(true); + }); + + it('is modified with shiftKey', () => { + expect(letBrowserHandleEvent({ ...event, shiftKey: true })).toBe(true); + }); + + it('it is not a left click event', () => { + expect(letBrowserHandleEvent({ ...event, button: 2 })).toBe(true); + }); + + it('the target is anything value other than _self', () => { + expect( + letBrowserHandleEvent({ + ...event, + target: targetValue('_blank'), + }) + ).toBe(true); + }); + }); + + describe('the browser should NOT handle the link when', () => { + it('default is not prevented', () => { + expect(letBrowserHandleEvent({ ...event, defaultPrevented: false })).toBe(false); + }); + + it('is not modified', () => { + expect( + letBrowserHandleEvent({ + ...event, + metaKey: false, + altKey: false, + ctrlKey: false, + shiftKey: false, + }) + ).toBe(false); + }); + + it('it is a left click event', () => { + expect(letBrowserHandleEvent({ ...event, button: 0 })).toBe(false); + }); + + it('the target is a value of _self', () => { + expect( + letBrowserHandleEvent({ + ...event, + target: targetValue('_self'), + }) + ).toBe(false); + }); + + it('the target has no value', () => { + expect( + letBrowserHandleEvent({ + ...event, + target: targetValue(null), + }) + ).toBe(false); + }); + }); +}); + +const targetValue = value => { + return { + getAttribute: () => value, + }; +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts similarity index 95% rename from x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.tsx rename to x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts index dba5d576faa7db..bb87ecaf6877b6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts @@ -26,5 +26,5 @@ const isLeftClickEvent: THandleEvent = event => event.button === 0; const isTargetBlank: THandleEvent = event => { const target = event.target.getAttribute('target'); - return target && target !== '_self'; + return !!target && target !== '_self'; }; From 07542577a744e4338fa2132cd78ea70a04115947 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Fri, 24 Apr 2020 16:30:21 -0400 Subject: [PATCH 06/10] Betterize these tests --- .../kibana_breadcrumbs/generate_breadcrumbs.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts index 5947b8d7e4f2ab..aca772f57c4b82 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts @@ -12,7 +12,7 @@ jest.mock('../react_router_helpers', () => ({ describe('appSearchBreadcrumbs', () => { const historyMock = { - createHref: jest.fn(), + createHref: jest.fn().mockImplementation(path => path.pathname), push: jest.fn(), }; @@ -36,22 +36,22 @@ describe('appSearchBreadcrumbs', () => { it('Builds a chain of breadcrumbs with Enterprise Search and App Search at the root', () => { expect(subject()).toEqual([ { - href: undefined, + href: '/', onClick: expect.any(Function), text: 'Enterprise Search', }, { - href: undefined, + href: '/app_search', onClick: expect.any(Function), text: 'App Search', }, { - href: undefined, + href: '/page1', onClick: expect.any(Function), text: 'Page 1', }, { - href: undefined, + href: '/page2', onClick: expect.any(Function), text: 'Page 2', }, From a7b0acd579ac21f46e165ecc49ec1a0643b10d1f Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Mon, 27 Apr 2020 15:10:26 -0400 Subject: [PATCH 07/10] PR Updates --- .../engine_overview_header.test.tsx | 31 +++---------------- .../index.test.ts} | 2 +- .../generate_breadcrumbs.test.ts | 8 ++--- .../set_breadcrumbs.test.tsx | 25 ++++++--------- .../applications/test_utils/helpers.tsx | 24 ++++++++++++++ 5 files changed, 44 insertions(+), 46 deletions(-) rename x-pack/plugins/enterprise_search/public/{application.test.ts => applications/index.test.ts} (93%) create mode 100644 x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx index 2b135cc71c508e..9273b2d6b5f2c4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx @@ -5,38 +5,18 @@ */ import React from 'react'; -import { mount } from 'enzyme'; import { EngineOverviewHeader } from '../engine_overview_header'; -import { KibanaContext } from '../../..'; +import { mountWithKibanaContext } from '../../../test_utils/helpers'; describe('EngineOverviewHeader', () => { - let enterpriseSearchUrl; - - afterEach(() => { - enterpriseSearchUrl = undefined; - }); - - const render = () => { - return mount( - - - - ); - }; - describe('when enterpriseSearchUrl is set', () => { let wrapper; beforeEach(() => { - enterpriseSearchUrl = 'http://localhost:3002'; - wrapper = render(); + wrapper = mountWithKibanaContext(, { + enterpriseSearchUrl: 'http://localhost:3002', + }); }); describe('the Launch App Search button', () => { @@ -56,8 +36,7 @@ describe('EngineOverviewHeader', () => { let wrapper; beforeEach(() => { - enterpriseSearchUrl = undefined; - wrapper = render(); + wrapper = mountWithKibanaContext(, {}); }); describe('the Launch App Search button', () => { diff --git a/x-pack/plugins/enterprise_search/public/application.test.ts b/x-pack/plugins/enterprise_search/public/applications/index.test.ts similarity index 93% rename from x-pack/plugins/enterprise_search/public/application.test.ts rename to x-pack/plugins/enterprise_search/public/applications/index.test.ts index b9133b83d7d3f4..7ece7e153c1541 100644 --- a/x-pack/plugins/enterprise_search/public/application.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/index.test.ts @@ -5,7 +5,7 @@ */ import { coreMock } from 'src/core/public/mocks'; -import { renderApp } from './applications'; +import { renderApp } from '../applications'; describe('renderApp', () => { it('mounts and unmounts UI', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts index aca772f57c4b82..aa2b584d984255 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts @@ -73,12 +73,12 @@ describe('appSearchBreadcrumbs', () => { expect(historyMock.push).toHaveBeenCalledWith('/app_search'); }); - it('has a link to our custom page third', () => { + it('has a link to page 1 third', () => { subject()[2].onClick(eventMock); expect(historyMock.push).toHaveBeenCalledWith('/page1'); }); - it('has a link to our second custom page last', () => { + it('has a link to page 2 last', () => { subject()[3].onClick(eventMock); expect(historyMock.push).toHaveBeenCalledWith('/page2'); }); @@ -138,12 +138,12 @@ describe('enterpriseSearchBreadcrumbs', () => { expect(historyMock.push).toHaveBeenCalledWith('/'); }); - it('has a link to our custom page third', () => { + it('has a link to page 1 second', () => { subject()[1].onClick(eventMock); expect(historyMock.push).toHaveBeenCalledWith('/page1'); }); - it('has a link to our second custom page last', () => { + it('has a link to page 2 last', () => { subject()[2].onClick(eventMock); expect(historyMock.push).toHaveBeenCalledWith('/page2'); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx index 10e8f922df5afe..83588d7f18212a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx @@ -5,8 +5,9 @@ */ import React from 'react'; + import { SetAppSearchBreadcrumbs } from '../kibana_breadcrumbs'; -import { mount } from 'enzyme'; +import { mountWithKibanaContext } from '../../test_utils/helpers'; jest.mock('./generate_breadcrumbs', () => ({ appSearchBreadcrumbs: jest.fn(), @@ -36,22 +37,16 @@ describe('SetAppSearchBreadcrumbs', () => { jest.clearAllMocks(); }); - const render = props => { - return mount( - - - - ); + const mountSetAppSearchBreadcrumbs = props => { + return mountWithKibanaContext(, { + http: {}, + enterpriseSearchUrl: 'http://localhost:3002', + setBreadcrumbs, + }); }; describe('when isRoot is false', () => { - const subject = () => render({ text: 'Page 1', isRoot: false }); + const subject = () => mountSetAppSearchBreadcrumbs({ text: 'Page 1', isRoot: false }); it('calls appSearchBreadcrumbs to build breadcrumbs, then registers them with Kibana', () => { subject(); @@ -67,7 +62,7 @@ describe('SetAppSearchBreadcrumbs', () => { }); describe('when isRoot is true', () => { - const subject = () => render({ text: 'Page 1', isRoot: true }); + const subject = () => mountSetAppSearchBreadcrumbs({ text: 'Page 1', isRoot: true }); it('calls appSearchBreadcrumbs to build breadcrumbs with an empty breadcrumb, then registers them with Kibana', () => { subject(); diff --git a/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx b/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx new file mode 100644 index 00000000000000..45ec76fa985722 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { mount } from 'enzyme'; + +import { KibanaContext } from '..'; + +export const mountWithKibanaContext = (node, contextProps) => { + return mount( + + {node} + + ); +}; From 5f28efe392a5b59aa1fd64cd537183d5687f905c Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Mon, 27 Apr 2020 15:31:30 -0400 Subject: [PATCH 08/10] Dope. --- .../engine_overview_header/engine_overview_header.test.tsx | 4 ++-- .../engine_overview_header/engine_overview_header.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx index 9273b2d6b5f2c4..a883ca8248aca5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx @@ -20,7 +20,7 @@ describe('EngineOverviewHeader', () => { }); describe('the Launch App Search button', () => { - const subject = () => wrapper.find('EuiButton[data-test-subj="launch_button"]'); + const subject = () => wrapper.find('EuiButton[data-test-subj="launchButton"]'); it('should not be disabled', () => { expect(subject().props().isDisabled).toBeFalsy(); @@ -40,7 +40,7 @@ describe('EngineOverviewHeader', () => { }); describe('the Launch App Search button', () => { - const subject = () => wrapper.find('EuiButton[data-test-subj="launch_button"]'); + const subject = () => wrapper.find('EuiButton[data-test-subj="launchButton"]'); it('should be disabled', () => { expect(subject().props().isDisabled).toBe(true); 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 eb50f83d46db44..69bfb9ad124eb5 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 @@ -15,7 +15,7 @@ export const EngineOverviewHeader: React.FC<> = () => { const buttonProps = { fill: true, iconType: 'popout', - ['data-test-subj']: 'launch_button', + ['data-test-subj']: 'launchButton', }; if (enterpriseSearchUrl) { buttonProps.href = `${enterpriseSearchUrl}/as`; From 8a678a0e2fb1218fee431d6989bf65a03bbd494c Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Mon, 27 Apr 2020 15:35:14 -0400 Subject: [PATCH 09/10] default enterpriseSearchUrl --- .../engine_overview_header/engine_overview_header.test.tsx | 4 +++- .../public/applications/test_utils/helpers.tsx | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx index a883ca8248aca5..19ea683eb878c8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx @@ -36,7 +36,9 @@ describe('EngineOverviewHeader', () => { let wrapper; beforeEach(() => { - wrapper = mountWithKibanaContext(, {}); + wrapper = mountWithKibanaContext(, { + enterpriseSearchUrl: undefined, + }); }); describe('the Launch App Search button', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx b/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx index 45ec76fa985722..9343e927e82ac1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/test_utils/helpers.tsx @@ -15,6 +15,7 @@ export const mountWithKibanaContext = (node, contextProps) => { value={{ http: {}, setBreadcrumbs: jest.fn(), + enterpriseSearchUrl: 'http://localhost:3002', ...contextProps, }} > From 47d6cda227a766e695f30aea7d8d3946a993f293 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Tue, 28 Apr 2020 07:49:08 -0400 Subject: [PATCH 10/10] Update x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx Co-Authored-By: Constance --- .../shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx index 83588d7f18212a..7d632208c007a4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx @@ -24,7 +24,6 @@ jest.mock('react-router-dom', () => ({ }), })); -import { KibanaContext } from '../..'; describe('SetAppSearchBreadcrumbs', () => { const setBreadcrumbs = jest.fn();