diff --git a/components/doc/rating/templatedoc.js b/components/doc/rating/templatedoc.js index cb3ffd1be2..cb636309c8 100644 --- a/components/doc/rating/templatedoc.js +++ b/components/doc/rating/templatedoc.js @@ -11,49 +11,30 @@ export function TemplateDoc(props) { const code = { basic: ` setVal(e.val)} -cancelIcon={ - (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-cancel-image" width="25px" height="25px" /> -} -onIcon={ - (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} -alt="custom-image-active" -width="25px" -height="25px" - /> -} -offIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image" width="25px" height="25px" />} - /> + value={val} + onChange={(e) => setVal(e.value)} + cancelIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-cancel-image" width="25px" height="25px" />} + onIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image-active" width="25px" height="25px" />} + offIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image" width="25px" height="25px" />} +/> `, javascript: ` import { useState } from "react"; import { Rating } from "primereact/rating"; -const [val, setVal] = useState(null); - export default function TemplateDoc() { + const [val, setVal] = useState(null); return ( - setVal(e.val)} -cancelIcon={ - (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-cancel-image" width="25px" height="25px" /> -} -onIcon={ - (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} -alt="custom-image-active" -width="25px" -height="25px" - /> -} -offIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image" width="25px" height="25px" />} - /> + setVal(e.value)} + cancelIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-cancel-image" width="25px" height="25px" />} + onIcon={ + (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image-active" width="25px" height="25px" /> + } + offIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image" width="25px" height="25px" />} + /> ); } `, @@ -61,28 +42,19 @@ offIcon={(0); - export default function TemplateDoc() { + const [val, setVal] = useState(0); return ( - setVal(e.val)} -cancelIcon={ - (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-cancel-image" width="25px" height="25px" /> -} -onIcon={ - (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} -alt="custom-image-active" -width="25px" -height="25px" - /> -} -offIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image" width="25px" height="25px" />} - /> + setVal(e.value)} + cancelIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-cancel-image" width="25px" height="25px" />} + onIcon={ + (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image-active" width="25px" height="25px" /> + } + offIcon={ (e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png')} alt="custom-image" width="25px" height="25px" />} + /> ); } ` diff --git a/components/lib/blockui/BlockUI.spec.js b/components/lib/blockui/BlockUI.spec.js new file mode 100644 index 0000000000..5df296fe68 --- /dev/null +++ b/components/lib/blockui/BlockUI.spec.js @@ -0,0 +1,69 @@ +import '@testing-library/jest-dom'; +import { act, render } from '@testing-library/react'; +import * as React from 'react'; +import { snapshotParent } from '../../test'; +import { Panel } from '../panel/Panel'; +import { BlockUI } from './BlockUI'; + +describe('BlockUI', () => { + snapshotParent(, 'block fullscreen'); + snapshotParent( + + blocked + , + 'block panel' + ); + snapshotParent( + + unblocked + , + 'unblock panel' + ); + test('block and unblock panel events', async () => { + // Arrange + const ref = React.createRef(); + const { container } = render( + + unblocked + + ); + + // Act + act(() => { + ref.current.block(); + ref.current.getElement(); + }); + + // Assert + expect(container).toMatchSnapshot('blocked-event'); + + // Act + act(() => { + ref.current.unblock(); + }); + + // Assert + expect(container).toMatchSnapshot('unblocked-event'); + }); + test('block and unblock fullscreen events', async () => { + // Arrange + const ref = React.createRef(); + const { container } = render(); + + // Act + act(() => { + ref.current.block(); + }); + + // Assert + expect(container.parentElement).toMatchSnapshot('blocked-event-fullscreen'); + + // Act + act(() => { + ref.current.unblock(); + }); + + // Assert + expect(container.parentElement).toMatchSnapshot('unblocked-event-fullscreen'); + }); +}); diff --git a/components/lib/blockui/__snapshots__/BlockUI.spec.js.snap b/components/lib/blockui/__snapshots__/BlockUI.spec.js.snap new file mode 100644 index 0000000000..a311c73818 --- /dev/null +++ b/components/lib/blockui/__snapshots__/BlockUI.spec.js.snap @@ -0,0 +1,173 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BlockUI block and unblock fullscreen events: blocked-event-fullscreen 1`] = ` + +
+
+
+
+ +`; + +exports[`BlockUI block and unblock fullscreen events: unblocked-event-fullscreen 1`] = ` + +
+
+
+
+ +`; + +exports[`BlockUI block and unblock panel events: blocked-event 1`] = ` +
+
+
+
+
+ unblocked +
+
+
+
+
+
+`; + +exports[`BlockUI block and unblock panel events: unblocked-event 1`] = ` +
+
+
+
+
+ unblocked +
+
+
+
+
+
+`; + +exports[`BlockUI block fullscreen 1`] = ` + +
+
+
+
+ +`; + +exports[`BlockUI block panel 1`] = ` + +
+
+
+
+
+ blocked +
+
+
+
+
+
+ +`; + +exports[`BlockUI unblock panel 1`] = ` + +
+
+
+
+
+ unblocked +
+
+
+
+
+ +`; diff --git a/components/test/index.js b/components/test/index.js index 8e510b24ef..829bbfbfef 100644 --- a/components/test/index.js +++ b/components/test/index.js @@ -41,6 +41,18 @@ export function snapshot(element, name) { }); } +/** + * Run a single snapshot test of the parent element. + * + * @param {*} element the element to render + * @param {*} name the name of the test + */ +export function snapshotParent(element, name) { + test(name, () => { + expect(render(element).container.parentElement).toMatchSnapshot(); + }); +} + /** * Sets the browser user agent so it can simulate browsers. If its IOS adds touch setting to allow DomUtils.isTouchDevice. *