Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 23, 2024
1 parent 1baa672 commit 65c38c5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
18 changes: 3 additions & 15 deletions src/plugins/workspace/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand Down
53 changes: 52 additions & 1 deletion src/plugins/workspace/public/services/use_case_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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<Record<string, NavGroupItemInMap>>({});
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({
Expand Down

0 comments on commit 65c38c5

Please sign in to comment.