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
21 changes: 21 additions & 0 deletions frontend/src/components/ui/progress.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import { Progress } from './progress';

describe('Progress Component', () => {
it('renders correctly with default values', () => {
render(<Progress />);
const progressbar = screen.getByRole('progressbar');
expect(progressbar).toBeInTheDocument();
expect(progressbar).toHaveAttribute('aria-valuemin', '0');
expect(progressbar).toHaveAttribute('aria-valuemax', '100');
expect(progressbar).toHaveAttribute('aria-valuenow', '0');
});

it('renders correctly with custom value and max', () => {
render(<Progress value={50} max={200} />);
const progressbar = screen.getByRole('progressbar');
expect(progressbar).toHaveAttribute('aria-valuenow', '50');
expect(progressbar).toHaveAttribute('aria-valuemax', '200');
});
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests assert the presence of ARIA attributes for default/custom cases, but they don't cover the out-of-range scenarios where the component currently clamps the visual fill. Adding tests for value > max and value < 0 would prevent regressions and ensure ARIA values stay consistent with the rendered progress.

Suggested change
});
});
it('clamps aria-valuenow to max when value exceeds max', () => {
render(<Progress value={150} max={100} />);
const progressbar = screen.getByRole('progressbar');
expect(progressbar).toHaveAttribute('aria-valuenow', '100');
expect(progressbar).toHaveAttribute('aria-valuemax', '100');
});
it('clamps aria-valuenow to the minimum when value is below zero', () => {
render(<Progress value={-10} max={100} />);
const progressbar = screen.getByRole('progressbar');
expect(progressbar).toHaveAttribute('aria-valuenow', '0');
expect(progressbar).toHaveAttribute('aria-valuemin', '0');
});

Copilot uses AI. Check for mistakes.
});
4 changes: 4 additions & 0 deletions frontend/src/components/ui/progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const Progress: React.FC<ProgressProps> = ({

return (
<div
role="progressbar"
aria-valuemin={0}
aria-valuemax={max}
aria-valuenow={value}
className={`relative w-full overflow-hidden rounded-full bg-gray-200 ${className}`}
Comment on lines +18 to 22
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aria-valuenow is set to the raw value, but the visual fill is clamped to 0–100% via percentage. If callers pass value < 0 or value > max, the UI will clamp while the ARIA attributes can become invalid/inconsistent (e.g., aria-valuenow > aria-valuemax). Consider clamping value into [0, max] (and using that clamped value for both percentage and aria-valuenow).

Copilot uses AI. Check for mistakes.
{...props}
>
Expand Down
Loading