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

Fix #3567: Add jest unit testing to Badge component #3568

Merged
merged 2 commits into from
Nov 3, 2022
Merged
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
83 changes: 83 additions & 0 deletions components/lib/badge/Badge.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { Badge } from './Badge';

describe('Badge', () => {
test('when value is not property it returns with dot class', () => {
// Arrange
const { container } = render(<Badge />);

// Act + Assert
expect(container.getElementsByClassName('p-badge-dot').length).toBe(1);
});

test('when value is property it returns with class', () => {
// Arrange
const { container } = render(<Badge value={22} />);
const badge = container.getElementsByClassName('p-badge p-component')[0].textContent;

// Act + Assert
expect(badge).toBe('22');
});

test('when size as property it returns with class', () => {
// Arrange
const { container } = render(<Badge size={'large'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-lg').length).toBe(1);
});
test('when size as property it returns with class', () => {
// Arrange
const { container } = render(<Badge size={'xlarge'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-xl').length).toBe(1);
});

test('when value of size property is invalid it returns with default class', () => {
// Arrange
const { container } = render(<Badge size={'invalid'} />);

// Act + Assert

expect(container.getElementsByClassName('p-badge p-component').length).toBe(1);
});

test('when severity as property it returns with class', () => {
// Arrange
const { container } = render(<Badge severity={'success'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-success').length).toBe(1);
});
melloware marked this conversation as resolved.
Show resolved Hide resolved
test('when severity as property it returns with class', () => {
// Arrange
const { container } = render(<Badge severity={'info'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-info').length).toBe(1);
});
test('when severity as property it returns with class', () => {
// Arrange
const { container } = render(<Badge severity={'warning'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-warning').length).toBe(1);
});
test('when severity as property it returns with class', () => {
// Arrange
const { container } = render(<Badge severity={'danger'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-danger').length).toBe(1);
});

test('when value of severity property is invalid it returns with class that has property additional class', () => {
// Arrange
const { container } = render(<Badge severity={'invalid'} />);

// Act + Assert
expect(container.getElementsByClassName('p-badge p-component p-badge-invalid').length).toBe(1);
});
});