From 65c38c51af1841115af7fba3726274e5f1b5e340 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 23 Aug 2024 14:05:23 +0800 Subject: [PATCH] fix: unit test Signed-off-by: SuZhou-Joe --- src/plugins/workspace/public/plugin.test.ts | 18 ++----- .../public/services/use_case_service.test.ts | 53 ++++++++++++++++++- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/plugins/workspace/public/plugin.test.ts b/src/plugins/workspace/public/plugin.test.ts index 1bb0b93c4a12..94b98996e2a4 100644 --- a/src/plugins/workspace/public/plugin.test.ts +++ b/src/plugins/workspace/public/plugin.test.ts @@ -170,14 +170,14 @@ describe('Workspace plugin', () => { expect.arrayContaining([ { id: 'workspace_list', - order: 150, - title: 'Workspace settings', + order: 350, + title: 'Workspaces', }, ]) ); }); - it('#setup should register workspace detail with a visible application and register to all nav group', async () => { + it('#setup should register workspace detail', async () => { const setupMock = coreMock.createSetup(); setupMock.chrome.navGroup.getNavGroupEnabled.mockReturnValue(true); const workspacePlugin = new WorkspacePlugin(); @@ -186,20 +186,8 @@ describe('Workspace plugin', () => { expect(setupMock.application.register).toHaveBeenCalledWith( expect.objectContaining({ id: 'workspace_detail', - navLinkStatus: AppNavLinkStatus.hidden, }) ); - - expect(setupMock.chrome.navGroup.addNavLinksToGroup).toHaveBeenCalledWith( - DEFAULT_NAV_GROUPS.all, - expect.arrayContaining([ - { - id: 'workspace_detail', - title: 'Overview', - order: 100, - }, - ]) - ); }); it('#setup should register workspace initial with a visible application', async () => { diff --git a/src/plugins/workspace/public/services/use_case_service.test.ts b/src/plugins/workspace/public/services/use_case_service.test.ts index 00938fd7d60d..17f977474f07 100644 --- a/src/plugins/workspace/public/services/use_case_service.test.ts +++ b/src/plugins/workspace/public/services/use_case_service.test.ts @@ -5,14 +5,17 @@ import { BehaviorSubject } from 'rxjs'; import { first } from 'rxjs/operators'; -import { chromeServiceMock } from '../../../../core/public/mocks'; +import { chromeServiceMock, coreMock } from '../../../../core/public/mocks'; import { ALL_USE_CASE_ID, + DEFAULT_APP_CATEGORIES, DEFAULT_NAV_GROUPS, NavGroupItemInMap, NavGroupType, } from '../../../../core/public'; import { UseCaseService } from './use_case_service'; +import { waitFor } from '@testing-library/dom'; +import { WORKSPACE_DETAIL_APP_ID } from '../../common/constants'; const mockNavGroupsMap = { system: { @@ -61,6 +64,54 @@ const setupUseCaseStart = (options?: { navGroupEnabled?: boolean }) => { }; describe('UseCaseService', () => { + describe('#setup', () => { + it('should add manage workspace category to current use case', async () => { + const useCaseService = new UseCaseService(); + const coreSetup = coreMock.createSetup(); + const navGroupMap$ = new BehaviorSubject>({}); + const coreStartMock = coreMock.createStart(); + coreSetup.getStartServices.mockResolvedValue([coreStartMock, {}, {}]); + coreStartMock.chrome.navGroup.getNavGroupsMap$.mockReturnValue(navGroupMap$); + useCaseService.setup(coreSetup); + const navGroupInfo = { + ...DEFAULT_NAV_GROUPS.all, + navLinks: [], + }; + navGroupMap$.next({ + [ALL_USE_CASE_ID]: navGroupInfo, + }); + coreSetup.workspaces.currentWorkspace$.next({ + id: ALL_USE_CASE_ID, + name: ALL_USE_CASE_ID, + features: [`use-case-${ALL_USE_CASE_ID}`], + }); + await waitFor(() => { + expect(coreSetup.chrome.navGroup.addNavLinksToGroup).toBeCalledWith(navGroupInfo, [ + { + id: 'dataSources_core', + category: DEFAULT_APP_CATEGORIES.manageWorkspace, + order: 100, + }, + { + id: 'indexPatterns', + category: DEFAULT_APP_CATEGORIES.manageWorkspace, + order: 200, + }, + { + id: 'objects', + category: DEFAULT_APP_CATEGORIES.manageWorkspace, + order: 300, + }, + { + id: WORKSPACE_DETAIL_APP_ID, + category: DEFAULT_APP_CATEGORIES.manageWorkspace, + order: 400, + title: 'Workspace settings', + }, + ]); + }); + }); + }); describe('#start', () => { it('should return built in use cases when nav group disabled', async () => { const { useCaseStart } = setupUseCaseStart({