-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Media & Text block displays video upload errors
- Loading branch information
Showing
2 changed files
with
59 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
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,58 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
addBlock, | ||
fireEvent, | ||
initializeEditor, | ||
screen, | ||
setupCoreBlocks, | ||
} from 'test/helpers'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
requestMediaPicker, | ||
sendMediaUpload, | ||
subscribeMediaUpload, | ||
} from '@wordpress/react-native-bridge'; | ||
import { MEDIA_UPLOAD_STATE_PAUSED } from '@wordpress/block-editor'; | ||
|
||
let uploadCallBack; | ||
subscribeMediaUpload.mockImplementation( ( callback ) => { | ||
uploadCallBack = callback; | ||
} ); | ||
sendMediaUpload.mockImplementation( ( payload ) => { | ||
uploadCallBack( payload ); | ||
} ); | ||
|
||
setupCoreBlocks( [ 'core/media-text' ] ); | ||
|
||
describe( 'Media & Text block edit', () => { | ||
it( 'should display an error message for failed video uploads', async () => { | ||
requestMediaPicker.mockImplementation( | ||
( source, filter, multiple, callback ) => { | ||
callback( { | ||
id: 1, | ||
url: 'file://video.mp4', | ||
type: 'video', | ||
} ); | ||
} | ||
); | ||
await initializeEditor(); | ||
await addBlock( screen, 'Media & Text' ); | ||
fireEvent.press( screen.getByText( 'Add image or video' ) ); | ||
fireEvent.press( screen.getByText( 'Choose from device' ) ); | ||
|
||
sendMediaUpload( { | ||
mediaId: 1, | ||
state: MEDIA_UPLOAD_STATE_PAUSED, | ||
progress: 0, | ||
} ); | ||
|
||
expect( | ||
screen.getByText( 'Failed to insert media.\nTap for more info.' ) | ||
).toBeVisible(); | ||
} ); | ||
} ); |