Skip to content

Commit

Permalink
feat: add unit test for mountWrapper (opensearch-project#223)
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe authored Oct 12, 2023
1 parent 903e594 commit 0906bf4
Showing 1 changed file with 58 additions and 5 deletions.
63 changes: 58 additions & 5 deletions src/plugins/saved_objects_management/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@
* under the License.
*/

const mountManagementSectionMock = jest.fn();
jest.doMock('./management_section', () => ({
mountManagementSection: mountManagementSectionMock,
}));
import { waitFor } from '@testing-library/dom';
import { coreMock } from '../../../core/public/mocks';
import { homePluginMock } from '../../home/public/mocks';
import { managementPluginMock } from '../../management/public/mocks';
import { dataPluginMock } from '../../data/public/mocks';
import { uiActionsPluginMock } from '../../ui_actions/public/mocks';
import { SavedObjectsManagementPlugin } from './plugin';
import {
MANAGE_LIBRARY_TITLE_WORDINGS,
SAVED_QUERIES_WORDINGS,
SAVED_SEARCHES_WORDINGS,
} from './constants';
import { DEFAULT_APP_CATEGORIES } from '../../../core/public';

describe('SavedObjectsManagementPlugin', () => {
let plugin: SavedObjectsManagementPlugin;
Expand All @@ -50,19 +61,61 @@ describe('SavedObjectsManagementPlugin', () => {
const homeSetup = homePluginMock.createSetupContract();
const managementSetup = managementPluginMock.createSetupContract();
const uiActionsSetup = uiActionsPluginMock.createSetupContract();
const registerMock = jest.fn((params) => params.mount({} as any, {} as any));

await plugin.setup(coreSetup, {
home: homeSetup,
management: managementSetup,
uiActions: uiActionsSetup,
});
await plugin.setup(
{
...coreSetup,
application: {
...coreSetup.application,
register: registerMock,
},
},
{
home: homeSetup,
management: managementSetup,
uiActions: uiActionsSetup,
}
);

expect(homeSetup.featureCatalogue.register).toHaveBeenCalledTimes(1);
expect(homeSetup.featureCatalogue.register).toHaveBeenCalledWith(
expect.objectContaining({
id: 'saved_objects',
})
);
expect(registerMock).toBeCalledWith(
expect.objectContaining({
id: 'objects',
title: MANAGE_LIBRARY_TITLE_WORDINGS,
order: 10000,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
})
);
expect(registerMock).toBeCalledWith(
expect.objectContaining({
id: 'objects_searches',
title: SAVED_SEARCHES_WORDINGS,
order: 8000,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
})
);
expect(registerMock).toBeCalledWith(
expect.objectContaining({
id: 'objects_query',
title: SAVED_QUERIES_WORDINGS,
order: 8001,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
})
);
waitFor(
() => {
expect(mountManagementSectionMock).toBeCalledTimes(3);
},
{
container: document.body,
}
);
});
});
});

0 comments on commit 0906bf4

Please sign in to comment.