From 898e80b652f6423f50c14de3ae712c4bbada1c52 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 8 Mar 2024 10:18:12 +0800 Subject: [PATCH] feat: update unit test Signed-off-by: SuZhou-Joe --- src/plugins/workspace/public/plugin.test.ts | 25 +++++++++++++++++++++ src/plugins/workspace/public/plugin.ts | 7 ++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/plugins/workspace/public/plugin.test.ts diff --git a/src/plugins/workspace/public/plugin.test.ts b/src/plugins/workspace/public/plugin.test.ts new file mode 100644 index 000000000000..1027e49b941c --- /dev/null +++ b/src/plugins/workspace/public/plugin.test.ts @@ -0,0 +1,25 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { workspaceClientMock, WorkspaceClientMock } from './workspace_client.mock'; +import { chromeServiceMock, coreMock } from '../../../core/public/mocks'; +import { WorkspacePlugin } from './plugin'; + +describe('Workspace plugin', () => { + const getSetupMock = () => ({ + ...coreMock.createSetup(), + chrome: chromeServiceMock.createSetupContract(), + }); + beforeEach(() => { + WorkspaceClientMock.mockClear(); + Object.values(workspaceClientMock).forEach((item) => item.mockClear()); + }); + it('#setup', async () => { + const setupMock = getSetupMock(); + const workspacePlugin = new WorkspacePlugin(); + await workspacePlugin.setup(setupMock); + expect(WorkspaceClientMock).toBeCalledTimes(1); + }); +}); diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 18e84e3a6f35..efd8f6de1683 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -3,10 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { Plugin } from '../../../core/public'; +import { Plugin, CoreSetup } from '../../../core/public'; +import { WorkspaceClient } from './workspace_client'; export class WorkspacePlugin implements Plugin<{}, {}, {}> { - public async setup() { + public async setup(core: CoreSetup) { + const workspaceClient = new WorkspaceClient(core.http, core.workspaces); + await workspaceClient.init(); return {}; }