Skip to content

Commit

Permalink
Fix #3567: Add jest unit testing to Badge component (#3568)
Browse files Browse the repository at this point in the history
* Add jest unit testing to Badge component

* Improve Badge component unit tests
  • Loading branch information
habubey authored Nov 3, 2022
1 parent a433b35 commit 8a9bd35
Showing 1 changed file with 83 additions and 0 deletions.
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);
});
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);
});
});

0 comments on commit 8a9bd35

Please sign in to comment.