+`;
diff --git a/components/lib/progressbar/ProgressBar.spec.js b/components/lib/progressbar/ProgressBar.spec.js
index 2f5cc8130c..6f47801d80 100644
--- a/components/lib/progressbar/ProgressBar.spec.js
+++ b/components/lib/progressbar/ProgressBar.spec.js
@@ -1,5 +1,4 @@
import '@testing-library/jest-dom';
-import { render } from '@testing-library/react';
import { snapshot } from '../../test';
import { ProgressBar } from './ProgressBar';
@@ -10,11 +9,4 @@ describe('ProgressBar', () => {
snapshot(, 'value with unit');
snapshot(, 'mode determinate');
snapshot(, 'mode indeterminate');
- test('when mode is invalid throws exception', () => {
- try {
- const { container } = render();
- } catch (error) {
- expect(error.toString().startsWith("Error: invalid is not a valid mode for the ProgressBar. Valid values are 'determinate' and 'indeterminate'")).toBeTruthy();
- }
- });
});
diff --git a/components/lib/ripple/Ripple.spec.js b/components/lib/ripple/Ripple.spec.js
new file mode 100644
index 0000000000..801919f4af
--- /dev/null
+++ b/components/lib/ripple/Ripple.spec.js
@@ -0,0 +1,38 @@
+import '@testing-library/jest-dom';
+import { fireEvent, render } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { userAgent } from '../../test';
+import PrimeReact from '../api/PrimeReact';
+import { Button } from '../button/Button';
+
+describe('Ripple', () => {
+ test('when Ripple is enabled, button should have ripple effect on desktop device', async () => {
+ // Arrange
+ userAgent('Chrome');
+ PrimeReact.ripple = true;
+ const { container } = render();
+ const button = container.getElementsByClassName('p-button')[0];
+
+ // Act
+ await userEvent.click(button);
+
+ // Assert
+ expect(button).toBeEnabled();
+ expect(container).toMatchSnapshot();
+ });
+
+ test('when Ripple is enabled, button should have ripple effect on touch device', async () => {
+ // Arrange
+ userAgent('iPhone');
+ PrimeReact.ripple = true;
+ const { container } = render();
+ const button = container.getElementsByClassName('p-button')[0];
+
+ // Act
+ fireEvent.touchStart(button, { targetTouches: [{ pageX: '50', pageY: '50' }] });
+
+ // Assert
+ expect(button).toBeEnabled();
+ expect(container).toMatchSnapshot();
+ });
+});
diff --git a/components/lib/ripple/__snapshots__/Ripple.spec.js.snap b/components/lib/ripple/__snapshots__/Ripple.spec.js.snap
new file mode 100644
index 0000000000..bcf5a4abe4
--- /dev/null
+++ b/components/lib/ripple/__snapshots__/Ripple.spec.js.snap
@@ -0,0 +1,39 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Ripple when Ripple is enabled, button should have ripple effect on desktop device 1`] = `
+
+
+
+`;
+
+exports[`Ripple when Ripple is enabled, button should have ripple effect on touch device 1`] = `
+
+
+
+`;
diff --git a/components/test/index.js b/components/test/index.js
index a207cee63f..8e510b24ef 100644
--- a/components/test/index.js
+++ b/components/test/index.js
@@ -1,8 +1,56 @@
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
+// Set the userAgent inside the navigator
+Object.defineProperty(
+ window.navigator,
+ 'userAgent',
+ ((value) => ({
+ get() {
+ return value;
+ },
+ set(v) {
+ value = v;
+ }
+ }))(window.navigator.userAgent)
+);
+
+// Set the maxTouchPoints inside the navigator for touch devices
+Object.defineProperty(
+ window.navigator,
+ 'maxTouchPoints',
+ ((value) => ({
+ get() {
+ return value;
+ },
+ set(v) {
+ value = v;
+ }
+ }))(window.navigator.maxTouchPoints)
+);
+
+/**
+ * Run a single snapshot test.
+ *
+ * @param {*} element the element to render
+ * @param {*} name the name of the test
+ */
export function snapshot(element, name) {
test(name, () => {
expect(render(element).container).toMatchSnapshot();
});
}
+
+/**
+ * Sets the browser user agent so it can simulate browsers. If its IOS adds touch setting to allow DomUtils.isTouchDevice.
+ *
+ * @param {*} name the name of the user agent.
+ */
+export function userAgent(name) {
+ // Set the userAgent that you wanna test on your function
+ global.navigator.userAgent = name;
+
+ if (name.match(/iPhone|iPad|iPod/i)) {
+ global.navigator.maxTouchPoints = 2;
+ }
+}