Skip to content
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
53 changes: 45 additions & 8 deletions packages/react-core/src/components/Badge/__tests__/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
import * as React from 'react';
import { render, screen } from '@testing-library/react';
import { Badge } from '../Badge';
import React from 'react';
import { render } from '@testing-library/react';

Object.values([true, false]).forEach(isRead => {
test(`${isRead} Badge`, () => {
const { asFragment } = render(<Badge isRead={isRead}>{isRead ? 'read' : 'unread'} Badge</Badge>);
expect(asFragment()).toMatchSnapshot();
});

test('Renders without children', () => {
render(
<div data-testid="badge">
<Badge />
</div>
);
expect(screen.getByTestId('badge').firstChild).toBeVisible();
});

test('Renders children', () => {
render(<Badge>Test</Badge>);
expect(screen.getByText('Test')).toBeVisible();
});

test('Renders with class name pf-c-badge', () => {
render(<Badge>Test</Badge>);
expect(screen.getByText('Test')).toHaveClass('pf-c-badge');
});

test('Renders with class name pf-m-unread by default', () => {
render(<Badge>Test</Badge>);
expect(screen.getByText('Test')).toHaveClass('pf-m-unread');
});

test('Renders with class name pf-m-read when isRead prop is true', () => {
render(<Badge isRead={true}>Test</Badge>);
expect(screen.getByText('Test')).toHaveClass('pf-m-read');
});

test('Renders with custom class name when className prop is provided', () => {
render(<Badge className="custom-class">Test</Badge>);
expect(screen.getByText('Test')).toHaveClass('custom-class');
});

test('Renders with inherited element props spread to the component', () => {
render(<Badge aria-label="Test label">Test</Badge>);
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
});

test('Matches the snapshot', () => {
const { asFragment } = render(<Badge>Test</Badge>);
expect(asFragment()).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`false Badge 1`] = `
exports[`Matches the snapshot 1`] = `
<DocumentFragment>
<span
class="pf-c-badge pf-m-unread"
>
unread Badge
</span>
</DocumentFragment>
`;

exports[`true Badge 1`] = `
<DocumentFragment>
<span
class="pf-c-badge pf-m-read"
>
read Badge
Test
</span>
</DocumentFragment>
`;