Skip to content

Commit

Permalink
fix: Media & Text block displays video upload errors (#59288)
Browse files Browse the repository at this point in the history
* fix: Media & Text block displays video upload errors

When the paused state and messaging was implemented for image uploads,
it was inadvertently applied to Media & Text blocks. This resulted in a
lack of any failed upload messages when a video was attached to the
Media & Text block.

* test: Media & Text block displays video upload errors

* docs: Add change log entry
  • Loading branch information
dcalhoun authored Feb 23, 2024
1 parent e31be2f commit 908e3ed
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
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
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ class MediaContainer extends Component {
{ getMediaOptions() }

<MediaUploadProgress
enablePausedUploads
enablePausedUploads={
mediaType === MEDIA_TYPE_IMAGE
}
coverUrl={ coverUrl }
mediaId={ mediaId }
onUpdateMediaProgress={
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();
} );
} );
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For each user feature we should also add a importance categorization label to i

## Unreleased
- [*] Prevent crash when autoscrolling to blocks [#59110]
- [*] Media & Text blocks correctly show an error message when the attached video upload fails [#59288]

## 1.112.0
- [*] [internal] Upgrade React Native to version 0.71.15 [#57667]
Expand Down

1 comment on commit 908e3ed

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 908e3ed.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8012923966
📝 Reported issues:

Please sign in to comment.