Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Oct 18, 2023
1 parent cbcb5d7 commit dcb3a60
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/plugins/workspace/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { applicationServiceMock, chromeServiceMock, coreMock } from '../../../co
import { WorkspacePlugin } from './plugin';
import { WORKSPACE_FATAL_ERROR_APP_ID, WORKSPACE_OVERVIEW_APP_ID } from '../common/constants';
import { Observable, Subscriber } from 'rxjs';
import { savedObjectsManagementPluginMock } from 'src/plugins/saved_objects_management/public/mocks';

describe('Workspace plugin', () => {
beforeEach(() => {
Expand All @@ -19,11 +20,15 @@ describe('Workspace plugin', () => {
});
it('#setup', async () => {
const setupMock = coreMock.createSetup();
const savedObjectManagementSetupMock = savedObjectsManagementPluginMock.createSetupContract();
const workspacePlugin = new WorkspacePlugin();
await workspacePlugin.setup(setupMock);
await workspacePlugin.setup(setupMock, {
savedObjectsManagement: savedObjectManagementSetupMock,
});
expect(setupMock.application.register).toBeCalledTimes(1);
expect(WorkspaceClientMock).toBeCalledTimes(1);
expect(workspaceClientMock.enterWorkspace).toBeCalledTimes(0);
expect(savedObjectManagementSetupMock.columns.register).toBeCalledTimes(1);
});

it('#setup when workspace id is in url and enterWorkspace return error', async () => {
Expand Down Expand Up @@ -55,7 +60,9 @@ describe('Workspace plugin', () => {
});

const workspacePlugin = new WorkspacePlugin();
await workspacePlugin.setup(setupMock);
await workspacePlugin.setup(setupMock, {
savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(),
});
expect(setupMock.application.register).toBeCalledTimes(1);
expect(WorkspaceClientMock).toBeCalledTimes(1);
expect(workspaceClientMock.enterWorkspace).toBeCalledWith('workspaceId');
Expand Down Expand Up @@ -109,7 +116,9 @@ describe('Workspace plugin', () => {
});

const workspacePlugin = new WorkspacePlugin();
await workspacePlugin.setup(setupMock);
await workspacePlugin.setup(setupMock, {
savedObjectsManagement: savedObjectsManagementPluginMock.createSetupContract(),
});
currentAppIdSubscriber?.next(WORKSPACE_FATAL_ERROR_APP_ID);
expect(applicationStartMock.navigateToApp).toBeCalledWith(WORKSPACE_OVERVIEW_APP_ID);
windowSpy.mockRestore();
Expand Down

0 comments on commit dcb3a60

Please sign in to comment.