import { render, screen } from '@testing-library/react' import { describe, expect, it } from 'vitest' import { expectNoA11yViolations } from '../test/a11y' import { Meter, Progress } from './Progress' describe('Progress', () => { it('exposes the value on a labelled progressbar', () => { render() const bar = screen.getByRole('progressbar', { name: 'Exporting' }) expect(bar).toHaveAttribute('aria-valuenow', '40') expect(bar).toHaveAttribute('aria-valuemax', '100') expect(screen.getByText('40%')).toBeInTheDocument() }) it('is indeterminate with value null', () => { render() const bar = screen.getByRole('progressbar', { name: 'Preparing' }) expect(bar).not.toHaveAttribute('aria-valuenow') }) it('formats with a function', () => { render( `${v} of ${max} files`} />) expect(screen.getByText('3 of 8 files')).toBeInTheDocument() expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuetext', '3 of 8 files') }) it('has no axe violations', async () => { const { container } = render(
, ) await expectNoA11yViolations(container) }) }) describe('Meter', () => { it('is a labelled meter with its value', () => { render() const meter = screen.getByRole('meter', { name: 'API requests' }) expect(meter).toHaveAttribute('aria-valuenow', '92') }) })