Skip to content

Commit

Permalink
app.test.tsx changes (elastic#21)
Browse files Browse the repository at this point in the history
* wip

* wip

* finish line

* revert cloneDeep
  • Loading branch information
mbondyra authored Sep 25, 2024
1 parent f6e6df0 commit e9a6508
Show file tree
Hide file tree
Showing 7 changed files with 564 additions and 794 deletions.
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

0 comments on commit e9a6508

Please sign in to comment.