This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0dd04e
commit 8095fa6
Showing
6 changed files
with
197 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { InlineLoading } from '../../Loading'; | ||
|
||
import { | ||
DashboardCard, | ||
DashboardCardBody, | ||
DashboardCardHeader, | ||
DashboardCardTitle, | ||
} from '../../Dashboard/DashboardCard'; | ||
import { StorageOverviewContext } from '../StorageOverviewContext'; | ||
import { CapacityItem } from '../../Dashboard/Capacity/CapacityItem'; | ||
import { formatBytes } from '../../../utils'; | ||
import { getCapacityStats } from '../../../selectors'; | ||
import { CapacityBody } from '../../Dashboard/Capacity/CapacityBody'; | ||
|
||
export const Capacity = ({ capacityTotal, capacityUsed, LoadingComponent }) => ( | ||
<DashboardCard> | ||
<DashboardCardHeader> | ||
<DashboardCardTitle>Capacity</DashboardCardTitle> | ||
</DashboardCardHeader> | ||
<DashboardCardBody> | ||
<CapacityBody> | ||
<CapacityItem | ||
id="capacity" | ||
title="Total capacity" | ||
used={getCapacityStats(capacityUsed)} | ||
total={getCapacityStats(capacityTotal)} | ||
formatValue={formatBytes} | ||
LoadingComponent={LoadingComponent} | ||
isLoading={!(capacityUsed && capacityTotal)} | ||
/> | ||
</CapacityBody> | ||
</DashboardCardBody> | ||
</DashboardCard> | ||
); | ||
|
||
Capacity.defaultProps = { | ||
capacityTotal: null, | ||
capacityUsed: null, | ||
LoadingComponent: InlineLoading, | ||
}; | ||
|
||
Capacity.propTypes = { | ||
capacityTotal: PropTypes.object, | ||
capacityUsed: PropTypes.object, | ||
LoadingComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), | ||
}; | ||
|
||
export const CapacityConnected = () => ( | ||
<StorageOverviewContext.Consumer>{props => <Capacity {...props} />}</StorageOverviewContext.Consumer> | ||
); |
21 changes: 21 additions & 0 deletions
21
src/components/StorageOverview/Capacity/fixtures/Capacity.fixture.js
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,21 @@ | ||
import { Capacity } from '../Capacity'; | ||
|
||
const getPromResponse = value => ({ | ||
data: { | ||
result: [ | ||
{ | ||
value: [0, value], | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
export const capacityStats = { | ||
capacityTotal: getPromResponse(11), | ||
capacityUsed: getPromResponse(5), | ||
}; | ||
|
||
export default { | ||
component: Capacity, | ||
props: { capacityStats }, | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/components/StorageOverview/Capacity/tests/Capacity.test.js
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,19 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
|
||
import { Capacity } from '../Capacity'; | ||
import { default as CapacityFixtures } from '../fixtures/Capacity.fixture'; | ||
|
||
const testCapacityOverview = () => <Capacity {...CapacityFixtures.props} />; | ||
|
||
describe('<Capacity />', () => { | ||
it('renders correctly', () => { | ||
const component = render(testCapacityOverview()); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly in Loading state', () => { | ||
const component = render(<Capacity />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
src/components/StorageOverview/Capacity/tests/__snapshots__/Capacity.test.js.snap
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,91 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<Capacity /> renders correctly 1`] = ` | ||
<div | ||
class="card-pf kubevirt-dashboard__card" | ||
> | ||
<div | ||
class="card-pf-heading kubevirt-dashboard__card-heading" | ||
> | ||
<h2 | ||
class="card-pf-title" | ||
> | ||
Capacity | ||
</h2> | ||
</div> | ||
<div | ||
class="card-pf-body" | ||
> | ||
<div | ||
class="kubevirt-capacity__items" | ||
> | ||
<div | ||
class="kubevirt-capacity__item" | ||
> | ||
<h2 | ||
class="kubevirt-capacity__item-title" | ||
> | ||
Total Capacity | ||
</h2> | ||
<h6> | ||
<div> | ||
<div | ||
class="spinner spinner-md blank-slate-pf-icon" | ||
/> | ||
</div> | ||
</h6> | ||
<div> | ||
<div | ||
class=" donut-chart-pf" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
exports[`<Capacity /> renders correctly in Loading state 1`] = ` | ||
<div | ||
class="card-pf kubevirt-dashboard__card" | ||
> | ||
<div | ||
class="card-pf-heading kubevirt-dashboard__card-heading" | ||
> | ||
<h2 | ||
class="card-pf-title" | ||
> | ||
Capacity | ||
</h2> | ||
</div> | ||
<div | ||
class="card-pf-body" | ||
> | ||
<div | ||
class="kubevirt-capacity__items" | ||
> | ||
<div | ||
class="kubevirt-capacity__item" | ||
> | ||
<h2 | ||
class="kubevirt-capacity__item-title" | ||
> | ||
Total Capacity | ||
</h2> | ||
<h6> | ||
<div> | ||
<div | ||
class="spinner spinner-md blank-slate-pf-icon" | ||
/> | ||
</div> | ||
</h6> | ||
<div> | ||
<div | ||
class=" donut-chart-pf" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
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