Skip to content
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
8 changes: 7 additions & 1 deletion src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ const ProgressBar = ({
accessibilityValue={
indeterminate
? {}
: { min: 0, max: 100, now: Math.round(progress * 100) }
: {
min: 0,
max: 100,
now: Math.round(
(animatedValue !== undefined ? animatedValue : progress) * 100
),
}
}
style={isWeb && styles.webContainer}
testID={testID}
Expand Down
42 changes: 42 additions & 0 deletions src/components/__tests__/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,45 @@ it('renders progress bar with custom style of filled part', async () => {
borderRadius: 4,
});
});

it('sets correct accessibilityValue with progress prop', async () => {
const tree = render(<ProgressBar progress={0.2} />);
await waitFor(() => tree.getByRole(a11yRole).props.onLayout(layoutEvent));

expect(tree.getByRole(a11yRole).props.accessibilityValue).toEqual({
min: 0,
max: 100,
now: 20,
});
});

it('sets correct accessibilityValue with animatedValue prop', async () => {
const tree = render(<ProgressBar animatedValue={0.4} />);
await waitFor(() => tree.getByRole(a11yRole).props.onLayout(layoutEvent));

expect(tree.getByRole(a11yRole).props.accessibilityValue).toEqual({
min: 0,
max: 100,
now: 40,
});
});

it('updates accessibilityValue when animatedValue changes', async () => {
const tree = render(<ProgressBar animatedValue={0.2} />);
await waitFor(() => tree.getByRole(a11yRole).props.onLayout(layoutEvent));

tree.update(<ProgressBar animatedValue={0.6} />);

expect(tree.getByRole(a11yRole).props.accessibilityValue).toEqual({
min: 0,
max: 100,
now: 60,
});
});

it('sets empty accessibilityValue when indeterminate is true', async () => {
const tree = render(<ProgressBar indeterminate />);
await waitFor(() => tree.getByRole(a11yRole).props.onLayout(layoutEvent));

expect(tree.getByRole(a11yRole).props.accessibilityValue).toEqual({});
});