Skip to content

Commit

Permalink
add types to management mock
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Feb 6, 2020
1 parent 6fac7e4 commit 2a01095
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/plugins/management/public/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
* under the License.
*/

const createSetupContract = () => ({
import { ManagementSetup, ManagementStart } from '../types';

const createSetupContract = (): DeeplyMockedKeys<ManagementSetup> => ({
sections: {
register: jest.fn(),
getSection: jest.fn(),
getSectionsEnabled: jest.fn(),
getAllSections: jest.fn(),
},
});

const createStartContract = () => ({
const createStartContract = (): DeeplyMockedKeys<ManagementStart> => ({
legacy: {},
sections: {
getSection: jest.fn(),
Expand Down
19 changes: 16 additions & 3 deletions x-pack/plugins/spaces/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { coreMock } from 'src/core/public/mocks';
import { SpacesPlugin } from './plugin';
import { homePluginMock } from '../../../../src/plugins/home/public/mocks';
import { ManagementSection } from '../../../../src/plugins/management/public';
import { managementPluginMock } from '../../../../src/plugins/management/public/mocks';
import { advancedSettingsMock } from '../../../../src/plugins/advanced_settings/public/mocks';

Expand All @@ -31,20 +32,32 @@ describe('Spaces plugin', () => {
it('should register the management and feature catalogue sections when the management and home plugins are both available', () => {
const coreSetup = coreMock.createSetup();

const registerApp = jest.fn();
const kibanaSection = new ManagementSection(
{
id: 'kibana',
title: 'Mock Kibana Section',
order: 1,
},
jest.fn(),
jest.fn(),
jest.fn(),
coreSetup.getStartServices
);

const registerAppSpy = jest.spyOn(kibanaSection, 'registerApp');

const home = homePluginMock.createSetupContract();

const management = managementPluginMock.createSetupContract();
management.sections.getSection.mockReturnValue({ registerApp });
management.sections.getSection.mockReturnValue(kibanaSection);

const plugin = new SpacesPlugin();
plugin.setup(coreSetup, {
management,
home,
});

expect(registerApp).toHaveBeenCalledWith(expect.objectContaining({ id: 'spaces' }));
expect(registerAppSpy).toHaveBeenCalledWith(expect.objectContaining({ id: 'spaces' }));

expect(home.featureCatalogue.register).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down

0 comments on commit 2a01095

Please sign in to comment.