Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ui tests #4

Merged
merged 10 commits into from
Apr 28, 2020
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', () => {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
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();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const EngineOverviewHeader: React.FC<> = () => {
const buttonProps = {
fill: true,
iconType: 'popout',
['data-test-subj']: 'launchButton',
};
if (enterpriseSearchUrl) {
buttonProps.href = `${enterpriseSearchUrl}/as`;
Expand Down
20 changes: 20 additions & 0 deletions x-pack/plugins/enterprise_search/public/applications/index.test.ts
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('');
});
});
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', () => {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
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');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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', () => {
JasonStoltz marked this conversation as resolved.
Show resolved Hide resolved
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);
});
});
});
Loading