|
1 | 1 | import * as React from 'react';
|
| 2 | +import { expect } from 'chai'; |
| 3 | +import { spy } from 'sinon'; |
2 | 4 | import { Progress } from '@base-ui-components/react/progress';
|
3 | 5 | import { createRenderer, describeConformance } from '#test-utils';
|
4 | 6 | import { ProgressRootContext } from '../root/ProgressRootContext';
|
@@ -27,4 +29,51 @@ describe('<Progress.Value />', () => {
|
27 | 29 | },
|
28 | 30 | refInstanceof: window.HTMLSpanElement,
|
29 | 31 | }));
|
| 32 | + |
| 33 | + describe('prop: children', () => { |
| 34 | + it('renders the value when children is not provided', async () => { |
| 35 | + const { getByTestId } = await render( |
| 36 | + <Progress.Root value={30}> |
| 37 | + <Progress.Value data-testid="value" /> |
| 38 | + </Progress.Root>, |
| 39 | + ); |
| 40 | + const value = getByTestId('value'); |
| 41 | + expect(value).to.have.text('30%'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('renders a formatted value when a format is provided', async () => { |
| 45 | + const format: Intl.NumberFormatOptions = { |
| 46 | + style: 'currency', |
| 47 | + currency: 'USD', |
| 48 | + }; |
| 49 | + function formatValue(v: number) { |
| 50 | + return new Intl.NumberFormat(undefined, format).format(v); |
| 51 | + } |
| 52 | + const { getByTestId } = await render( |
| 53 | + <Progress.Root value={30} format={format}> |
| 54 | + <Progress.Value data-testid="value" /> |
| 55 | + </Progress.Root>, |
| 56 | + ); |
| 57 | + const value = getByTestId('value'); |
| 58 | + expect(value).to.have.text(formatValue(30)); |
| 59 | + }); |
| 60 | + |
| 61 | + it('accepts a render function', async () => { |
| 62 | + const renderSpy = spy(); |
| 63 | + const format: Intl.NumberFormatOptions = { |
| 64 | + style: 'currency', |
| 65 | + currency: 'USD', |
| 66 | + }; |
| 67 | + function formatValue(v: number) { |
| 68 | + return new Intl.NumberFormat(undefined, format).format(v); |
| 69 | + } |
| 70 | + await render( |
| 71 | + <Progress.Root value={30} format={format}> |
| 72 | + <Progress.Value data-testid="value">{renderSpy}</Progress.Value> |
| 73 | + </Progress.Root>, |
| 74 | + ); |
| 75 | + expect(renderSpy.lastCall.args[0]).to.deep.equal(formatValue(30)); |
| 76 | + expect(renderSpy.lastCall.args[1]).to.deep.equal(30); |
| 77 | + }); |
| 78 | + }); |
30 | 79 | });
|
0 commit comments