From 8a9bd35ef6d018ad921df8b985f403dca23cc5f8 Mon Sep 17 00:00:00 2001
From: Bugra <71140097+habubey@users.noreply.github.com>
Date: Thu, 3 Nov 2022 18:21:41 +0300
Subject: [PATCH] Fix #3567: Add jest unit testing to Badge component (#3568)
* Add jest unit testing to Badge component
* Improve Badge component unit tests
---
components/lib/badge/Badge.spec.js | 83 ++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 components/lib/badge/Badge.spec.js
diff --git a/components/lib/badge/Badge.spec.js b/components/lib/badge/Badge.spec.js
new file mode 100644
index 0000000000..2986b9991c
--- /dev/null
+++ b/components/lib/badge/Badge.spec.js
@@ -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();
+
+ // Act + Assert
+ expect(container.getElementsByClassName('p-badge-dot').length).toBe(1);
+ });
+
+ test('when value is property it returns with class', () => {
+ // Arrange
+ const { container } = render();
+ 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();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+
+ // 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();
+
+ // Act + Assert
+ expect(container.getElementsByClassName('p-badge p-component p-badge-invalid').length).toBe(1);
+ });
+});