Skip to content

Commit

Permalink
Add unit tets for default and custom side nav components
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed May 2, 2023
1 parent 6643b56 commit 322c0dd
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';
import React from 'react';
import * as Rx from 'rxjs';
import { toArray } from 'rxjs/operators';
Expand All @@ -19,6 +19,7 @@ import { notificationServiceMock } from '@kbn/core-notifications-browser-mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-browser-mocks';
import { customBrandingServiceMock } from '@kbn/core-custom-branding-browser-mocks';
import { getAppInfo } from '@kbn/core-application-browser-internal';
import { findTestSubject } from '@kbn/test-jest-helpers';
import { ChromeService } from './chrome_service';

class FakeApp implements App {
Expand Down Expand Up @@ -176,6 +177,41 @@ describe('start', () => {
// Don't capture the snapshot because it's 600+ lines long.
expect(shallow(React.createElement(() => chrome.getHeaderComponent()))).toBeDefined();
});

it('renders the default project side navigation', async () => {
const { chrome } = await start();

chrome.setChromeStyle('project');

const component = mount(chrome.getHeaderComponent());

const projectHeader = findTestSubject(component, 'kibanaProjectHeader');
expect(projectHeader.length).toBe(1);

const defaultProjectSideNav = findTestSubject(component, 'defaultProjectSideNav');
expect(defaultProjectSideNav.length).toBe(1);
});

it('renders the custom project side navigation', async () => {
const { chrome } = await start();

const MyNav = function MyNav() {
return <div data-test-subj="customProjectSideNav">HELLO</div>;
};
chrome.setChromeStyle('project');
chrome.project.setSideNavComponent(MyNav);

const component = mount(chrome.getHeaderComponent());

const projectHeader = findTestSubject(component, 'kibanaProjectHeader');
expect(projectHeader.length).toBe(1);

const defaultProjectSideNav = findTestSubject(component, 'defaultProjectSideNav');
expect(defaultProjectSideNav.length).toBe(0); // Default side nav not mounted

const customProjectSideNav = findTestSubject(component, 'customProjectSideNav');
expect(customProjectSideNav.text()).toBe('HELLO');
});
});

describe('visibility', () => {
Expand Down

0 comments on commit 322c0dd

Please sign in to comment.