-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
970217e
commit 84ac583
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useDropZone from '../'; | ||
|
||
describe( 'useDropZone', () => { | ||
const ComponentWithWrapperDropZone = () => { | ||
const outerRef = useRef(); | ||
const dropZoneRef = useDropZone( { | ||
dropZoneRef: outerRef, | ||
} ); | ||
|
||
return ( | ||
<div role="main" ref={ outerRef }> | ||
<div role="region" ref={ dropZoneRef }> | ||
<div>Drop Zone</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const ComponentWithoutWrapperDropZone = () => { | ||
const dropZoneRef = useDropZone( {} ); | ||
|
||
return ( | ||
<div role="main"> | ||
<div role="region" ref={ dropZoneRef }> | ||
<div>Drop Zone</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
it( 'will attach dropzone to outer wrapper', () => { | ||
const { rerender } = render( <ComponentWithWrapperDropZone /> ); | ||
// Ensure `useEffect` has run. | ||
rerender( <ComponentWithWrapperDropZone /> ); | ||
|
||
expect( screen.getByRole( 'main' ) ).toHaveAttribute( | ||
'data-is-drop-zone' | ||
); | ||
} ); | ||
|
||
it( 'will attach dropzone to element with dropZoneRef attached', () => { | ||
const { rerender } = render( <ComponentWithoutWrapperDropZone /> ); | ||
// Ensure `useEffect` has run. | ||
rerender( <ComponentWithoutWrapperDropZone /> ); | ||
|
||
expect( screen.getByRole( 'region' ) ).toHaveAttribute( | ||
'data-is-drop-zone' | ||
); | ||
} ); | ||
} ); |