forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elastic#8 from angorayc/onboarding-fleet-integration
Onboarding fleet integration
- Loading branch information
Showing
55 changed files
with
2,262 additions
and
75 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
...eet/public/applications/integrations/sections/epm/components/installation_status.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,130 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { installationStatuses } from '../../../../../../common/constants'; | ||
|
||
import { | ||
InstallationStatus, | ||
getLineClampStyles, | ||
shouldShowInstallationStatus, | ||
} from './installation_status'; | ||
|
||
// Mock useEuiTheme to return a mock theme | ||
jest.mock('@elastic/eui', () => ({ | ||
...jest.requireActual('@elastic/eui'), | ||
useEuiTheme: () => ({ | ||
euiTheme: { | ||
border: { radius: { medium: '4px' } }, | ||
size: { s: '8px', m: '16px' }, | ||
colors: { emptyShade: '#FFFFFF' }, | ||
}, | ||
}), | ||
})); | ||
|
||
describe('getLineClampStyles', () => { | ||
it('returns the correct styles when lineClamp is provided', () => { | ||
expect(getLineClampStyles(3)).toEqual( | ||
'-webkit-line-clamp: 3;display: -webkit-box;-webkit-box-orient: vertical;overflow: hidden;' | ||
); | ||
}); | ||
|
||
it('returns an empty string when lineClamp is not provided', () => { | ||
expect(getLineClampStyles()).toEqual(''); | ||
}); | ||
}); | ||
|
||
describe('shouldShowInstallationStatus', () => { | ||
it('returns false when showInstallationStatus is false', () => { | ||
expect( | ||
shouldShowInstallationStatus({ | ||
installStatus: installationStatuses.Installed, | ||
showInstallationStatus: false, | ||
}) | ||
).toEqual(false); | ||
}); | ||
|
||
it('returns true when showInstallationStatus is true and installStatus is installed', () => { | ||
expect( | ||
shouldShowInstallationStatus({ | ||
installStatus: installationStatuses.Installed, | ||
showInstallationStatus: true, | ||
}) | ||
).toEqual(true); | ||
}); | ||
|
||
it('returns true when showInstallationStatus is true and installStatus is installFailed', () => { | ||
expect( | ||
shouldShowInstallationStatus({ | ||
installStatus: installationStatuses.InstallFailed, | ||
showInstallationStatus: true, | ||
}) | ||
).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('InstallationStatus', () => { | ||
it('renders null when showInstallationStatus is false', () => { | ||
const { container } = render( | ||
<InstallationStatus | ||
installStatus={installationStatuses.Installed} | ||
showInstallationStatus={false} | ||
/> | ||
); | ||
expect(container.firstChild).toBeNull(); | ||
}); | ||
|
||
it('renders the Installed status correctly', () => { | ||
render( | ||
<InstallationStatus | ||
installStatus={installationStatuses.Installed} | ||
showInstallationStatus={true} | ||
/> | ||
); | ||
expect(screen.getByText('Installed')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the Install Failed status correctly', () => { | ||
render( | ||
<InstallationStatus | ||
installStatus={installationStatuses.InstallFailed} | ||
showInstallationStatus={true} | ||
/> | ||
); | ||
expect(screen.getByText('Installed')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders null when installStatus is null or undefined', () => { | ||
const { container } = render( | ||
<InstallationStatus installStatus={null} showInstallationStatus={true} /> | ||
); | ||
expect(container.firstChild).toBeNull(); | ||
|
||
const { container: undefinedContainer } = render( | ||
<InstallationStatus installStatus={undefined} showInstallationStatus={true} /> | ||
); | ||
expect(undefinedContainer.firstChild).toBeNull(); | ||
}); | ||
|
||
it('applies the correct styles for the component', () => { | ||
const { getByTestId } = render( | ||
<InstallationStatus | ||
installStatus={installationStatuses.Installed} | ||
showInstallationStatus={true} | ||
/> | ||
); | ||
|
||
const spacer = getByTestId('installation-status-spacer'); | ||
const callout = getByTestId('installation-status-callout'); | ||
|
||
expect(spacer).toHaveStyle('background: #FFFFFF'); | ||
expect(callout).toHaveStyle('padding: 8px 16px'); | ||
expect(callout).toHaveTextContent('Installed'); | ||
}); | ||
}); |
87 changes: 87 additions & 0 deletions
87
...ns/fleet/public/applications/integrations/sections/epm/components/installation_status.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,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiCallOut, EuiSpacer, useEuiTheme } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { css } from '@emotion/react'; | ||
|
||
import { installationStatuses } from '../../../../../../common/constants'; | ||
import type { EpmPackageInstallStatus } from '../../../../../../common/types'; | ||
|
||
const installedLabel = i18n.translate('xpack.fleet.packageCard.installedLabel', { | ||
defaultMessage: 'Installed', | ||
}); | ||
|
||
const installStatusMapToColor: Readonly< | ||
Record<string, { color: 'success' | 'warning'; iconType: string; title: string }> | ||
> = { | ||
installed: { | ||
color: 'success', | ||
iconType: 'check', | ||
title: installedLabel, | ||
}, | ||
install_failed: { | ||
color: 'warning', | ||
iconType: 'warning', | ||
title: installedLabel, | ||
}, | ||
}; | ||
|
||
interface InstallationStatusProps { | ||
installStatus: EpmPackageInstallStatus | null | undefined; | ||
showInstallationStatus?: boolean; | ||
} | ||
|
||
export const getLineClampStyles = (lineClamp?: number) => | ||
lineClamp | ||
? `-webkit-line-clamp: ${lineClamp};display: -webkit-box;-webkit-box-orient: vertical;overflow: hidden;` | ||
: ''; | ||
|
||
export const shouldShowInstallationStatus = ({ | ||
installStatus, | ||
showInstallationStatus, | ||
}: InstallationStatusProps) => | ||
showInstallationStatus && | ||
(installStatus === installationStatuses.Installed || | ||
installStatus === installationStatuses.InstallFailed); | ||
|
||
export const InstallationStatus: React.FC<InstallationStatusProps> = React.memo( | ||
({ installStatus, showInstallationStatus }) => { | ||
const { euiTheme } = useEuiTheme(); | ||
return shouldShowInstallationStatus({ installStatus, showInstallationStatus }) ? ( | ||
<div | ||
css={css` | ||
position: absolute; | ||
border-radius: 0 0 ${euiTheme.border.radius.medium} ${euiTheme.border.radius.medium}; | ||
bottom: 0; | ||
left: 0; | ||
width: 100%; | ||
overflow: hidden; | ||
`} | ||
> | ||
<EuiSpacer | ||
data-test-subj="installation-status-spacer" | ||
size="m" | ||
css={css` | ||
background: ${euiTheme.colors.emptyShade}; | ||
`} | ||
/> | ||
<EuiCallOut | ||
data-test-subj="installation-status-callout" | ||
css={css` | ||
padding: ${euiTheme.size.s} ${euiTheme.size.m}; | ||
text-align: center; | ||
`} | ||
{...(installStatus ? installStatusMapToColor[installStatus] : {})} | ||
/> | ||
</div> | ||
) : null; | ||
} | ||
); |
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
Oops, something went wrong.