Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Decimal support Progress Table Cell Type #824 #2226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ui/src/progress_table_cell_type.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ describe('ProgressTableCellType.tsx', () => {
const { queryByTestId } = render(<XProgressTableCellType model={progressCellProps} progress={progress} />)
expect(queryByTestId(name)).toBeInTheDocument()
})

it('Renders decimal values with correct precision ', () => {
const {getByText} = render(<XProgressTableCellType model={progressCellProps} progress={progress} decimals={true}/>)
const expectedTextDecimalTrue = `${Math.round(progress * 10000) / 100}%`
expect(getByText(expectedTextDecimalTrue)).toBeInTheDocument()
})

it('Renders decimal values with correct precision ', () => {
const {getByText} = render(<XProgressTableCellType model={progressCellProps} progress={progress} decimals={false}/>)
const expectedTextDecimalFalse = `${Math.round(progress * 100)}%`
expect(getByText(expectedTextDecimalFalse)).toBeInTheDocument()
})

})
12 changes: 9 additions & 3 deletions ui/src/progress_table_cell_type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import * as Fluent from '@fluentui/react'
import { F, S } from './core'
import { F, S, B } from './core'
import React from 'react'
import { stylesheet } from 'typestyle'
import { ProgressArc } from './parts/progress_arc'
Expand Down Expand Up @@ -46,11 +46,17 @@ export interface ProgressTableCellType {
name?: S
}

export const XProgressTableCellType = ({ model: m, progress }: { model: ProgressTableCellType, progress: F }) => (
export const XProgressTableCellType = ({ model: m, progress, decimals }: { model: ProgressTableCellType, progress: F, decimals?: B }) => (
<div data-test={m.name} className={css.container}>
<ProgressArc thickness={2} color={cssVar(m.color || '$red')} value={progress} />
<Fluent.Stack horizontalAlign='center' verticalAlign='center' className={clas(css.percentContainer, 'wave-s12')}>
<div className={css.percent}>{`${Math.round(progress * 100)}%`}</div>
<div className={css.percent}>
{decimals ? (
`${Math.round(progress *10000)/ 100}%`
) : (
`${Math.round(progress * 100)}%`
)}
</div>
</Fluent.Stack>
</div >
)