-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vcd)(post-ga): add VDC usage tile (#13831)
ref: MANAGER-15243 Signed-off-by: Paul Dickerson <[email protected]> Co-authored-by: Paul Dickerson <[email protected]>
- Loading branch information
Showing
6 changed files
with
127 additions
and
28 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
...-managed-vcd/src/components/tiles/datacentre-usage-tile/DatacentreUsageTile.component.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,54 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
ActionMenu, | ||
DashboardTile, | ||
Description, | ||
} from '@ovh-ux/manager-react-components'; | ||
import { ODS_ICON_NAME } from '@ovhcloud/ods-components'; | ||
import IVcdDatacentre from '@/types/vcd-datacenter.interface'; | ||
|
||
type TTileProps = { | ||
vcdDatacentre: IVcdDatacentre; | ||
}; | ||
|
||
export default function DatacentreUsageTile({ | ||
vcdDatacentre, | ||
}: Readonly<TTileProps>) { | ||
const { t } = useTranslation('hpc-vmware-managed-vcd/datacentres'); | ||
|
||
return ( | ||
<div> | ||
<DashboardTile | ||
title={t('managed_vcd_vdc_usage')} | ||
items={[ | ||
{ | ||
id: 'vcpuSpeed', | ||
label: t('managed_vcd_vdc_vcpu_speed'), | ||
value: ( | ||
<div className="flex items-center justify-between"> | ||
<Description> | ||
{t('managed_vcd_vdc_vcpu_value', { | ||
speed: vcdDatacentre?.currentState.vCPUSpeed, | ||
})} | ||
</Description> | ||
<ActionMenu | ||
items={[]} | ||
icon={ODS_ICON_NAME.ELLIPSIS_VERTICAL} | ||
isCompact | ||
/> | ||
</div> | ||
), | ||
}, | ||
{ | ||
id: 'vcpuCount', | ||
label: t('managed_vcd_vdc_vcpu_count'), | ||
value: ( | ||
<Description>{vcdDatacentre?.currentState.vCPUCount}</Description> | ||
), | ||
}, | ||
]} | ||
/> | ||
</div> | ||
); | ||
} |
66 changes: 66 additions & 0 deletions
66
...mware-managed-vcd/src/components/tiles/datacentre-usage-tile/DatacentreUsageTile.spec.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,66 @@ | ||
import React from 'react'; | ||
import { vi } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import { | ||
ODS_THEME_TYPOGRAPHY_LEVEL, | ||
ODS_THEME_TYPOGRAPHY_SIZE, | ||
} from '@ovhcloud/ods-common-theming'; | ||
import DatacentreUsageTile from './DatacentreUsageTile.component'; | ||
import { datacentreList } from '../../../../mocks/vcd-organization/vcd-datacentre.mock'; | ||
|
||
type TTileItem = { | ||
label: HTMLElement; | ||
value: HTMLElement; | ||
}; | ||
|
||
const testVDC = datacentreList[0]; | ||
|
||
vi.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string, options: Record<string, unknown>) => { | ||
if (key === 'managed_vcd_vdc_vcpu_value') { | ||
return `${options.speed} GHz`; | ||
} | ||
return key; | ||
}, | ||
}), | ||
})); | ||
|
||
describe('DatacentreUsageTile component unit test suite', () => { | ||
it('should define all sections with correct typo', () => { | ||
// when | ||
const { getByText } = render( | ||
<DatacentreUsageTile vcdDatacentre={testVDC} />, | ||
); | ||
|
||
// then | ||
const usageTitle = getByText('managed_vcd_vdc_usage'); | ||
expect(usageTitle).toBeVisible(); | ||
|
||
// and | ||
const tileItems: TTileItem[] = [ | ||
{ | ||
label: getByText('managed_vcd_vdc_vcpu_speed'), | ||
value: getByText(`${testVDC.currentState.vCPUSpeed} GHz`), | ||
}, | ||
{ | ||
label: getByText('managed_vcd_vdc_vcpu_count'), | ||
value: getByText(testVDC.currentState.vCPUCount), | ||
}, | ||
]; | ||
|
||
tileItems.forEach((item: TTileItem) => { | ||
expect(item.label).toBeVisible(); | ||
expect(item.value).toBeVisible(); | ||
|
||
expect(item.label).toHaveAttribute( | ||
'size', | ||
ODS_THEME_TYPOGRAPHY_SIZE._200, | ||
); | ||
expect(item.label).toHaveAttribute( | ||
'level', | ||
ODS_THEME_TYPOGRAPHY_LEVEL.heading, | ||
); | ||
}); | ||
}); | ||
}); |
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