Skip to content

Commit 0260430

Browse files
authored
feat: Support decimal values in table progress cell type #824 (#2329)
1 parent 9bd3cb3 commit 0260430

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ui/src/progress_table_cell_type.test.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ import { ProgressTableCellType, XProgressTableCellType } from './progress_table_
1919
const
2020
name = 'progress-cell',
2121
progress = 0.0,
22-
progressCellProps: ProgressTableCellType = { name }
22+
progressCellProps: ProgressTableCellType = { name },
23+
progressValues = [
24+
{input: 0.88, output: '88%'},
25+
{input: 0.888, output: '88.8%'},
26+
{input: 0.8888, output: '88.88%'},
27+
{input: 0.88888, output: '88.89%'},
28+
{input: 0.88899, output: '88.90%'},
29+
{input: 0.88999, output: '89.00%'},]
2330

2431
describe('ProgressTableCellType.tsx', () => {
2532

@@ -32,4 +39,13 @@ describe('ProgressTableCellType.tsx', () => {
3239
const { queryByTestId } = render(<XProgressTableCellType model={progressCellProps} progress={progress} />)
3340
expect(queryByTestId(name)).toBeInTheDocument()
3441
})
42+
43+
it('Renders data-test attr with decimal values', () => {
44+
const { queryByTestId, rerender } = render(<XProgressTableCellType model={progressCellProps} progress={progress} />)
45+
progressValues.map(progressValue => {
46+
rerender(<XProgressTableCellType model={progressCellProps} progress={progressValue.input} />)
47+
expect(queryByTestId(name)).toBeInTheDocument()
48+
expect(queryByTestId(name)).toHaveTextContent(progressValue.output)
49+
})
50+
})
3551
})

ui/src/progress_table_cell_type.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const XProgressTableCellType = ({ model: m, progress }: { model: Progress
5050
<div data-test={m.name} className={css.container}>
5151
<ProgressArc thickness={2} color={cssVar(m.color || '$red')} value={progress} />
5252
<Fluent.Stack horizontalAlign='center' verticalAlign='center' className={clas(css.percentContainer, 'wave-s12')}>
53-
<div className={css.percent}>{`${Math.round(progress * 100)}%`}</div>
53+
<div className={css.percent}>{`${Number.isInteger(progress * 1000) ? (progress * 100) : (progress * 100).toFixed(2)}%`}</div>
5454
</Fluent.Stack>
5555
</div >
5656
)

0 commit comments

Comments
 (0)