Skip to content

Commit

Permalink
test: Media & Text block displays video upload errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dcalhoun committed Feb 22, 2024
1 parent 20a834a commit f7cea0c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export { default as MediaUploadProgress } from './media-upload-progress';
export {
MEDIA_UPLOAD_STATE_UPLOADING,
MEDIA_UPLOAD_STATE_SUCCEEDED,
MEDIA_UPLOAD_STATE_PAUSED,
MEDIA_UPLOAD_STATE_FAILED,
MEDIA_UPLOAD_STATE_RESET,
} from './media-upload-progress/constants';
Expand Down
58 changes: 58 additions & 0 deletions packages/block-library/src/media-text/test/edit.native.js
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();
} );
} );

0 comments on commit f7cea0c

Please sign in to comment.