Skip to content

Commit

Permalink
Add render tests
Browse files Browse the repository at this point in the history
  • Loading branch information
efegurkan committed Apr 20, 2022
1 parent 3610fce commit 7c57802
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { mount } from 'enzyme';

import { EuiPopover, EuiButtonEmpty } from '@elastic/eui';

import { EnterpriseSearchOverviewHeaderActions } from './kibana_header_actions';

describe('Enterprise Search overview HeaderActions', () => {
it('renders', () => {
const wrapper = mount(<EnterpriseSearchOverviewHeaderActions />);
const popover = wrapper.find(EuiPopover);

expect(popover.find(EuiButtonEmpty).text()).toContain('Deployment details');
expect(popover.prop('isOpen')).toBeFalsy();
});

it('opens popover when clicked', () => {
const wrapper = mount(<EnterpriseSearchOverviewHeaderActions />);

expect(wrapper.find(EuiPopover).prop('isOpen')).toBeFalsy();
wrapper.find(EuiPopover).find(EuiButtonEmpty).simulate('click');
wrapper.update();

expect(wrapper.find(EuiPopover).prop('isOpen')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiLinkTo } from '../react_router_helpers';

import { AddContentEmptyPrompt } from '.';

describe('AddContentEmptyPrompt', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
wrapper = shallow(<AddContentEmptyPrompt />);
});

it('renders', () => {
expect(wrapper.find('h2').text()).toEqual('Add content to Enterprise Search');
expect(wrapper.find(EuiLinkTo).prop('to')).toEqual(
'/app/enterprise_search/content/search_indices'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const AddContentEmptyPrompt: React.FC = () => {
</EuiLinkTo>
</EuiFlexItem>
<EuiFlexItem>
{/* TODO need link for Learn More link*/}
<EuiLink href="#" target="_blank">
{i18n.translate('xpack.enterpriseSearch.overview.emptyState.footerLinkTitle', {
defaultMessage: 'Learn more',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

jest.mock('../doc_links', () => ({
docLinks: {
elasticsearchGettingStarted: 'elasticsearchGettingStarted-link',
elasticsearchCreateIndex: 'elasticsearchCreateIndex-link',
clientsGuide: 'elasticsearchClientsGuide-link',
},
}));
import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiLink } from '@elastic/eui';

import { ElasticsearchResources } from '.';

describe('ElasticsearchResources', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
wrapper = shallow(<ElasticsearchResources />);
});

it('renders', () => {
expect(wrapper.find('h4').text()).toEqual('Resources');

expect(wrapper.find(EuiLink).at(0).prop('href')).toEqual('elasticsearchGettingStarted-link');
expect(wrapper.find(EuiLink).at(0).text()).toEqual('Getting started with Elasticsearch');

expect(wrapper.find(EuiLink).at(1).prop('href')).toEqual('elasticsearchCreateIndex-link');
expect(wrapper.find(EuiLink).at(1).text()).toEqual('Create a new index');

expect(wrapper.find(EuiLink).at(2).prop('href')).toEqual('elasticsearchClientsGuide-link');
expect(wrapper.find(EuiLink).at(2).text()).toEqual('Setup a language client');

expect(wrapper.find(EuiLink).at(3).prop('href')).toEqual(
'https://github.com/elastic/search-ui/tree/master/packages/search-ui-elasticsearch-connector'
);
expect(wrapper.find(EuiLink).at(3).text()).toEqual('Search UI for Elasticsearch');
});
});
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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

jest.mock('../doc_links', () => ({
docLinks: {
elasticsearchGettingStarted: 'elasticsearchGettingStarted-link',
elasticsearchCreateIndex: 'elasticsearchCreateIndex-link',
clientsGuide: 'elasticsearchClientsGuide-link',
},
}));
import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiSteps } from '@elastic/eui';

import { EuiLinkTo } from '../react_router_helpers';

import { IconRow } from './icon_row';

import { GettingStartedSteps } from '.';

describe('GettingStartedSteps', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
wrapper = shallow(<GettingStartedSteps />);
});

it('renders', () => {
const steps = wrapper
.find(EuiSteps)
.prop('steps')
.map(({ title, children, status, ...rest }) => ({
title,
status,
children: shallow(<div>{children}</div>),
...rest,
}));

expect(steps[0].title).toEqual('Add your documents and data to Enterprise Search');
expect(steps[0].status).toEqual('current');
expect(steps[0].children.find(IconRow).length).toEqual(1);

expect(steps[1].title).toEqual('Build a search experience');
expect(steps[1].status).toEqual('incomplete');
expect(steps[1].children.find(EuiLinkTo).prop('to')).toEqual('/elasticsearch_guide');

expect(steps[2].title).toEqual('Tune your search relevance');
expect(steps[2].status).toEqual('incomplete');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const GettingStartedSteps: React.FC = () => {
isOpen={isPopoverOpen}
closePopover={() => setIsPopoverOpen(false)}
>
{/* TODO add onclick for these links*/}
<EuiContextMenuPanel
items={[
<EuiContextMenuItem key="" onClick={() => {}}>
Expand Down

0 comments on commit 7c57802

Please sign in to comment.