Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: switch progress bar tests to react testing library #1366

Merged
merged 2 commits into from
Feb 28, 2024
Merged
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
40 changes: 0 additions & 40 deletions packages/react/__tests__/src/components/ProgressBar/index.js

This file was deleted.

41 changes: 41 additions & 0 deletions packages/react/src/components/ProgressBar/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import ProgressBar from './';
import axe from '../../axe';

test('should set correct props for progress bar', () => {
render(<ProgressBar aria-label="progress" progress={75} />);
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', '75');
expect(progressBar).toHaveAttribute('aria-label', 'progress');
});

test('should set default progress bar progress', () => {
render(<ProgressBar aria-label="progress" progress={75} />);
const progressBar = screen.getByRole('progressbar');
const progressBarFill = progressBar.querySelector('.ProgressBar--fill');
expect(progressBarFill).toHaveStyle({ width: '75%' });
});

test('should set custom progress bar progress', () => {
render(
<ProgressBar
aria-label="progress"
progressMin={0}
progressMax={25}
progress={5}
/>
);
const progressBar = screen.getByRole('progressbar');
const progressBarFill = progressBar.querySelector('.ProgressBar--fill');
expect(progressBarFill).toHaveStyle({ width: '20%' });
});

test('should return no axe violations', async () => {
render(<ProgressBar aria-label="progress" progress={75} />);
const results = await axe(screen.getByRole('progressbar'));
expect(results).toHaveNoViolations();
});
Loading