From 07da7f09dd071bee333f72d685d251552275be83 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Wed, 28 Jun 2023 14:43:36 +0300 Subject: [PATCH] RN: Remove unused BlockMediaUpdateProgress component --- .../block-media-update-progress/README.md | 100 ---- .../index.native.js | 299 ---------- .../styles.native.scss | 9 - .../test/index.native.js | 543 ------------------ .../src/components/index.native.js | 1 - 5 files changed, 952 deletions(-) delete mode 100644 packages/block-editor/src/components/block-media-update-progress/README.md delete mode 100644 packages/block-editor/src/components/block-media-update-progress/index.native.js delete mode 100644 packages/block-editor/src/components/block-media-update-progress/styles.native.scss delete mode 100644 packages/block-editor/src/components/block-media-update-progress/test/index.native.js diff --git a/packages/block-editor/src/components/block-media-update-progress/README.md b/packages/block-editor/src/components/block-media-update-progress/README.md deleted file mode 100644 index 97abff477ea24f..00000000000000 --- a/packages/block-editor/src/components/block-media-update-progress/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# BlockMediaUpdateProgress - -`BlockMediaUpdateProgress` shows a progress bar while the media files associated with a media-containing block are being saved first and uploaded later - -## Usage - -Usage example - -```jsx -import { ImageBackground, Text, View } from 'react-native'; -import { BlockMediaUpdateProgress } from '@wordpress/block-editor'; - -function BlockUpdatingProgress( { url, id } ) { - return ( - { - return ( - - { isSaveFailed && ( - - { retryMessage } - - ) } - - ); - } } - /> - ); -} -``` - -## Props - -### mediaFiles - -A collection of media ID that identifies the current collection of files represented in this media container block. - -- Type: `Array` -- Required: Yes -- Platform: Mobile - -### renderContent - -Content to be rendered along with the progress bar, usually the thumbnail of the media being uploaded. - -- Type: `React components` -- Required: Yes -- Platform: Mobile - -It passes an object containing the following properties: - -`{ isUploadInProgress, isUploadFailed, isSaveInProgress, isSaveFailed, retryMessage }` - -### onUpdateMediaProgress - -Callback called when the progress of the upload is updated. - -- Type: `Function` -- Required: No -- Platform: Mobile - -The argument of the callback is an object containing the following properties: - -`{ mediaId, mediaUrl, progress, state }` - -### onFinishMediaUploadWithSuccess - -Callback called when the media file has been uploaded successfully. - -- Type: `Function` -- Required: No -- Platform: Mobile - -The argument of the callback is an object containing the following properties: - -`{ mediaId, mediaServerId, mediaUrl, progress, state }` - -### onFinishMediaUploadWithFailure - -Callback called when the media file couldn't be uploaded. - -- Type: `Function` -- Required: No -- Platform: Mobile - -The argument of the callback is an object containing the following properties: - -`{ mediaId, progress, state }` - -### onMediaUploadStateReset - -Callback called when the media upload is reset - -- Type: `Function` -- Required: No -- Platform: Mobile diff --git a/packages/block-editor/src/components/block-media-update-progress/index.native.js b/packages/block-editor/src/components/block-media-update-progress/index.native.js deleted file mode 100644 index 916851eafc85a8..00000000000000 --- a/packages/block-editor/src/components/block-media-update-progress/index.native.js +++ /dev/null @@ -1,299 +0,0 @@ -/** - * External dependencies - */ -import { View } from 'react-native'; - -/** - * WordPress dependencies - */ -import { Component } from '@wordpress/element'; -import { Spinner } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; -import { - subscribeMediaUpload, - subscribeMediaSave, -} from '@wordpress/react-native-bridge'; - -/** - * Internal dependencies - */ -import styles from './styles.scss'; - -export const MEDIA_UPLOAD_STATE_UPLOADING = 1; -export const MEDIA_UPLOAD_STATE_SUCCEEDED = 2; -export const MEDIA_UPLOAD_STATE_FAILED = 3; -export const MEDIA_UPLOAD_STATE_RESET = 4; - -export const MEDIA_SAVE_STATE_SAVING = 5; -export const MEDIA_SAVE_STATE_SUCCEEDED = 6; -export const MEDIA_SAVE_STATE_FAILED = 7; -export const MEDIA_SAVE_STATE_RESET = 8; -export const MEDIA_SAVE_FINAL_STATE_RESULT = 9; -export const MEDIA_SAVE_MEDIAID_CHANGED = 10; - -export class BlockMediaUpdateProgress extends Component { - constructor( props ) { - super( props ); - - this.state = { - progress: 0, - isSaveInProgress: false, - isSaveFailed: false, - isUploadInProgress: false, - isUploadFailed: false, - }; - - this.mediaUpload = this.mediaUpload.bind( this ); - this.mediaSave = this.mediaSave.bind( this ); - } - - componentDidMount() { - this.addMediaUploadListener(); - this.addMediaSaveListener(); - } - - componentWillUnmount() { - this.removeMediaUploadListener(); - this.removeMediaSaveListener(); - } - - mediaIdContainedInMediaFiles( mediaId, mediaFiles ) { - if ( mediaId !== undefined && mediaFiles !== undefined ) { - return mediaFiles.some( - ( element ) => element.id === mediaId.toString() - ); - } - return false; - } - - mediaUpload( payload ) { - const { mediaFiles } = this.props; - - if ( - this.mediaIdContainedInMediaFiles( payload.mediaId, mediaFiles ) === - false - ) { - return; - } - - switch ( payload.state ) { - case MEDIA_UPLOAD_STATE_UPLOADING: - this.updateMediaUploadProgress( payload ); - break; - case MEDIA_UPLOAD_STATE_SUCCEEDED: - this.finishMediaUploadWithSuccess( payload ); - break; - case MEDIA_UPLOAD_STATE_FAILED: - this.finishMediaUploadWithFailure( payload ); - break; - case MEDIA_UPLOAD_STATE_RESET: - this.mediaUploadStateReset( payload ); - break; - } - } - - mediaSave( payload ) { - const { mediaFiles } = this.props; - - if ( - this.mediaIdContainedInMediaFiles( payload.mediaId, mediaFiles ) === - false - ) { - return; - } - - switch ( payload.state ) { - case MEDIA_SAVE_STATE_SAVING: - this.updateMediaSaveProgress( payload ); - break; - case MEDIA_SAVE_STATE_SUCCEEDED: - this.finishMediaSaveWithSuccess( payload ); - break; - case MEDIA_SAVE_STATE_FAILED: - this.finishMediaSaveWithFailure( payload ); - break; - case MEDIA_SAVE_STATE_RESET: - this.mediaSaveStateReset( payload ); - break; - case MEDIA_SAVE_FINAL_STATE_RESULT: - this.finalSaveResult( payload ); - break; - case MEDIA_SAVE_MEDIAID_CHANGED: - this.mediaIdChanged( payload ); - break; - } - } - - // ---- Block media save actions. - updateMediaSaveProgress( payload ) { - this.setState( { - progress: payload.progress, - isUploadInProgress: false, - isUploadFailed: false, - isSaveInProgress: true, - isSaveFailed: false, - } ); - if ( this.props.onUpdateMediaSaveProgress ) { - this.props.onUpdateMediaSaveProgress( payload ); - } - } - - finishMediaSaveWithSuccess( payload ) { - this.setState( { isSaveInProgress: false } ); - if ( this.props.onFinishMediaSaveWithSuccess ) { - this.props.onFinishMediaSaveWithSuccess( payload ); - } - } - - finishMediaSaveWithFailure( payload ) { - this.setState( { isSaveInProgress: false, isSaveFailed: true } ); - if ( this.props.onFinishMediaSaveWithFailure ) { - this.props.onFinishMediaSaveWithFailure( payload ); - } - } - - mediaSaveStateReset( payload ) { - this.setState( { isSaveInProgress: false, isSaveFailed: false } ); - if ( this.props.onMediaSaveStateReset ) { - this.props.onMediaSaveStateReset( payload ); - } - } - - finalSaveResult( payload ) { - this.setState( { - progress: payload.progress, - isUploadInProgress: false, - isUploadFailed: false, - isSaveInProgress: false, - isSaveFailed: ! payload.success, - } ); - if ( this.props.onFinalSaveResult ) { - this.props.onFinalSaveResult( payload ); - } - } - - mediaIdChanged( payload ) { - this.setState( { - isUploadInProgress: false, - isUploadFailed: false, - isSaveInProgress: false, - isSaveFailed: false, - } ); - if ( this.props.onMediaIdChanged ) { - this.props.onMediaIdChanged( payload ); - } - } - - // ---- Block media upload actions. - updateMediaUploadProgress( payload ) { - this.setState( { - progress: payload.progress, - isUploadInProgress: true, - isUploadFailed: false, - isSaveInProgress: false, - isSaveFailed: false, - } ); - if ( this.props.onUpdateMediaUploadProgress ) { - this.props.onUpdateMediaUploadProgress( payload ); - } - } - - finishMediaUploadWithSuccess( payload ) { - this.setState( { isUploadInProgress: false, isSaveInProgress: false } ); - if ( this.props.onFinishMediaUploadWithSuccess ) { - this.props.onFinishMediaUploadWithSuccess( payload ); - } - } - - finishMediaUploadWithFailure( payload ) { - this.setState( { isUploadInProgress: false, isUploadFailed: true } ); - if ( this.props.onFinishMediaUploadWithFailure ) { - this.props.onFinishMediaUploadWithFailure( payload ); - } - } - - mediaUploadStateReset( payload ) { - this.setState( { isUploadInProgress: false, isUploadFailed: false } ); - if ( this.props.onMediaUploadStateReset ) { - this.props.onMediaUploadStateReset( payload ); - } - } - - addMediaUploadListener() { - // If we already have a subscription not worth doing it again. - if ( this.subscriptionParentMediaUpload ) { - return; - } - this.subscriptionParentMediaUpload = subscribeMediaUpload( - ( payload ) => { - this.mediaUpload( payload ); - } - ); - } - - removeMediaUploadListener() { - if ( this.subscriptionParentMediaUpload ) { - this.subscriptionParentMediaUpload.remove(); - } - } - - addMediaSaveListener() { - // If we already have a subscription not worth doing it again. - if ( this.subscriptionParentMediaSave ) { - return; - } - this.subscriptionParentMediaSave = subscribeMediaSave( ( payload ) => { - this.mediaSave( payload ); - } ); - } - - removeMediaSaveListener() { - if ( this.subscriptionParentMediaSave ) { - this.subscriptionParentMediaSave.remove(); - } - } - - render() { - const { renderContent = () => null } = this.props; - const { - isUploadInProgress, - isUploadFailed, - isSaveInProgress, - isSaveFailed, - } = this.state; - const showSpinner = - this.state.isUploadInProgress || this.state.isSaveInProgress; - const progress = this.state.progress * 100; - // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace - const retryMessageSave = __( - 'Failed to save files.\nPlease tap for options.' - ); - // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace - const retryMessageUpload = __( - 'Failed to upload files.\nPlease tap for options.' - ); - let retryMessage = retryMessageSave; - if ( isUploadFailed ) { - retryMessage = retryMessageUpload; - } - - return ( - - { showSpinner && ( - - - - ) } - { renderContent( { - isUploadInProgress, - isUploadFailed, - isSaveInProgress, - isSaveFailed, - retryMessage, - } ) } - - ); - } -} - -export default BlockMediaUpdateProgress; diff --git a/packages/block-editor/src/components/block-media-update-progress/styles.native.scss b/packages/block-editor/src/components/block-media-update-progress/styles.native.scss deleted file mode 100644 index 2178be1968b1c5..00000000000000 --- a/packages/block-editor/src/components/block-media-update-progress/styles.native.scss +++ /dev/null @@ -1,9 +0,0 @@ -.mediaUploadProgress { - flex: 1; - z-index: 1; -} - -.progressBar { - background-color: $gray-lighten-30; - z-index: 1; -} diff --git a/packages/block-editor/src/components/block-media-update-progress/test/index.native.js b/packages/block-editor/src/components/block-media-update-progress/test/index.native.js deleted file mode 100644 index c2c1a71a1f0717..00000000000000 --- a/packages/block-editor/src/components/block-media-update-progress/test/index.native.js +++ /dev/null @@ -1,543 +0,0 @@ -/** - * External dependencies - */ -import { render } from 'test/helpers'; - -/** - * WordPress dependencies - */ -import { - sendMediaSave, - sendMediaUpload, - subscribeMediaSave, - subscribeMediaUpload, -} from '@wordpress/react-native-bridge'; - -/** - * Internal dependencies - */ -import { - BlockMediaUpdateProgress, - MEDIA_UPLOAD_STATE_UPLOADING, - MEDIA_UPLOAD_STATE_SUCCEEDED, - MEDIA_UPLOAD_STATE_FAILED, - MEDIA_UPLOAD_STATE_RESET, - MEDIA_SAVE_STATE_SAVING, - MEDIA_SAVE_STATE_SUCCEEDED, - MEDIA_SAVE_STATE_FAILED, - MEDIA_SAVE_STATE_RESET, - MEDIA_SAVE_FINAL_STATE_RESULT, - MEDIA_SAVE_MEDIAID_CHANGED, -} from '../'; - -let uploadCallBack; -subscribeMediaUpload.mockImplementation( ( callback ) => { - uploadCallBack = callback; -} ); -let saveCallBack; -subscribeMediaSave.mockImplementation( ( callback ) => { - saveCallBack = callback; -} ); -sendMediaUpload.mockImplementation( ( payload ) => { - uploadCallBack( payload ); -} ); -sendMediaSave.mockImplementation( ( payload ) => { - saveCallBack( payload ); -} ); - -const MEDIAID_LOCAL = 2; -const MEDIAID_TEMP = 'tempid-0-1'; - -const tempMediaFiles = [ - { - alt: '', - caption: '', - id: 'tempid-0-1', - link: '', - mime: 'image/jpeg', - type: 'image', - url: '', - }, - { - alt: '', - caption: '', - id: 'tempid-0-2', - link: '', - mime: 'image/jpeg', - type: 'image', - url: '', - }, -]; - -const localMediaFiles = [ - { - alt: '', - caption: '', - id: '2', - link: '', - mime: 'image/jpeg', - type: 'image', - url: '', - }, - { - alt: '', - caption: '', - id: '3', - link: '', - mime: 'image/jpeg', - type: 'image', - url: '', - }, -]; - -describe( 'BlockMediaUpdateProgress component', () => { - it( 'renders without crashing', () => { - const wrapper = render( - {} } /> - ); - expect( wrapper ).toBeTruthy(); - } ); - - it( 'upload: onUpdateMediaUploadProgress is called when a progress update payload is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payload = { - state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIAID_LOCAL, - progress, - }; - - const onUpdateMediaUploadProgress = jest.fn(); - - const wrapper = render( - - ); - - sendMediaUpload( payload ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isUploadInProgress: true, - isUploadFailed: false, - } ) - ); - expect( onUpdateMediaUploadProgress ).toHaveBeenCalledTimes( 1 ); - expect( onUpdateMediaUploadProgress ).toHaveBeenCalledWith( payload ); - } ); - - // UPLOAD tests. - it( 'upload does not get affected by unrelated media uploads', () => { - const payload = { - state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: 432, // id not belonging to assigned mediaFiles collection in test - progress: 0.2, - }; - const onUpdateMediaUploadProgress = jest.fn(); - const wrapper = render( - {} } - /> - ); - - sendMediaUpload( payload ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( onUpdateMediaUploadProgress ).toHaveBeenCalledTimes( 0 ); - } ); - - it( 'upload: onFinishMediaUploadWithSuccess is called when a success payload is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadSuccess = { - state: MEDIA_UPLOAD_STATE_SUCCEEDED, - mediaId: MEDIAID_LOCAL, - }; - const payloadUploading = { - state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIAID_LOCAL, - progress, - }; - - const onFinishMediaUploadWithSuccess = jest.fn(); - - const wrapper = render( - - ); - - sendMediaUpload( payloadUploading ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaUpload( payloadSuccess ); - - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isUploadInProgress: false, - } ) - ); - expect( onFinishMediaUploadWithSuccess ).toHaveBeenCalledTimes( 1 ); - expect( onFinishMediaUploadWithSuccess ).toHaveBeenCalledWith( - payloadSuccess - ); - } ); - - it( 'upload: onFinishMediaUploadWithFailure is called when a failed payload is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadFail = { - state: MEDIA_UPLOAD_STATE_FAILED, - mediaId: MEDIAID_LOCAL, - }; - const payloadUploading = { - state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIAID_LOCAL, - progress, - }; - - const onFinishMediaUploadWithFailure = jest.fn(); - - const wrapper = render( - - ); - - sendMediaUpload( payloadUploading ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaUpload( payloadFail ); - - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isUploadInProgress: false, - isUploadFailed: true, - } ) - ); - expect( onFinishMediaUploadWithFailure ).toHaveBeenCalledTimes( 1 ); - expect( onFinishMediaUploadWithFailure ).toHaveBeenCalledWith( - payloadFail - ); - } ); - - it( 'upload: onMediaUploadStateReset is called when a reset payload is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadReset = { - state: MEDIA_UPLOAD_STATE_RESET, - mediaId: MEDIAID_LOCAL, - }; - const payloadUploading = { - state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIAID_LOCAL, - progress, - }; - - const onMediaUploadStateReset = jest.fn(); - - const wrapper = render( - - ); - - sendMediaUpload( payloadUploading ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaUpload( payloadReset ); - - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isUploadInProgress: false, - isUploadFailed: false, - } ) - ); - expect( onMediaUploadStateReset ).toHaveBeenCalledTimes( 1 ); - expect( onMediaUploadStateReset ).toHaveBeenCalledWith( payloadReset ); - } ); - - // SAVE tests. - it( 'save does not get affected by unrelated media save events', () => { - const payload = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: 'tempid-432', // id not belonging to assigned mediaFiles collection in test - progress: 0.2, - }; - const onUpdateMediaSaveProgress = jest.fn(); - const wrapper = render( - {} } - /> - ); - - sendMediaSave( payload ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( onUpdateMediaSaveProgress ).toHaveBeenCalledTimes( 0 ); - } ); - - it( 'save: onFinishMediaSaveWithSuccess is called when a success payload is received', () => { - const progress = 0.1; - const payloadSuccess = { - state: MEDIA_SAVE_STATE_SUCCEEDED, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - }; - const payloadSaving = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - progress, - }; - - const onFinishMediaSaveWithSuccess = jest.fn(); - - const wrapper = render( - {} } - /> - ); - - sendMediaSave( payloadSaving ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaSave( payloadSuccess ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledTimes( 1 ); - expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledWith( - payloadSuccess - ); - } ); - - it( 'save: onFinishMediaSaveWithFailure is called when a failed payload is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadFail = { - state: MEDIA_SAVE_STATE_FAILED, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - }; - const payloadSaving = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - progress, - }; - - const onFinishMediaSaveWithFailure = jest.fn(); - - const wrapper = render( - - ); - - sendMediaSave( payloadSaving ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaSave( payloadFail ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isSaveInProgress: false, - isSaveFailed: true, - } ) - ); - expect( onFinishMediaSaveWithFailure ).toHaveBeenCalledTimes( 1 ); - expect( onFinishMediaSaveWithFailure ).toHaveBeenCalledWith( - payloadFail - ); - } ); - - it( 'save: onMediaSaveStateReset is called when a reset payload is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadReset = { - state: MEDIA_SAVE_STATE_RESET, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - }; - const payloadSaving = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - progress, - }; - - const onMediaSaveStateReset = jest.fn(); - - const wrapper = render( - - ); - - sendMediaSave( payloadSaving ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaSave( payloadReset ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isSaveFailed: false, - isSaveInProgress: false, - } ) - ); - expect( onMediaSaveStateReset ).toHaveBeenCalledTimes( 1 ); - expect( onMediaSaveStateReset ).toHaveBeenCalledWith( payloadReset ); - } ); - - it( 'save: onFinalSaveResult is called with fail result when fail result is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadFail = { - state: MEDIA_SAVE_FINAL_STATE_RESULT, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - success: false, - }; - const payloadSaving = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - progress, - }; - - const onFinalSaveResult = jest.fn(); - - const wrapper = render( - - ); - - sendMediaSave( payloadSaving ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaSave( payloadFail ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isSaveFailed: true, - isSaveInProgress: false, - } ) - ); - expect( onFinalSaveResult ).toHaveBeenCalledTimes( 1 ); - expect( onFinalSaveResult ).toHaveBeenCalledWith( payloadFail ); - } ); - - it( 'save: onFinalSaveResult is called with success result when success result is received', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadSuccess = { - state: MEDIA_SAVE_FINAL_STATE_RESULT, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - success: true, - }; - const payloadSaving = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - progress, - }; - - const onFinalSaveResult = jest.fn(); - - const wrapper = render( - - ); - - sendMediaSave( payloadSaving ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaSave( payloadSuccess ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isSaveFailed: false, - isSaveInProgress: false, - } ) - ); - expect( onFinalSaveResult ).toHaveBeenCalledTimes( 1 ); - expect( onFinalSaveResult ).toHaveBeenCalledWith( payloadSuccess ); - } ); - - it( 'save: listens to mediaId change and passes it up', () => { - const renderContentMock = jest.fn(); - const progress = 0.1; - const payloadMediaIdChange = { - state: MEDIA_SAVE_MEDIAID_CHANGED, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - newId: MEDIAID_LOCAL, - mediaUrl: 'file:///folder/someimage.jpg', - }; - const payloadSaving = { - state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIAID_TEMP, // while saving, we have a tempid key - progress, - }; - - const onMediaIdChanged = jest.fn(); - - const wrapper = render( - - ); - - sendMediaSave( payloadSaving ); - - expect( wrapper.getByTestId( 'spinner' ) ).toBeTruthy(); - - sendMediaSave( payloadMediaIdChange ); - - expect( wrapper.queryByTestId( 'spinner' ) ).toBeNull(); - expect( renderContentMock ).toHaveBeenCalledWith( - expect.objectContaining( { - isSaveFailed: false, - isSaveInProgress: false, - isUploadInProgress: false, - isUploadFailed: false, - } ) - ); - expect( onMediaIdChanged ).toHaveBeenCalledTimes( 1 ); - expect( onMediaIdChanged ).toHaveBeenCalledWith( payloadMediaIdChange ); - } ); -} ); diff --git a/packages/block-editor/src/components/index.native.js b/packages/block-editor/src/components/index.native.js index a6ab6bb76d0480..0936b636c99d67 100644 --- a/packages/block-editor/src/components/index.native.js +++ b/packages/block-editor/src/components/index.native.js @@ -52,7 +52,6 @@ export { MEDIA_UPLOAD_STATE_FAILED, MEDIA_UPLOAD_STATE_RESET, } from './media-upload-progress'; -export { default as BlockMediaUpdateProgress } from './block-media-update-progress'; export { default as URLInput } from './url-input'; export { default as BlockInvalidWarning } from './block-list/block-invalid-warning'; export { default as BlockCaption } from './block-caption';