Skip to content

Commit

Permalink
add util test
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao committed Mar 27, 2024
1 parent 3a5648d commit ff16c79
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/plugins/workspace/public/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function useApplications(application?: ApplicationStart) {
const applications = useObservable(application?.applications$ ?? of(new Map()), new Map());
return useMemo(() => {
const apps: PublicAppInfo[] = [];
applications?.forEach((app) => {
applications.forEach((app) => {
apps.push(app);
});
return apps;
Expand Down
54 changes: 53 additions & 1 deletion src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { featureMatchesConfig } from './utils';
import { featureMatchesConfig, getSelectedFeatureQuantities } from './utils';
import { PublicAppInfo } from '../../../core/public';

describe('workspace utils: featureMatchesConfig', () => {
it('feature configured with `*` should match any features', () => {
Expand Down Expand Up @@ -91,3 +92,54 @@ describe('workspace utils: featureMatchesConfig', () => {
);
});
});

describe('workspace utils: getSelectedFeatureQuantities', () => {
const defaultApplications = [
{
appRoute: '/app/dashboards',
id: 'dashboards',
title: 'Dashboards',
category: {
id: 'opensearchDashboards',
label: 'OpenSearch Dashboards',
euiIconType: 'inputOutput',
order: 1000,
},
status: 0,
navLinkStatus: 1,
},
{
appRoute: '/app/dev_tools',
id: 'dev_tools',
title: 'Dev Tools',
category: {
id: 'management',
label: 'Management',
order: 5000,
euiIconType: 'managementApp',
},
status: 0,
navLinkStatus: 1,
},
] as PublicAppInfo[];
it('should support * rules', () => {
const { total, selected } = getSelectedFeatureQuantities(['*'], defaultApplications);
expect(total).toBe(2);
expect(selected).toBe(2);
});

it('should support @ and exclude rule', () => {
const { total, selected } = getSelectedFeatureQuantities(['!@management'], defaultApplications);
expect(total).toBe(2);
expect(selected).toBe(0);
});

it('should get quantity normally', () => {
const { total, selected } = getSelectedFeatureQuantities(
['!@management', 'dev_tools'],
defaultApplications
);
expect(total).toBe(2);
expect(selected).toBe(1);
});
});

0 comments on commit ff16c79

Please sign in to comment.