Skip to content

Commit

Permalink
test: Decimal support Progress Table Cell Type h2oai#824
Browse files Browse the repository at this point in the history
  • Loading branch information
Modhurima Roy Kenopy committed Dec 13, 2023
1 parent 7887ef6 commit 29b4010
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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 >
)

0 comments on commit 29b4010

Please sign in to comment.