forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* application.test.ts * Added Unit Test for EngineOverviewHeader * Added Unit Test for generate_breadcrumbs * Added Unit Test for set_breadcrumb.tsx * 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 * Betterize these tests Co-Authored-By: Constance <constancecchen@users.noreply.github.com> Co-authored-by: Constance <constancecchen@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
431 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 { EngineOverviewHeader } from '../engine_overview_header'; | ||
import { mountWithKibanaContext } from '../../../test_utils/helpers'; | ||
|
||
describe('EngineOverviewHeader', () => { | ||
describe('when enterpriseSearchUrl is set', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mountWithKibanaContext(<EngineOverviewHeader />, { | ||
enterpriseSearchUrl: 'http://localhost:3002', | ||
}); | ||
}); | ||
|
||
describe('the Launch App Search button', () => { | ||
const subject = () => wrapper.find('EuiButton[data-test-subj="launchButton"]'); | ||
|
||
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(() => { | ||
wrapper = mountWithKibanaContext(<EngineOverviewHeader />, { | ||
enterpriseSearchUrl: undefined, | ||
}); | ||
}); | ||
|
||
describe('the Launch App Search button', () => { | ||
const subject = () => wrapper.find('EuiButton[data-test-subj="launchButton"]'); | ||
|
||
it('should be disabled', () => { | ||
expect(subject().props().isDisabled).toBe(true); | ||
}); | ||
|
||
it('should not have an href', () => { | ||
expect(subject().props().href).toBeUndefined(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/enterprise_search/public/applications/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(''); | ||
}); | ||
}); |
151 changes: 151 additions & 0 deletions
151
...erprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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().mockImplementation(path => path.pathname), | ||
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: '/', | ||
onClick: expect.any(Function), | ||
text: 'Enterprise Search', | ||
}, | ||
{ | ||
href: '/app_search', | ||
onClick: expect.any(Function), | ||
text: 'App Search', | ||
}, | ||
{ | ||
href: '/page1', | ||
onClick: expect.any(Function), | ||
text: 'Page 1', | ||
}, | ||
{ | ||
href: '/page2', | ||
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 page 1 third', () => { | ||
subject()[2].onClick(eventMock); | ||
expect(historyMock.push).toHaveBeenCalledWith('/page1'); | ||
}); | ||
|
||
it('has a link to page 2 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 page 1 second', () => { | ||
subject()[1].onClick(eventMock); | ||
expect(historyMock.push).toHaveBeenCalledWith('/page1'); | ||
}); | ||
|
||
it('has a link to page 2 last', () => { | ||
subject()[2].onClick(eventMock); | ||
expect(historyMock.push).toHaveBeenCalledWith('/page2'); | ||
}); | ||
}); | ||
}); |
75 changes: 75 additions & 0 deletions
75
.../enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { SetAppSearchBreadcrumbs } from '../kibana_breadcrumbs'; | ||
import { mountWithKibanaContext } from '../../test_utils/helpers'; | ||
|
||
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', | ||
}, | ||
}), | ||
})); | ||
|
||
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 mountSetAppSearchBreadcrumbs = props => { | ||
return mountWithKibanaContext(<SetAppSearchBreadcrumbs {...props} />, { | ||
http: {}, | ||
enterpriseSearchUrl: 'http://localhost:3002', | ||
setBreadcrumbs, | ||
}); | ||
}; | ||
|
||
describe('when isRoot is false', () => { | ||
const subject = () => mountSetAppSearchBreadcrumbs({ 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 = () => mountSetAppSearchBreadcrumbs({ 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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.