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

app.test.tsx changes #21

Open
wants to merge 3 commits into
base: feat/react-embeddable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { of } from 'rxjs';
import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { Plugin } from '.';
import { createTopNav } from './top_nav_menu';

export type Setup = jest.Mocked<ReturnType<Plugin['setup']>>;
export type Start = jest.Mocked<ReturnType<Plugin['start']>>;

// mock mountPointPortal
jest.mock('@kbn/react-kibana-mount', () => ({
MountPointPortal: jest.fn(({ children }) => children),
}));

const createSetupContract = (): jest.Mocked<Setup> => {
const setupContract = {
registerMenuItem: jest.fn(),
Expand All @@ -21,12 +28,21 @@ const createSetupContract = (): jest.Mocked<Setup> => {
return setupContract;
};

export const unifiedSearchMock = {
ui: {
SearchBar: () => <div className="searchBar" />,
AggregateQuerySearchBar: () => <div className="searchBar" />,
},
} as unknown as UnifiedSearchPublicPluginStart;

const createStartContract = (): jest.Mocked<Start> => {
const startContract = {
ui: {
TopNavMenu: jest.fn(),
createTopNavWithCustomContext: jest.fn().mockImplementation(() => jest.fn()),
AggregateQueryTopNavMenu: jest.fn(),
TopNavMenu: jest.fn().mockImplementation(createTopNav(unifiedSearchMock, [])),
AggregateQueryTopNavMenu: jest.fn().mockImplementation(createTopNav(unifiedSearchMock, [])),
createTopNavWithCustomContext: jest
.fn()
.mockImplementation(createTopNav(unifiedSearchMock, [])),
},
addSolutionNavigation: jest.fn(),
isSolutionNavEnabled$: of(false),
Expand Down
19 changes: 6 additions & 13 deletions src/plugins/navigation/public/top_nav_menu/top_nav_menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@ import { MountPoint } from '@kbn/core/public';
import { TopNavMenu } from './top_nav_menu';
import { TopNavMenuData } from './top_nav_menu_data';
import { findTestSubject, mountWithIntl } from '@kbn/test-jest-helpers';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { EuiToolTipProps } from '@elastic/eui';
import type { TopNavMenuBadgeProps } from './top_nav_menu_badges';

const unifiedSearch = {
ui: {
SearchBar: () => <div className="searchBar" />,
AggregateQuerySearchBar: () => <div className="searchBar" />,
},
} as unknown as UnifiedSearchPublicPluginStart;
import { unifiedSearchMock } from '../mocks';

describe('TopNavMenu', () => {
const WRAPPER_SELECTOR = '.kbnTopNavMenu__wrapper';
Expand Down Expand Up @@ -97,7 +90,7 @@ describe('TopNavMenu', () => {

it('Should render search bar', () => {
const component = mountWithIntl(
<TopNavMenu appName={'test'} showSearchBar={true} unifiedSearch={unifiedSearch} />
<TopNavMenu appName={'test'} showSearchBar={true} unifiedSearch={unifiedSearchMock} />
);
expect(component.find(WRAPPER_SELECTOR).length).toBe(1);
expect(component.find(TOP_NAV_ITEM_SELECTOR).length).toBe(0);
Expand All @@ -110,7 +103,7 @@ describe('TopNavMenu', () => {
appName={'test'}
config={menuItems}
showSearchBar={true}
unifiedSearch={unifiedSearch}
unifiedSearch={unifiedSearchMock}
/>
);
expect(component.find(WRAPPER_SELECTOR).length).toBe(1);
Expand All @@ -124,7 +117,7 @@ describe('TopNavMenu', () => {
appName={'test'}
config={menuItems}
showSearchBar={true}
unifiedSearch={unifiedSearch}
unifiedSearch={unifiedSearchMock}
className={'myCoolClass'}
/>
);
Expand Down Expand Up @@ -172,7 +165,7 @@ describe('TopNavMenu', () => {
appName={'test'}
config={menuItems}
showSearchBar={true}
unifiedSearch={unifiedSearch}
unifiedSearch={unifiedSearchMock}
setMenuMountPoint={setMountPoint}
/>
);
Expand All @@ -195,7 +188,7 @@ describe('TopNavMenu', () => {
appName={'test'}
badges={badges}
showSearchBar={true}
unifiedSearch={unifiedSearch}
unifiedSearch={unifiedSearchMock}
setMenuMountPoint={setMountPoint}
/>
);
Expand Down
Loading