import { render, screen } from '@testing-library/react';
import { Progress, ProgressSize } from '../Progress';
import { ProgressVariant, ProgressMeasureLocation } from '../ProgressContainer';
test('Simple progress', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('no value specified', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('additional label', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('Progress with aria-valuetext', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('value lower than minValue', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('value higher than maxValue', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('value scaled with minValue', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('value scaled with maxValue', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('value scaled between minValue and maxValue', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
describe('Progress size', () => {
Object.keys(ProgressSize).forEach((oneSize) => {
test(oneSize, () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
});
});
describe('Progress variant', () => {
Object.keys(ProgressVariant).forEach((oneVariant) => {
test(oneVariant, () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
});
});
describe('Progress measure location', () => {
Object.keys(ProgressMeasureLocation).forEach((oneLocation) => {
test(oneLocation, () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
});
test('inside and small should render large', () => {
const { asFragment } = render(
);
expect(asFragment()).toMatchSnapshot();
});
});
test('progress component generates console warning when no accessible name is provided', () => {
const consoleWarnMock = jest.fn();
global.console = { warn: consoleWarnMock } as any;
render();
expect(consoleWarnMock).toHaveBeenCalled();
});
test('Does not render helper text by default', () => {
render();
expect(screen.queryByText('Test helper text')).not.toBeInTheDocument();
});
test('Renders passed helper text', () => {
render();
expect(screen.getByText('Test helper text')).toBeVisible();
});
describe('hideStatusIcon prop behavior', () => {
test('shows status icon by default when hideStatusIcon is not set', () => {
render();
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
});
test('hides status icon when hideStatusIcon flag is set with success variant', () => {
render();
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
});
test('hides status icon when hideStatusIcon flag is set with danger variant', () => {
render();
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
});
test('hides status icon when hideStatusIcon flag is set with warning variant', () => {
render();
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
});
test('shows status icon when hideStatusIcon is explicitly false', () => {
render();
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
});
});