-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hailong Cui <[email protected]>
- Loading branch information
1 parent
9a5d060
commit b85d879
Showing
3 changed files
with
240 additions
and
4 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/plugins/management_overview/public/__snapshots__/application.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
src/plugins/management_overview/public/application.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { render } from '@testing-library/react'; | ||
import { ManagementOverviewWrapper } from './application'; | ||
import React from 'react'; | ||
import { ApplicationStart, PublicAppInfo } from 'opensearch-dashboards/public'; | ||
import { BehaviorSubject, Subject } from 'rxjs'; | ||
import { deepFreeze } from '@osd/std'; | ||
import { OverviewApp } from './overview_app'; | ||
import { AppNavLinkStatus, AppStatus } from '../../../core/public'; | ||
|
||
const applicationStartMock = (apps: Map<string, PublicAppInfo>): jest.Mocked<ApplicationStart> => { | ||
const currentAppId$ = new Subject<string | undefined>(); | ||
|
||
return { | ||
applications$: new BehaviorSubject<Map<string, PublicAppInfo>>(apps), | ||
currentAppId$: currentAppId$.asObservable(), | ||
capabilities: deepFreeze({ | ||
catalogue: {}, | ||
management: {}, | ||
navLinks: {}, | ||
}), | ||
navigateToApp: jest.fn(), | ||
navigateToUrl: jest.fn(), | ||
getUrlForApp: jest.fn(), | ||
registerMountContext: jest.fn(), | ||
}; | ||
}; | ||
|
||
function renderOverviewPage(apps: Map<string, PublicAppInfo>, overviewApps?: OverviewApp[]) { | ||
return render( | ||
<ManagementOverviewWrapper | ||
application={applicationStartMock(apps)} | ||
overviewApps={overviewApps} | ||
/> | ||
); | ||
} | ||
|
||
describe('Overview page rendering', () => { | ||
it('should render normally', () => { | ||
const overviewApps: OverviewApp[] = [ | ||
{ | ||
id: 'dev_tools', | ||
title: 'Dev Tools', | ||
description: 'dev tools description', | ||
order: 0, | ||
}, | ||
]; | ||
|
||
const apps: Map<string, PublicAppInfo> = new Map<string, PublicAppInfo>(); | ||
apps.set('dev_tools', { | ||
status: AppStatus.accessible, | ||
navLinkStatus: AppNavLinkStatus.default, | ||
appRoute: '/app/console', | ||
} as PublicAppInfo); | ||
const { container, queryByText } = renderOverviewPage(apps, overviewApps); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(queryByText('Dev Tools')).not.toBeNull(); | ||
}); | ||
|
||
it('should render normally when no overview app', () => { | ||
const { container, queryByText } = renderOverviewPage(new Map<string, PublicAppInfo>()); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(queryByText('Overview')).not.toBeNull(); | ||
}); | ||
|
||
it('should render normally when no application available', () => { | ||
const overviewApps: OverviewApp[] = [ | ||
{ | ||
id: 'dev_tools', | ||
title: 'Dev Tools', | ||
description: 'dev tools description', | ||
order: 0, | ||
}, | ||
]; | ||
const { container, queryByText } = renderOverviewPage( | ||
new Map<string, PublicAppInfo>(), | ||
overviewApps | ||
); | ||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(queryByText('Dev Tools')).toBeNull(); | ||
}); | ||
|
||
it('should overview app not display when nav link status is hidden', () => { | ||
const overviewApps: OverviewApp[] = [ | ||
{ | ||
id: 'dev_tools', | ||
title: 'Dev Tools', | ||
description: 'dev tools description', | ||
order: 0, | ||
}, | ||
]; | ||
|
||
const apps: Map<string, PublicAppInfo> = new Map<string, PublicAppInfo>(); | ||
apps.set('dev_tools', { | ||
status: AppStatus.accessible, | ||
navLinkStatus: AppNavLinkStatus.hidden, | ||
appRoute: '/app/console', | ||
} as PublicAppInfo); | ||
const { queryByText } = renderOverviewPage(apps, overviewApps); | ||
expect(queryByText('Dev Tools')).toBeNull(); | ||
}); | ||
|
||
it('should overview app not display when it is invalid app', () => { | ||
const overviewApps: OverviewApp[] = [ | ||
{ | ||
id: 'invalid_app_id', | ||
title: 'Dev Tools', | ||
description: 'dev tools description', | ||
order: 0, | ||
}, | ||
]; | ||
|
||
const apps: Map<string, PublicAppInfo> = new Map<string, PublicAppInfo>(); | ||
apps.set('dev_tools', { | ||
status: AppStatus.accessible, | ||
navLinkStatus: AppNavLinkStatus.hidden, | ||
appRoute: '/app/console', | ||
} as PublicAppInfo); | ||
const { queryByText } = renderOverviewPage(apps, overviewApps); | ||
expect(queryByText('Dev Tools')).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters