-
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.
Browse files
Browse the repository at this point in the history
* refactor for management overview page Signed-off-by: Hailong Cui <[email protected]> * Add missing changelog Signed-off-by: Hailong Cui <[email protected]> * Add unit test Signed-off-by: Hailong Cui <[email protected]> * remove duplicate snapshot validation Signed-off-by: Hailong Cui <[email protected]> * Update src/plugins/management_overview/public/application.test.tsx Co-authored-by: Josh Romero <[email protected]> Signed-off-by: Hailong Cui <[email protected]> * Update src/plugins/management_overview/public/application.test.tsx Co-authored-by: Josh Romero <[email protected]> Signed-off-by: Hailong Cui <[email protected]> * export empty plugin start to make it consistent Signed-off-by: Hailong Cui <[email protected]> * export empty plugin start to make it consistent Signed-off-by: Hailong Cui <[email protected]> --------- Signed-off-by: Hailong Cui <[email protected]> Co-authored-by: Josh Romero <[email protected]> Co-authored-by: Ashwin P Chandran <[email protected]> (cherry picked from commit 16b1e29) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fae4e3c
commit 4db18c9
Showing
4 changed files
with
201 additions
and
18 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
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.
121 changes: 121 additions & 0 deletions
121
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,121 @@ | ||
/* | ||
* 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 { queryByText } = renderOverviewPage(new Map<string, PublicAppInfo>()); | ||
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 { queryByText } = renderOverviewPage(new Map<string, PublicAppInfo>(), overviewApps); | ||
expect(queryByText('Dev Tools')).toBeNull(); | ||
}); | ||
|
||
it('should not display overview app 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 not display overview app 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
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