diff --git a/components/lib/button/Button.spec.js b/components/lib/button/Button.spec.js index 4f57fd9bee..40818ed17f 100644 --- a/components/lib/button/Button.spec.js +++ b/components/lib/button/Button.spec.js @@ -1,5 +1,6 @@ import '@testing-library/jest-dom'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { snapshot } from '../../test'; import PrimeReact from '../api/PrimeReact'; import { Button } from './Button'; @@ -44,33 +45,33 @@ describe('Button', () => { expect(screen.queryByText(tooltipText)).toBeNull(); }); - test('when button is clicked ensure onClick is fired', () => { + test('when button is clicked ensure onClick is fired', async () => { // Arrange const clickOn = jest.fn(); const { container } = render( diff --git a/components/lib/message/Message.spec.js b/components/lib/message/Message.spec.js new file mode 100644 index 0000000000..2b35f634a3 --- /dev/null +++ b/components/lib/message/Message.spec.js @@ -0,0 +1,20 @@ +import '@testing-library/jest-dom'; +import { Message } from './Message'; + +import { snapshot } from '../../test'; + +describe('Message', () => { + snapshot(, 'default'); + snapshot(, 'severity success'); + snapshot(, 'severity info'); + snapshot(, 'severity warn'); + snapshot(, 'severity error'); + snapshot(, 'icon'); + snapshot(Test} />, 'content'); + snapshot( + + Jester + , + 'templating' + ); +}); diff --git a/components/lib/message/__snapshots__/Message.spec.js.snap b/components/lib/message/__snapshots__/Message.spec.js.snap new file mode 100644 index 0000000000..10b26674e9 --- /dev/null +++ b/components/lib/message/__snapshots__/Message.spec.js.snap @@ -0,0 +1,142 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Message content 1`] = ` +
+ +
+`; + +exports[`Message default 1`] = ` +
+ +
+`; + +exports[`Message icon 1`] = ` +
+ +
+`; + +exports[`Message severity error 1`] = ` +
+ +
+`; + +exports[`Message severity info 1`] = ` +
+ +
+`; + +exports[`Message severity success 1`] = ` +
+ +
+`; + +exports[`Message severity warn 1`] = ` +
+ +
+`; + +exports[`Message templating 1`] = ` +
+ +
+`; 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( + +`; + +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; + } +}