Date: Tue, 24 Aug 2021 17:06:33 -0500
Subject: [PATCH 08/85] Empty dependency array to avoid listener from being
re-added at each render
---
packages/components/src/confirm/component.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/components/src/confirm/component.tsx b/packages/components/src/confirm/component.tsx
index ebb4a801bde97..49bde17e74436 100644
--- a/packages/components/src/confirm/component.tsx
+++ b/packages/components/src/confirm/component.tsx
@@ -44,7 +44,7 @@ function Confirm(
document.addEventListener( 'keydown', handleEscapePress );
return () =>
document.removeEventListener( 'keydown', handleEscapePress );
- } );
+ }, [] );
return (
Date: Tue, 24 Aug 2021 17:06:59 -0500
Subject: [PATCH 09/85] Remove unused style
---
packages/components/src/confirm/styles.ts | 2 --
1 file changed, 2 deletions(-)
diff --git a/packages/components/src/confirm/styles.ts b/packages/components/src/confirm/styles.ts
index b7a389abefa65..c1ad06057e598 100644
--- a/packages/components/src/confirm/styles.ts
+++ b/packages/components/src/confirm/styles.ts
@@ -25,5 +25,3 @@ export const overlay = css`
z-index: -1;
background: rgba( 0, 0, 0, 0.5 );
`;
-
-export const dialogWrapper = css``;
From 18e0231d6b22d2b8dde1dfffb0b3e7cda2a33674 Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Tue, 24 Aug 2021 19:29:03 -0500
Subject: [PATCH 10/85] wip
---
packages/components/src/confirm/component.tsx | 76 +++++++------------
packages/components/src/confirm/hook.ts | 30 --------
packages/components/src/confirm/styles.ts | 23 +-----
.../higher-order/with-focus-outside/index.js | 2 +
packages/components/src/modal/aria-helper.js | 2 +
packages/components/src/modal/frame.js | 2 +
packages/components/src/modal/header.js | 2 +
packages/components/src/modal/index.js | 2 +
packages/components/tsconfig.json | 6 +-
9 files changed, 44 insertions(+), 101 deletions(-)
delete mode 100644 packages/components/src/confirm/hook.ts
diff --git a/packages/components/src/confirm/component.tsx b/packages/components/src/confirm/component.tsx
index 49bde17e74436..9520a37809f11 100644
--- a/packages/components/src/confirm/component.tsx
+++ b/packages/components/src/confirm/component.tsx
@@ -1,78 +1,58 @@
-// @ts-nocheck (for now)
+//@ts-nocheck (while we're using react-confirm)
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
-import { Ref, useEffect } from 'react';
import { confirmable } from 'react-confirm';
+import { __ } from '@wordpress/i18n';
+import { useMemo } from 'react';
/**
* Internal dependencies
*/
+import * as styles from './styles';
import Button from '../button';
+import Modal from '../modal';
import type { OwnProps } from './types';
-import { Card, CardHeader, CardFooter } from '../card';
-import { Heading } from '../heading';
-import { contextConnect, PolymorphicComponentProps } from '../ui/context';
+import {
+ useContextSystem,
+ contextConnect,
+ PolymorphicComponentProps,
+} from '../ui/context';
import { useConfirm } from './hook';
-import type { KeyboardEvent } from 'react';
+import { useCx } from '../utils/hooks/use-cx';
// @todo add type declarations for the react-confirm functions
function Confirm(
props: PolymorphicComponentProps< OwnProps, 'div', false >,
forwardedRef: Ref< any >
) {
- const {
- role,
- wrapperClassName,
- overlayClassName,
- show,
- proceed,
- confirmation,
- ...otherProps
- } = useConfirm( props );
+ const { show, proceed, role, ...otherProps } = useContextSystem(
+ props,
+ 'Confirm'
+ );
+ const cx = useCx();
- function handleEscapePress( event: KeyboardEvent< HTMLDivElement > ) {
- // `keyCode` is deprecated, so let's use `key`
- if ( event.key === 'Escape' ) {
- proceed( false );
- }
- }
+ const invisibleClassName = cx( ! show && styles.wrapperHidden );
- useEffect( () => {
- document.addEventListener( 'keydown', handleEscapePress );
- return () =>
- document.removeEventListener( 'keydown', handleEscapePress );
- }, [] );
+ console.log( show );
+ console.log( isVisible );
return (
-
event.preventDefault() }>
-
- { confirmation }
-
-
-
-
-
-
-
proceed( false ) }
- >
+
+
+
+
);
}
diff --git a/packages/components/src/confirm/hook.ts b/packages/components/src/confirm/hook.ts
deleted file mode 100644
index 05bb1004b4f81..0000000000000
--- a/packages/components/src/confirm/hook.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Internal dependencies
- */
-import { useContextSystem, PolymorphicComponentProps } from '../ui/context';
-
-/**
- * Internal dependencies
- */
-import * as styles from './styles';
-import { useCx } from '../utils/hooks/use-cx';
-import type { OwnProps } from './types';
-
-export function useConfirm(
- props: PolymorphicComponentProps< OwnProps, 'div' >
-) {
- const { className, ...otherProps } = useContextSystem( props, 'Confirm' );
-
- const cx = useCx();
-
- const classes = cx( className );
- const wrapperClassName = cx( styles.wrapper );
- const overlayClassName = cx( styles.overlay );
-
- return {
- className: classes,
- wrapperClassName,
- overlayClassName,
- ...otherProps,
- };
-}
diff --git a/packages/components/src/confirm/styles.ts b/packages/components/src/confirm/styles.ts
index c1ad06057e598..b34d4ea936013 100644
--- a/packages/components/src/confirm/styles.ts
+++ b/packages/components/src/confirm/styles.ts
@@ -3,25 +3,6 @@
*/
import { css } from '@emotion/react';
-export const wrapper = css`
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 9999999;
- display: flex;
- justify-content: center;
- -ms-align-items: center;
- align-items: center;
-`;
-
-export const overlay = css`
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: -1;
- background: rgba( 0, 0, 0, 0.5 );
+export const wrapperHidden = css`
+ visibility: hidden;
`;
diff --git a/packages/components/src/higher-order/with-focus-outside/index.js b/packages/components/src/higher-order/with-focus-outside/index.js
index c83de77f00906..41a7d9c9c3ea4 100644
--- a/packages/components/src/higher-order/with-focus-outside/index.js
+++ b/packages/components/src/higher-order/with-focus-outside/index.js
@@ -1,3 +1,5 @@
+//@ts-nocheck
+
/**
* WordPress dependencies
*/
diff --git a/packages/components/src/modal/aria-helper.js b/packages/components/src/modal/aria-helper.js
index 277293b337f46..aa6ecd01064ee 100644
--- a/packages/components/src/modal/aria-helper.js
+++ b/packages/components/src/modal/aria-helper.js
@@ -1,3 +1,5 @@
+//@ts-nocheck
+
/**
* External dependencies
*/
diff --git a/packages/components/src/modal/frame.js b/packages/components/src/modal/frame.js
index b563dff76c255..c38d776864e9a 100644
--- a/packages/components/src/modal/frame.js
+++ b/packages/components/src/modal/frame.js
@@ -1,3 +1,5 @@
+//@ts-nocheck
+
/**
* External dependencies
*/
diff --git a/packages/components/src/modal/header.js b/packages/components/src/modal/header.js
index 7fcc145b05484..ef05861a08ad1 100644
--- a/packages/components/src/modal/header.js
+++ b/packages/components/src/modal/header.js
@@ -1,3 +1,5 @@
+//@ts-nocheck
+
/**
* WordPress dependencies
*/
diff --git a/packages/components/src/modal/index.js b/packages/components/src/modal/index.js
index 2144972d42f18..e689b77171486 100644
--- a/packages/components/src/modal/index.js
+++ b/packages/components/src/modal/index.js
@@ -1,3 +1,5 @@
+//@ts-nocheck
+
/**
* WordPress dependencies
*/
diff --git a/packages/components/tsconfig.json b/packages/components/tsconfig.json
index e479cda0ce936..3c8f146acaff8 100644
--- a/packages/components/tsconfig.json
+++ b/packages/components/tsconfig.json
@@ -36,9 +36,11 @@
"src/grid/**/*",
"src/h-stack/**/*",
"src/heading/**/*",
- "src/item-group/**/*",
- "src/input-control/**/*",
+ "src/higher-order/with-focus-outside/**/*",
"src/icon/**/*",
+ "src/input-control/**/*",
+ "src/item-group/**/*",
+ "src/modal/**/*",
"src/number-control/**/*",
"src/popover/**/*",
"src/range-control/**/*",
From 2391e35044b6b542661c5cd83cce4dccdbf8ace1 Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Tue, 24 Aug 2021 20:22:36 -0500
Subject: [PATCH 11/85] Address code review suggestions partially, and refactor
to use the existing component
---
packages/components/src/confirm/component.tsx | 64 +++++++++++--------
.../components/src/confirm/stories/index.js | 6 +-
packages/components/src/confirm/styles.ts | 8 ---
packages/components/src/confirm/types.ts | 5 +-
.../src/components/post-visibility/index.js | 2 +-
5 files changed, 42 insertions(+), 43 deletions(-)
delete mode 100644 packages/components/src/confirm/styles.ts
diff --git a/packages/components/src/confirm/component.tsx b/packages/components/src/confirm/component.tsx
index 9520a37809f11..5872d2e33e1f6 100644
--- a/packages/components/src/confirm/component.tsx
+++ b/packages/components/src/confirm/component.tsx
@@ -5,13 +5,14 @@
*/
// eslint-disable-next-line no-restricted-imports
import { confirmable } from 'react-confirm';
+/**
+ * WordPress dependencies
+ */
import { __ } from '@wordpress/i18n';
-import { useMemo } from 'react';
/**
* Internal dependencies
*/
-import * as styles from './styles';
import Button from '../button';
import Modal from '../modal';
import type { OwnProps } from './types';
@@ -20,40 +21,47 @@ import {
contextConnect,
PolymorphicComponentProps,
} from '../ui/context';
-import { useConfirm } from './hook';
-import { useCx } from '../utils/hooks/use-cx';
+import { Flex } from '../flex';
// @todo add type declarations for the react-confirm functions
function Confirm(
props: PolymorphicComponentProps< OwnProps, 'div', false >,
forwardedRef: Ref< any >
) {
- const { show, proceed, role, ...otherProps } = useContextSystem(
- props,
- 'Confirm'
- );
- const cx = useCx();
-
- const invisibleClassName = cx( ! show && styles.wrapperHidden );
-
- console.log( show );
- console.log( isVisible );
+ const {
+ show: isOpen = true,
+ proceed,
+ role,
+ message,
+ ...otherProps
+ } = useContextSystem( props, 'Confirm' );
return (
-
-
-
-
-
-
+ <>
+ { isOpen && (
+
proceed( false ) }
+ { ...otherProps }
+ ref={ forwardedRef }
+ >
+
+
+
+
+
+ ) }
+ >
);
}
diff --git a/packages/components/src/confirm/stories/index.js b/packages/components/src/confirm/stories/index.js
index 0ecee6007cf4e..e0d63ffbaa431 100644
--- a/packages/components/src/confirm/stories/index.js
+++ b/packages/components/src/confirm/stories/index.js
@@ -19,10 +19,10 @@ export const _default = () => {
const [ confirmVal, setConfirmVal ] = useState();
async function triggerConfirm() {
- if ( await confirm( { confirmation: 'Are you sure?' } ) ) {
- setConfirmVal( 'You are sure!' );
+ if ( await confirm( { message: 'Are you sure?' } ) ) {
+ setConfirmVal( "Let's do it!" );
} else {
- setConfirmVal( 'Ok, take more time to decide!' );
+ setConfirmVal( 'Ok, take your time!' );
}
}
diff --git a/packages/components/src/confirm/styles.ts b/packages/components/src/confirm/styles.ts
deleted file mode 100644
index b34d4ea936013..0000000000000
--- a/packages/components/src/confirm/styles.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * External dependencies
- */
-import { css } from '@emotion/react';
-
-export const wrapperHidden = css`
- visibility: hidden;
-`;
diff --git a/packages/components/src/confirm/types.ts b/packages/components/src/confirm/types.ts
index f917d36434c55..69b0e9b283bee 100644
--- a/packages/components/src/confirm/types.ts
+++ b/packages/components/src/confirm/types.ts
@@ -2,9 +2,8 @@
* Internal dependencies
*/
-// TBD
export interface OwnProps {
show: boolean;
- proceed: Function;
- confirmation: string;
+ proceed: ( flag: boolean ) => void;
+ confirmation: React.ReactNode;
}
diff --git a/packages/editor/src/components/post-visibility/index.js b/packages/editor/src/components/post-visibility/index.js
index 52d71dae6a9c1..ac3fb2cfc9e4a 100644
--- a/packages/editor/src/components/post-visibility/index.js
+++ b/packages/editor/src/components/post-visibility/index.js
@@ -38,7 +38,7 @@ export class PostVisibility extends Component {
if (
// eslint-disable-next-line no-alert
! ( await confirm( {
- confirmation: __(
+ message: __(
'Would you like to privately publish this post now?'
),
} ) )
From a8788021ebd8a14f00316c841c42bcace818fdbd Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Wed, 25 Aug 2021 18:47:37 -0500
Subject: [PATCH 12/85] Improve component by allowing it to be used without the
`confirm` helper, remove dependency on `react-confirm`
---
packages/components/package.json | 2 +-
packages/components/src/confirm/component.tsx | 29 +++++----
packages/components/src/confirm/index.ts | 15 -----
packages/components/src/confirm/index.tsx | 59 +++++++++++++++++++
.../components/src/confirm/stories/index.js | 3 +-
packages/components/src/confirm/types.ts | 10 ++--
6 files changed, 87 insertions(+), 31 deletions(-)
delete mode 100644 packages/components/src/confirm/index.ts
create mode 100644 packages/components/src/confirm/index.tsx
diff --git a/packages/components/package.json b/packages/components/package.json
index 640e4d739f8e6..d37128ced84e0 100644
--- a/packages/components/package.json
+++ b/packages/components/package.json
@@ -60,8 +60,8 @@
"moment": "^2.22.1",
"re-resizable": "^6.4.0",
"react-colorful": "^5.3.0",
- "react-confirm": "0.1.24",
"react-dates": "^17.1.1",
+ "react-dom": "^16.14.0",
"react-resize-aware": "^3.1.0",
"react-use-gesture": "^9.0.0",
"reakit": "^1.3.8",
diff --git a/packages/components/src/confirm/component.tsx b/packages/components/src/confirm/component.tsx
index 5872d2e33e1f6..ea81a6444ad14 100644
--- a/packages/components/src/confirm/component.tsx
+++ b/packages/components/src/confirm/component.tsx
@@ -1,10 +1,10 @@
-//@ts-nocheck (while we're using react-confirm)
-
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
-import { confirmable } from 'react-confirm';
+import { useState } from 'react';
+// eslint-disable-next-line no-restricted-imports
+import type { Ref, MouseEvent } from 'react';
/**
* WordPress dependencies
*/
@@ -29,32 +29,41 @@ function Confirm(
forwardedRef: Ref< any >
) {
const {
- show: isOpen = true,
- proceed,
- role,
message,
+ onConfirm,
+ onCancel,
+ role,
...otherProps
} = useContextSystem( props, 'Confirm' );
+ const [ isOpen, setIsOpen ] = useState( true );
+
+ const closeAndHandle = (
+ callback: ( event: MouseEvent< HTMLButtonElement > ) => void
+ ) => ( event: MouseEvent< HTMLButtonElement > ) => {
+ setIsOpen( false );
+ callback( event );
+ };
+
return (
<>
{ isOpen && (
proceed( false ) }
+ onRequestClose={ closeAndHandle( onCancel ) }
{ ...otherProps }
ref={ forwardedRef }
>
@@ -65,4 +74,4 @@ function Confirm(
);
}
-export default confirmable( contextConnect( Confirm, 'Confirm' ) );
+export default contextConnect( Confirm, 'Confirm' );
diff --git a/packages/components/src/confirm/index.ts b/packages/components/src/confirm/index.ts
deleted file mode 100644
index 51bfc98fc1b4d..0000000000000
--- a/packages/components/src/confirm/index.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-//@ts-nocheck
-
-/**
- * External dependencies
- */
-import { createConfirmation } from 'react-confirm';
-
-/**
- * Internal dependencies
- */
-import Confirm from './component';
-
-const confirm = createConfirmation( Confirm );
-
-export { Confirm, confirm };
diff --git a/packages/components/src/confirm/index.tsx b/packages/components/src/confirm/index.tsx
new file mode 100644
index 0000000000000..3a9ea16d81e0d
--- /dev/null
+++ b/packages/components/src/confirm/index.tsx
@@ -0,0 +1,59 @@
+//@ts-nocheck
+
+/**
+ * External dependencies
+ */
+import ReactDOM from 'react-dom';
+
+/**
+ * Internal dependencies
+ */
+import Confirm from './component';
+
+/**
+ * Helper function that turns the Confirm component into a self-contained
+ * confirm dialog, callable from outside an existing React tree, mimicking
+ * the native `confirm` API.
+ *
+ * @param message the confirm message
+ * @return Promise
+ */
+const confirm = ( message: string ) => {
+ const wrapper = document.body.appendChild(
+ document.createElement( 'div' )
+ );
+
+ const dispose = () => {
+ setTimeout( () => {
+ ReactDOM.unmountComponentAtNode( wrapper );
+ setTimeout( () => {
+ if ( document.body.contains( wrapper ) ) {
+ document.body.removeChild( wrapper );
+ }
+ } );
+ }, 1000 );
+ };
+
+ return new Promise( ( resolve ) => {
+ const confirmHandler = ( _ ) => resolve( true );
+ const cancelHandler = ( _ ) => resolve( false );
+
+ try {
+ ReactDOM.render(
+ ,
+ wrapper
+ );
+ } catch ( e ) {
+ throw e;
+ }
+ } ).then( ( result: boolean ) => {
+ dispose();
+ return result;
+ } );
+};
+
+export { Confirm, confirm };
diff --git a/packages/components/src/confirm/stories/index.js b/packages/components/src/confirm/stories/index.js
index e0d63ffbaa431..a091814daa29a 100644
--- a/packages/components/src/confirm/stories/index.js
+++ b/packages/components/src/confirm/stories/index.js
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
+// eslint-disable-next-line no-restricted-imports
import React, { useState } from 'react';
/**
@@ -19,7 +20,7 @@ export const _default = () => {
const [ confirmVal, setConfirmVal ] = useState();
async function triggerConfirm() {
- if ( await confirm( { message: 'Are you sure?' } ) ) {
+ if ( await confirm( 'Are you sure?' ) ) {
setConfirmVal( "Let's do it!" );
} else {
setConfirmVal( 'Ok, take your time!' );
diff --git a/packages/components/src/confirm/types.ts b/packages/components/src/confirm/types.ts
index 69b0e9b283bee..41048d633818f 100644
--- a/packages/components/src/confirm/types.ts
+++ b/packages/components/src/confirm/types.ts
@@ -1,9 +1,11 @@
/**
- * Internal dependencies
+ * External dependencies
*/
+// eslint-disable-next-line no-restricted-imports
+import type { MouseEvent } from 'react';
export interface OwnProps {
- show: boolean;
- proceed: ( flag: boolean ) => void;
- confirmation: React.ReactNode;
+ message: string;
+ onConfirm: ( event: MouseEvent< HTMLButtonElement > ) => void;
+ onCancel: ( event: MouseEvent< HTMLButtonElement > ) => void;
}
From b09651b5e4f1d7747bc4fa1af18230b0df8674e6 Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Wed, 25 Aug 2021 19:54:20 -0500
Subject: [PATCH 13/85] Update README
---
packages/components/src/confirm/README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/packages/components/src/confirm/README.md b/packages/components/src/confirm/README.md
index 3586c12eeb86e..07fe55bc119f6 100644
--- a/packages/components/src/confirm/README.md
+++ b/packages/components/src/confirm/README.md
@@ -1,3 +1,7 @@
# `Confirm`
+
+This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
+
+
TBD
From c221e9d91823ee102f527a9e6d352f7227837663 Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Wed, 25 Aug 2021 20:14:46 -0500
Subject: [PATCH 14/85] Update confirm call in post-visibility
---
packages/editor/src/components/post-visibility/index.js | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/packages/editor/src/components/post-visibility/index.js b/packages/editor/src/components/post-visibility/index.js
index ac3fb2cfc9e4a..a12cfeb0b40cb 100644
--- a/packages/editor/src/components/post-visibility/index.js
+++ b/packages/editor/src/components/post-visibility/index.js
@@ -37,11 +37,9 @@ export class PostVisibility extends Component {
async setPrivate() {
if (
// eslint-disable-next-line no-alert
- ! ( await confirm( {
- message: __(
- 'Would you like to privately publish this post now?'
- ),
- } ) )
+ ! ( await confirm(
+ __( 'Would you like to privately publish this post now?' )
+ ) )
) {
return;
}
From cac2732fde5a25c97e5234ff9fe900fdf4c746fd Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Wed, 25 Aug 2021 20:19:25 -0500
Subject: [PATCH 15/85] Remove role prop as it is not explicitely used at the
moment
---
packages/components/src/confirm/component.tsx | 1 -
1 file changed, 1 deletion(-)
diff --git a/packages/components/src/confirm/component.tsx b/packages/components/src/confirm/component.tsx
index ea81a6444ad14..49b579eda3ce0 100644
--- a/packages/components/src/confirm/component.tsx
+++ b/packages/components/src/confirm/component.tsx
@@ -32,7 +32,6 @@ function Confirm(
message,
onConfirm,
onCancel,
- role,
...otherProps
} = useContextSystem( props, 'Confirm' );
From 09427074bd0cd2c76373383c4ad6a0649288a7a8 Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Wed, 25 Aug 2021 21:29:23 -0500
Subject: [PATCH 16/85] Add basic tests
---
.../confirm/test/__snapshots__/index.js.snap | 441 ++++++++++++++++++
packages/components/src/confirm/test/index.js | 84 ++++
2 files changed, 525 insertions(+)
create mode 100644 packages/components/src/confirm/test/__snapshots__/index.js.snap
diff --git a/packages/components/src/confirm/test/__snapshots__/index.js.snap b/packages/components/src/confirm/test/__snapshots__/index.js.snap
new file mode 100644
index 0000000000000..d565e49fbe79e
--- /dev/null
+++ b/packages/components/src/confirm/test/__snapshots__/index.js.snap
@@ -0,0 +1,441 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Confirm Confirm component should not render if closed by clicking OK 1`] = `
+Object {
+ "asFragment": [Function],
+ "baseElement":
+
+
+ ,
+ "container": ,
+ "debug": [Function],
+ "findAllByAltText": [Function],
+ "findAllByDisplayValue": [Function],
+ "findAllByLabelText": [Function],
+ "findAllByPlaceholderText": [Function],
+ "findAllByRole": [Function],
+ "findAllByTestId": [Function],
+ "findAllByText": [Function],
+ "findAllByTitle": [Function],
+ "findByAltText": [Function],
+ "findByDisplayValue": [Function],
+ "findByLabelText": [Function],
+ "findByPlaceholderText": [Function],
+ "findByRole": [Function],
+ "findByTestId": [Function],
+ "findByText": [Function],
+ "findByTitle": [Function],
+ "getAllByAltText": [Function],
+ "getAllByDisplayValue": [Function],
+ "getAllByLabelText": [Function],
+ "getAllByPlaceholderText": [Function],
+ "getAllByRole": [Function],
+ "getAllByTestId": [Function],
+ "getAllByText": [Function],
+ "getAllByTitle": [Function],
+ "getByAltText": [Function],
+ "getByDisplayValue": [Function],
+ "getByLabelText": [Function],
+ "getByPlaceholderText": [Function],
+ "getByRole": [Function],
+ "getByTestId": [Function],
+ "getByText": [Function],
+ "getByTitle": [Function],
+ "queryAllByAltText": [Function],
+ "queryAllByDisplayValue": [Function],
+ "queryAllByLabelText": [Function],
+ "queryAllByPlaceholderText": [Function],
+ "queryAllByRole": [Function],
+ "queryAllByTestId": [Function],
+ "queryAllByText": [Function],
+ "queryAllByTitle": [Function],
+ "queryByAltText": [Function],
+ "queryByDisplayValue": [Function],
+ "queryByLabelText": [Function],
+ "queryByPlaceholderText": [Function],
+ "queryByRole": [Function],
+ "queryByTestId": [Function],
+ "queryByText": [Function],
+ "queryByTitle": [Function],
+ "rerender": [Function],
+ "unmount": [Function],
+}
+`;
+
+exports[`Confirm Confirm component should not render if closed by clicking cancel 1`] = `
+Object {
+ "asFragment": [Function],
+ "baseElement":
+
+
+ ,
+ "container": ,
+ "debug": [Function],
+ "findAllByAltText": [Function],
+ "findAllByDisplayValue": [Function],
+ "findAllByLabelText": [Function],
+ "findAllByPlaceholderText": [Function],
+ "findAllByRole": [Function],
+ "findAllByTestId": [Function],
+ "findAllByText": [Function],
+ "findAllByTitle": [Function],
+ "findByAltText": [Function],
+ "findByDisplayValue": [Function],
+ "findByLabelText": [Function],
+ "findByPlaceholderText": [Function],
+ "findByRole": [Function],
+ "findByTestId": [Function],
+ "findByText": [Function],
+ "findByTitle": [Function],
+ "getAllByAltText": [Function],
+ "getAllByDisplayValue": [Function],
+ "getAllByLabelText": [Function],
+ "getAllByPlaceholderText": [Function],
+ "getAllByRole": [Function],
+ "getAllByTestId": [Function],
+ "getAllByText": [Function],
+ "getAllByTitle": [Function],
+ "getByAltText": [Function],
+ "getByDisplayValue": [Function],
+ "getByLabelText": [Function],
+ "getByPlaceholderText": [Function],
+ "getByRole": [Function],
+ "getByTestId": [Function],
+ "getByText": [Function],
+ "getByTitle": [Function],
+ "queryAllByAltText": [Function],
+ "queryAllByDisplayValue": [Function],
+ "queryAllByLabelText": [Function],
+ "queryAllByPlaceholderText": [Function],
+ "queryAllByRole": [Function],
+ "queryAllByTestId": [Function],
+ "queryAllByText": [Function],
+ "queryAllByTitle": [Function],
+ "queryByAltText": [Function],
+ "queryByDisplayValue": [Function],
+ "queryByLabelText": [Function],
+ "queryByPlaceholderText": [Function],
+ "queryByRole": [Function],
+ "queryByTestId": [Function],
+ "queryByText": [Function],
+ "queryByTitle": [Function],
+ "rerender": [Function],
+ "unmount": [Function],
+}
+`;
+
+exports[`Confirm Confirm component should not render if dialog is closed by clicking the \`x\` button 1`] = `
+Object {
+ "asFragment": [Function],
+ "baseElement":
+
+
+ ,
+ "container": ,
+ "debug": [Function],
+ "findAllByAltText": [Function],
+ "findAllByDisplayValue": [Function],
+ "findAllByLabelText": [Function],
+ "findAllByPlaceholderText": [Function],
+ "findAllByRole": [Function],
+ "findAllByTestId": [Function],
+ "findAllByText": [Function],
+ "findAllByTitle": [Function],
+ "findByAltText": [Function],
+ "findByDisplayValue": [Function],
+ "findByLabelText": [Function],
+ "findByPlaceholderText": [Function],
+ "findByRole": [Function],
+ "findByTestId": [Function],
+ "findByText": [Function],
+ "findByTitle": [Function],
+ "getAllByAltText": [Function],
+ "getAllByDisplayValue": [Function],
+ "getAllByLabelText": [Function],
+ "getAllByPlaceholderText": [Function],
+ "getAllByRole": [Function],
+ "getAllByTestId": [Function],
+ "getAllByText": [Function],
+ "getAllByTitle": [Function],
+ "getByAltText": [Function],
+ "getByDisplayValue": [Function],
+ "getByLabelText": [Function],
+ "getByPlaceholderText": [Function],
+ "getByRole": [Function],
+ "getByTestId": [Function],
+ "getByText": [Function],
+ "getByTitle": [Function],
+ "queryAllByAltText": [Function],
+ "queryAllByDisplayValue": [Function],
+ "queryAllByLabelText": [Function],
+ "queryAllByPlaceholderText": [Function],
+ "queryAllByRole": [Function],
+ "queryAllByTestId": [Function],
+ "queryAllByText": [Function],
+ "queryAllByTitle": [Function],
+ "queryByAltText": [Function],
+ "queryByDisplayValue": [Function],
+ "queryByLabelText": [Function],
+ "queryByPlaceholderText": [Function],
+ "queryByRole": [Function],
+ "queryByTestId": [Function],
+ "queryByText": [Function],
+ "queryByTitle": [Function],
+ "rerender": [Function],
+ "unmount": [Function],
+}
+`;
+
+exports[`Confirm Confirm component should not render if dialog is closed by clicking the overlay 1`] = `
+.emotion-0 {
+ display: -webkit-box;
+ display: -webkit-flex;
+ display: -ms-flexbox;
+ display: flex;
+ -webkit-align-items: center;
+ -webkit-box-align: center;
+ -ms-flex-align: center;
+ align-items: center;
+ -webkit-flex-direction: row;
+ -ms-flex-direction: row;
+ flex-direction: row;
+ -webkit-box-pack: end;
+ -ms-flex-pack: end;
+ -webkit-justify-content: flex-end;
+ justify-content: flex-end;
+ width: 100%;
+}
+
+.emotion-0>*+*:not( marquee ) {
+ margin-left: calc(4px * 2);
+}
+
+.emotion-0>* {
+ min-width: 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+`;
+
+exports[`Confirm Confirm component should render correctly 1`] = `
+Object {
+ "asFragment": [Function],
+ "baseElement": .emotion-0 {
+ display: -webkit-box;
+ display: -webkit-flex;
+ display: -ms-flexbox;
+ display: flex;
+ -webkit-align-items: center;
+ -webkit-box-align: center;
+ -ms-flex-align: center;
+ align-items: center;
+ -webkit-flex-direction: row;
+ -ms-flex-direction: row;
+ flex-direction: row;
+ -webkit-box-pack: end;
+ -ms-flex-pack: end;
+ -webkit-justify-content: flex-end;
+ justify-content: flex-end;
+ width: 100%;
+}
+
+.emotion-0>*+*:not( marquee ) {
+ margin-left: calc(4px * 2);
+}
+
+.emotion-0>* {
+ min-width: 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ,
+ "container": ,
+ "debug": [Function],
+ "findAllByAltText": [Function],
+ "findAllByDisplayValue": [Function],
+ "findAllByLabelText": [Function],
+ "findAllByPlaceholderText": [Function],
+ "findAllByRole": [Function],
+ "findAllByTestId": [Function],
+ "findAllByText": [Function],
+ "findAllByTitle": [Function],
+ "findByAltText": [Function],
+ "findByDisplayValue": [Function],
+ "findByLabelText": [Function],
+ "findByPlaceholderText": [Function],
+ "findByRole": [Function],
+ "findByTestId": [Function],
+ "findByText": [Function],
+ "findByTitle": [Function],
+ "getAllByAltText": [Function],
+ "getAllByDisplayValue": [Function],
+ "getAllByLabelText": [Function],
+ "getAllByPlaceholderText": [Function],
+ "getAllByRole": [Function],
+ "getAllByTestId": [Function],
+ "getAllByText": [Function],
+ "getAllByTitle": [Function],
+ "getByAltText": [Function],
+ "getByDisplayValue": [Function],
+ "getByLabelText": [Function],
+ "getByPlaceholderText": [Function],
+ "getByRole": [Function],
+ "getByTestId": [Function],
+ "getByText": [Function],
+ "getByTitle": [Function],
+ "queryAllByAltText": [Function],
+ "queryAllByDisplayValue": [Function],
+ "queryAllByLabelText": [Function],
+ "queryAllByPlaceholderText": [Function],
+ "queryAllByRole": [Function],
+ "queryAllByTestId": [Function],
+ "queryAllByText": [Function],
+ "queryAllByTitle": [Function],
+ "queryByAltText": [Function],
+ "queryByDisplayValue": [Function],
+ "queryByLabelText": [Function],
+ "queryByPlaceholderText": [Function],
+ "queryByRole": [Function],
+ "queryByTestId": [Function],
+ "queryByText": [Function],
+ "queryByTitle": [Function],
+ "rerender": [Function],
+ "unmount": [Function],
+}
+`;
diff --git a/packages/components/src/confirm/test/index.js b/packages/components/src/confirm/test/index.js
index 954ddd236b585..c93449892bc47 100644
--- a/packages/components/src/confirm/test/index.js
+++ b/packages/components/src/confirm/test/index.js
@@ -1 +1,85 @@
// TBD
+
+/**
+ * External dependencies
+ */
+import { render, fireEvent } from '@testing-library/react';
+
+/**
+ * Internal dependencies
+ */
+import { Confirm } from '..';
+
+const noop = () => {};
+
+describe( 'Confirm', () => {
+ describe( 'Confirm component', () => {
+ it( 'should render correctly', () => {
+ const wrapper = render(
+
+ );
+
+ expect( wrapper ).toMatchSnapshot();
+ } );
+
+ it( 'should not render if closed by clicking OK', async () => {
+ const wrapper = render(
+
+ );
+
+ const button = await wrapper.findByText( 'OK' );
+
+ fireEvent.click( button );
+
+ expect( wrapper ).toMatchSnapshot();
+ } );
+
+ it( 'should not render if closed by clicking cancel', async () => {
+ const wrapper = render(
+
+ );
+
+ const button = await wrapper.findByText( 'Cancel' );
+
+ fireEvent.click( button );
+
+ expect( wrapper ).toMatchSnapshot();
+ } );
+
+ it( 'should not render if dialog is closed by clicking the `x` button', async () => {
+ const wrapper = render(
+
+ );
+
+ const button = await wrapper.findByLabelText( 'Close dialog' );
+
+ fireEvent.click( button );
+
+ expect( wrapper ).toMatchSnapshot();
+ } );
+
+ it( 'should not render if dialog is closed by clicking the overlay', async () => {
+ const wrapper = render(
+
+ );
+
+ const overlay = wrapper.baseElement.querySelector(
+ '.components-modal__screen-overlay'
+ );
+
+ fireEvent.click( overlay );
+
+ expect( overlay ).toMatchSnapshot();
+ } );
+
+ it.skip( 'should call the confirm callback upon confirming', () => {} );
+ it.skip( 'should call the cancel callback upon confirming', () => {} );
+ } );
+
+ /**
+ * Confirm provides a `confirm` helper function that provides an interface
+ * that's closer to the default native `confirm`, returning a boolean and
+ * that can called outside of the component's render function.
+ */
+ describe( 'Self-contained rendering using `confirm`', () => {} );
+} );
From 7d629b828507320019752b88f86041b5f2d02c6c Mon Sep 17 00:00:00 2001
From: Marcelo Serpa <81248+fullofcaffeine@users.noreply.github.com>
Date: Thu, 26 Aug 2021 20:58:01 -0500
Subject: [PATCH 17/85] Test that the Confirm closes when clicking the overlay
---
.../confirm/test/__snapshots__/index.js.snap | 145 ++++++++----------
packages/components/src/confirm/test/index.js | 17 +-
2 files changed, 71 insertions(+), 91 deletions(-)
diff --git a/packages/components/src/confirm/test/__snapshots__/index.js.snap b/packages/components/src/confirm/test/__snapshots__/index.js.snap
index d565e49fbe79e..48baee7132bf3 100644
--- a/packages/components/src/confirm/test/__snapshots__/index.js.snap
+++ b/packages/components/src/confirm/test/__snapshots__/index.js.snap
@@ -193,92 +193,67 @@ Object {
`;
exports[`Confirm Confirm component should not render if dialog is closed by clicking the overlay 1`] = `
-.emotion-0 {
- display: -webkit-box;
- display: -webkit-flex;
- display: -ms-flexbox;
- display: flex;
- -webkit-align-items: center;
- -webkit-box-align: center;
- -ms-flex-align: center;
- align-items: center;
- -webkit-flex-direction: row;
- -ms-flex-direction: row;
- flex-direction: row;
- -webkit-box-pack: end;
- -ms-flex-pack: end;
- -webkit-justify-content: flex-end;
- justify-content: flex-end;
- width: 100%;
-}
-
-.emotion-0>*+*:not( marquee ) {
- margin-left: calc(4px * 2);
-}
-
-.emotion-0>* {
- min-width: 0;
-}
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+