Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianogorza committed Dec 6, 2023
1 parent 85fdd8a commit 77b4046
Show file tree
Hide file tree
Showing 9 changed files with 1,892 additions and 206 deletions.
74 changes: 49 additions & 25 deletions plugins/main/public/components/common/welcome/overview-welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,25 @@ import {
EuiButtonEmpty,
} from '@elastic/eui';
import './welcome.scss';
import { withErrorBoundary, withGlobalBreadcrumb, withReduxProvider } from '../hocs';
import {
withErrorBoundary,
withGlobalBreadcrumb,
withReduxProvider,
} from '../hocs';
import { compose } from 'redux';
import { Applications, Categories, endpointSumary, overview } from '../../../utils/applications';
import {
Applications,
Categories,
endpointSumary,
overview,
} from '../../../utils/applications';
import { getCore } from '../../../kibana-services';
import { RedirectAppLinks } from '../../../../../../src/plugins/opensearch_dashboards_react/public';

const appCategories = Applications.reduce((categories, app) => {
const existingCategory = categories.find((category) => category.label === app.category);
const existingCategory = categories.find(
category => category.label === app.category,
);
if (app.showInOverviewApp) {
if (existingCategory) {
existingCategory.apps.push(app);
Expand All @@ -46,17 +57,17 @@ const appCategories = Applications.reduce((categories, app) => {
return categories;
}, []).sort((a, b) => {
return (
Categories.find((category) => a.label === category.id).order -
Categories.find((category) => b.label === category.id).order
Categories.find(category => a.label === category.id).order -
Categories.find(category => b.label === category.id).order
);
});

export const OverviewWelcome = compose(
withReduxProvider,
withErrorBoundary,
withGlobalBreadcrumb((props) => {
withGlobalBreadcrumb(props => {
return [{ text: overview.title }];
})
}),
)(
class OverviewWelcome extends Component {
constructor(props) {
Expand All @@ -75,21 +86,24 @@ export const OverviewWelcome = compose(
<>
No agents were added to this manager.{' '}
<EuiButtonEmpty
href={getCore().application.getUrlForApp(endpointSumary.id, {
path: '#/agents-preview/deploy',
})}
href={getCore().application.getUrlForApp(
endpointSumary.id,
{
path: '#/agents-preview/deploy',
},
)}
>
Add agent
</EuiButtonEmpty>
</>
}
color="warning"
iconType="alert"
color='warning'
iconType='alert'
></EuiCallOut>
</RedirectAppLinks>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="xl" />
<EuiSpacer size='xl' />
</>
);
}
Expand All @@ -98,7 +112,7 @@ export const OverviewWelcome = compose(
return (
<Fragment>
<EuiPage>
<EuiFlexGroup gutterSize="l">
<EuiFlexGroup gutterSize='l'>
<EuiFlexItem>
{this.props.agentsCountTotal === 0 && this.addAgent()}
<EuiFlexGroup>
Expand All @@ -109,23 +123,33 @@ export const OverviewWelcome = compose(
title
description
betaBadgeLabel={
Categories.find((category) => category.id === label)?.label
Categories.find(category => category.id === label)
?.label
}
>
<EuiSpacer size="s" />
<EuiSpacer size='s' />
<EuiFlexGrid columns={2}>
{apps.map((app) => (
{apps.map(app => (
<EuiFlexItem key={app.id}>
<RedirectAppLinks application={getCore().application}>
<RedirectAppLinks
application={getCore().application}
>
<EuiCard
size="xs"
layout="horizontal"
icon={<EuiIcon size="xl" type={app.euiIconType} />}
className="homSynopsis__card"
size='xs'
layout='horizontal'
icon={
<EuiIcon
size='xl'
type={app.euiIconType}
/>
}
className='homSynopsis__card'
title={app.title}
href={getCore().application.getUrlForApp(app.id)}
href={getCore().application.getUrlForApp(
app.id,
)}
data-test-subj={`overviewWelcome${this.strtools.capitalize(
app.id
app.id,
)}`}
description={app.description}
/>
Expand All @@ -144,5 +168,5 @@ export const OverviewWelcome = compose(
</Fragment>
);
}
}
},
);
3 changes: 1 addition & 2 deletions plugins/main/public/components/fleet/fleet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import {
EuiCard,
EuiLink,
} from '@elastic/eui';
import { AgentsTable } from './table/agent-table';
import { AgentsTable } from './table/agents-table';
import { WzRequest } from '../../react-services/wz-request';
import KibanaVis from '../../kibana-integrations/kibana-vis';
import WzReduxProvider from '../../redux/wz-redux-provider';
import { VisFactoryHandler } from '../../react-services/vis-factory-handler';
import { AppState } from '../../react-services/app-state';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { OsCard } from '../os-card/os-card';
import { OsCard } from './os-card';

jest.mock('../../../../../kibana-services', () => ({
...(jest.requireActual('../../../../../kibana-services') as object),
getHttp: jest.fn().mockReturnValue({
basePath: {
get: () => {
return 'http://localhost:5601';
},
prepend: (url) => {
return `http://localhost:5601${url}`;
},
},
}),
getCookies: jest.fn().mockReturnValue({
set: (name, value, options) => {
return true;
},
get: () => {
return '{}';
},
remove: () => {
return;
},
}),
getUiSettings: jest.fn().mockReturnValue({
get: (name) => {
return true;
},
}),
}));
// jest.mock('../../../../../../kibana-services', () => ({
// ...(jest.requireActual('../../../../../../kibana-services') as object),
// getHttp: jest.fn().mockReturnValue({
// basePath: {
// get: () => {
// return 'http://localhost:5601';
// },
// prepend: url => {
// return `http://localhost:5601${url}`;
// },
// },
// }),
// getCookies: jest.fn().mockReturnValue({
// set: (name, value, options) => {
// return true;
// },
// get: () => {
// return '{}';
// },
// remove: () => {
// return;
// },
// }),
// getUiSettings: jest.fn().mockReturnValue({
// get: name => {
// return true;
// },
// }),
// }));

describe('OsCard', () => {
test('renders three cards with different titles', () => {
Expand Down
Loading

0 comments on commit 77b4046

Please sign in to comment.