From ad1dce80a055ba7749bc8a48e4ac129bc6ee47f9 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 10:05:55 -0300 Subject: [PATCH 01/11] adding upload progress tests on BLockMediaUpdateProgress component (mediaFiles collection) --- .../test/index.native.js | 236 ++++++++++++++++++ 1 file changed, 236 insertions(+) create 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/test/index.native.js b/packages/block-editor/src/components/block-media-update-progress/test/index.native.js new file mode 100644 index 00000000000000..93f28565fe98a6 --- /dev/null +++ b/packages/block-editor/src/components/block-media-update-progress/test/index.native.js @@ -0,0 +1,236 @@ +/** + * External dependencies + */ +import { shallow } from 'enzyme'; + +/** + * WordPress dependencies + */ +import { sendMediaUpload } 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, +} from '../'; + +jest.mock( '@wordpress/react-native-bridge', () => { + const callUploadCallback = ( payload ) => { + this.uploadCallBack( payload ); + }; + const subscribeMediaUpload = ( callback ) => { + this.uploadCallBack = callback; + }; + const mediaSources = { + deviceCamera: 'DEVICE_CAMERA', + deviceLibrary: 'DEVICE_MEDIA_LIBRARY', + siteMediaLibrary: 'SITE_MEDIA_LIBRARY', + }; + return { + subscribeMediaUpload, + sendMediaUpload: callUploadCallback, + mediaSources, + }; +} ); + +// const MEDIA_ID_REMOTE = 123; +const MEDIA_ID_LOCAL = 2; +// const MEDIA_ID_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: '', + }, +]; + +// const remoteMediaFiles = [{'alt':'','caption':'','id':122,'link':'','mime':'image/jpeg','type':'image','url':''}, +// {'alt':'','caption':'','id':123,'link':'','mime':'image/jpeg','type':'image','url':''}]; + +describe( 'BlockMediaUpdateProgress component', () => { + it( 'renders without crashing', () => { + const wrapper = shallow( + {} } /> + ); + expect( wrapper ).toBeTruthy(); + } ); + + it( 'upload: listens media upload progress for local file', () => { + const progress = 10; + const payload = { + state: MEDIA_UPLOAD_STATE_UPLOADING, + mediaId: MEDIA_ID_LOCAL, + progress, + }; + + const onUpdateMediaProgress = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaUpload( payload ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + expect( wrapper.instance().state.isUploadInProgress ).toEqual( true ); + expect( wrapper.instance().state.isUploadFailed ).toEqual( false ); + expect( onUpdateMediaProgress ).toHaveBeenCalledTimes( 1 ); + expect( onUpdateMediaProgress ).toHaveBeenCalledWith( payload ); + } ); + + 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: 20, + }; + const onUpdateMediaProgress = jest.fn(); + const wrapper = shallow( + {} } + /> + ); + + sendMediaUpload( payload ); + + expect( wrapper.instance().state.progress ).toEqual( 0 ); + expect( onUpdateMediaProgress ).toHaveBeenCalledTimes( 0 ); + } ); + + it( 'upload: listens media upload success', () => { + const progress = 10; + const payloadSuccess = { + state: MEDIA_UPLOAD_STATE_SUCCEEDED, + mediaId: MEDIA_ID_LOCAL, + }; + const payloadUploading = { + state: MEDIA_UPLOAD_STATE_UPLOADING, + mediaId: MEDIA_ID_LOCAL, + progress, + }; + + const onFinishMediaUploadWithSuccess = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaUpload( payloadUploading ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaUpload( payloadSuccess ); + + expect( wrapper.instance().state.isUploadInProgress ).toEqual( false ); + expect( onFinishMediaUploadWithSuccess ).toHaveBeenCalledTimes( 1 ); + expect( onFinishMediaUploadWithSuccess ).toHaveBeenCalledWith( + payloadSuccess + ); + } ); + + it( 'upload: listens media upload fail', () => { + const progress = 10; + const payloadFail = { + state: MEDIA_UPLOAD_STATE_FAILED, + mediaId: MEDIA_ID_LOCAL, + }; + const payloadUploading = { + state: MEDIA_UPLOAD_STATE_UPLOADING, + mediaId: MEDIA_ID_LOCAL, + progress, + }; + + const onFinishMediaUploadWithFailure = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaUpload( payloadUploading ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaUpload( payloadFail ); + + expect( wrapper.instance().state.isUploadInProgress ).toEqual( false ); + expect( wrapper.instance().state.isUploadFailed ).toEqual( true ); + expect( onFinishMediaUploadWithFailure ).toHaveBeenCalledTimes( 1 ); + expect( onFinishMediaUploadWithFailure ).toHaveBeenCalledWith( + payloadFail + ); + } ); + + it( 'upload: listens media upload reset', () => { + const progress = 10; + const payloadReset = { + state: MEDIA_UPLOAD_STATE_RESET, + mediaId: MEDIA_ID_LOCAL, + }; + const payloadUploading = { + state: MEDIA_UPLOAD_STATE_UPLOADING, + mediaId: MEDIA_ID_LOCAL, + progress, + }; + + const onMediaUploadStateReset = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaUpload( payloadUploading ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaUpload( payloadReset ); + + expect( wrapper.instance().state.isUploadInProgress ).toEqual( false ); + expect( wrapper.instance().state.isUploadFailed ).toEqual( false ); + expect( onMediaUploadStateReset ).toHaveBeenCalledTimes( 1 ); + expect( onMediaUploadStateReset ).toHaveBeenCalledWith( payloadReset ); + } ); +} ); From b51ac46ebec5a4c8a84c3d50f458784682abf202 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 11:17:12 -0300 Subject: [PATCH 02/11] added save event tests for BlockMediaUpdateProgress component --- .../test/index.native.js | 279 +++++++++++++++++- 1 file changed, 272 insertions(+), 7 deletions(-) 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 index 93f28565fe98a6..792997d3a083ad 100644 --- 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 @@ -6,7 +6,7 @@ import { shallow } from 'enzyme'; /** * WordPress dependencies */ -import { sendMediaUpload } from '@wordpress/react-native-bridge'; +import { sendMediaUpload, sendMediaSave } from '@wordpress/react-native-bridge'; /** * Internal dependencies @@ -17,15 +17,27 @@ import { 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 '../'; jest.mock( '@wordpress/react-native-bridge', () => { const callUploadCallback = ( payload ) => { this.uploadCallBack( payload ); }; + const callSaveCallback = ( payload ) => { + this.saveCallBack( payload ); + }; const subscribeMediaUpload = ( callback ) => { this.uploadCallBack = callback; }; + const subscribeMediaSave = ( callback ) => { + this.saveCallBack = callback; + }; const mediaSources = { deviceCamera: 'DEVICE_CAMERA', deviceLibrary: 'DEVICE_MEDIA_LIBRARY', @@ -33,17 +45,37 @@ jest.mock( '@wordpress/react-native-bridge', () => { }; return { subscribeMediaUpload, + subscribeMediaSave, sendMediaUpload: callUploadCallback, + sendMediaSave: callSaveCallback, mediaSources, }; } ); // const MEDIA_ID_REMOTE = 123; const MEDIA_ID_LOCAL = 2; -// const MEDIA_ID_TEMP = 'tempid-0-1'; +const MEDIA_ID_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 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 = [ { @@ -66,9 +98,6 @@ const localMediaFiles = [ }, ]; -// const remoteMediaFiles = [{'alt':'','caption':'','id':122,'link':'','mime':'image/jpeg','type':'image','url':''}, -// {'alt':'','caption':'','id':123,'link':'','mime':'image/jpeg','type':'image','url':''}]; - describe( 'BlockMediaUpdateProgress component', () => { it( 'renders without crashing', () => { const wrapper = shallow( @@ -104,6 +133,7 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( onUpdateMediaProgress ).toHaveBeenCalledWith( payload ); } ); + // UPLOAD tests it( 'upload does not get affected by unrelated media uploads', () => { const payload = { state: MEDIA_UPLOAD_STATE_UPLOADING, @@ -233,4 +263,239 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( onMediaUploadStateReset ).toHaveBeenCalledTimes( 1 ); expect( onMediaUploadStateReset ).toHaveBeenCalledWith( payloadReset ); } ); + + // SAVE tests + it( 'save does not get affected by unrelated media uploads', () => { + const payload = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: 'tempid-432', // id not belonging to assigned mediaFiles collection in test + progress: 20, + }; + const onUpdateMediaSaveProgress = jest.fn(); + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payload ); + + expect( wrapper.instance().state.progress ).toEqual( 0 ); + expect( onUpdateMediaSaveProgress ).toHaveBeenCalledTimes( 0 ); + } ); + + it( 'save: listens media save success', () => { + const progress = 10; + const payloadSuccess = { + state: MEDIA_SAVE_STATE_SUCCEEDED, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + }; + const payloadSaving = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + progress, + }; + + const onFinishMediaSaveWithSuccess = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payloadSaving ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaSave( payloadSuccess ); + + expect( wrapper.instance().state.c ).toEqual( false ); + expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledTimes( 1 ); + expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledWith( + payloadSuccess + ); + } ); + + it( 'save: listens media save fail', () => { + const progress = 10; + const payloadFail = { + state: MEDIA_SAVE_STATE_FAILED, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + }; + const payloadSaving = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + progress, + }; + + const onFinishMediaSaveWithFailure = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payloadSaving ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaSave( payloadFail ); + + expect( wrapper.instance().state.isSaveInProgress ).toEqual( false ); + expect( wrapper.instance().state.isSaveFailed ).toEqual( true ); + expect( onFinishMediaSaveWithFailure ).toHaveBeenCalledTimes( 1 ); + expect( onFinishMediaSaveWithFailure ).toHaveBeenCalledWith( + payloadFail + ); + } ); + + it( 'save: listens media save reset', () => { + const progress = 10; + const payloadReset = { + state: MEDIA_SAVE_STATE_RESET, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + }; + const payloadSaving = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + progress, + }; + + const onMediaSaveStateReset = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payloadSaving ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaSave( payloadReset ); + + expect( wrapper.instance().state.isSaveInProgress ).toEqual( false ); + expect( wrapper.instance().state.isSaveFailed ).toEqual( false ); + expect( onMediaSaveStateReset ).toHaveBeenCalledTimes( 1 ); + expect( onMediaSaveStateReset ).toHaveBeenCalledWith( payloadReset ); + } ); + + it( 'save: listens total media save result, with result: fail', () => { + const progress = 10; + const payloadFail = { + state: MEDIA_SAVE_FINAL_STATE_RESULT, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + success: false, + }; + const payloadSaving = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + progress, + }; + + const onFinalSaveResult = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payloadSaving ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaSave( payloadFail ); + + expect( wrapper.instance().state.isSaveInProgress ).toEqual( false ); + expect( wrapper.instance().state.isSaveFailed ).toEqual( true ); + expect( onFinalSaveResult ).toHaveBeenCalledTimes( 1 ); + expect( onFinalSaveResult ).toHaveBeenCalledWith( payloadFail ); + } ); + + it( 'save: listens total media save result, with result: success', () => { + const progress = 10; + const payloadSuccess = { + state: MEDIA_SAVE_FINAL_STATE_RESULT, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + success: true, + }; + const payloadSaving = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + progress, + }; + + const onFinalSaveResult = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payloadSaving ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaSave( payloadSuccess ); + + expect( wrapper.instance().state.isSaveInProgress ).toEqual( false ); + expect( wrapper.instance().state.isSaveFailed ).toEqual( false ); + expect( onFinalSaveResult ).toHaveBeenCalledTimes( 1 ); + expect( onFinalSaveResult ).toHaveBeenCalledWith( payloadSuccess ); + } ); + + it( 'save: listens to mediaId change and passes it up', () => { + const progress = 10; + const payloadMediaIdChange = { + state: MEDIA_SAVE_MEDIAID_CHANGED, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + newId: MEDIA_ID_LOCAL, + mediaUrl: 'file:///folder/someimage.jpg', + }; + const payloadSaving = { + state: MEDIA_SAVE_STATE_SAVING, + mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + progress, + }; + + const onMediaIdChanged = jest.fn(); + + const wrapper = shallow( + {} } + /> + ); + + sendMediaSave( payloadSaving ); + + expect( wrapper.instance().state.progress ).toEqual( progress ); + + sendMediaSave( payloadMediaIdChange ); + + expect( wrapper.instance().state.isSaveInProgress ).toEqual( false ); + expect( wrapper.instance().state.isSaveFailed ).toEqual( false ); + expect( wrapper.instance().state.isUploadInProgress ).toEqual( false ); + expect( wrapper.instance().state.isUploadFailed ).toEqual( false ); + expect( onMediaIdChanged ).toHaveBeenCalledTimes( 1 ); + expect( onMediaIdChanged ).toHaveBeenCalledWith( payloadMediaIdChange ); + } ); } ); From b170d2bb5141b0ae2c4fa086ea74921e0ab0e6c5 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 12:09:10 -0300 Subject: [PATCH 03/11] ids in mediaFiles array are always strings, fixed that --- .../block-media-update-progress/test/index.native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 792997d3a083ad..bf892e87c5c657 100644 --- 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 @@ -81,7 +81,7 @@ const localMediaFiles = [ { alt: '', caption: '', - id: 2, + id: '2', link: '', mime: 'image/jpeg', type: 'image', @@ -90,7 +90,7 @@ const localMediaFiles = [ { alt: '', caption: '', - id: 3, + id: '3', link: '', mime: 'image/jpeg', type: 'image', From 7ddb7509c90a40a3bb64fd1f7adf2b30879341cd Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 12:33:46 -0300 Subject: [PATCH 04/11] updated function name passed by props --- .../test/index.native.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 index bf892e87c5c657..49c5867b1aad2c 100644 --- 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 @@ -114,11 +114,11 @@ describe( 'BlockMediaUpdateProgress component', () => { progress, }; - const onUpdateMediaProgress = jest.fn(); + const onUpdateMediaUploadProgress = jest.fn(); const wrapper = shallow( {} } /> @@ -129,8 +129,8 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( wrapper.instance().state.progress ).toEqual( progress ); expect( wrapper.instance().state.isUploadInProgress ).toEqual( true ); expect( wrapper.instance().state.isUploadFailed ).toEqual( false ); - expect( onUpdateMediaProgress ).toHaveBeenCalledTimes( 1 ); - expect( onUpdateMediaProgress ).toHaveBeenCalledWith( payload ); + expect( onUpdateMediaUploadProgress ).toHaveBeenCalledTimes( 1 ); + expect( onUpdateMediaUploadProgress ).toHaveBeenCalledWith( payload ); } ); // UPLOAD tests @@ -140,10 +140,10 @@ describe( 'BlockMediaUpdateProgress component', () => { mediaId: 432, // id not belonging to assigned mediaFiles collection in test progress: 20, }; - const onUpdateMediaProgress = jest.fn(); + const onUpdateMediaUploadProgress = jest.fn(); const wrapper = shallow( {} } /> @@ -152,7 +152,7 @@ describe( 'BlockMediaUpdateProgress component', () => { sendMediaUpload( payload ); expect( wrapper.instance().state.progress ).toEqual( 0 ); - expect( onUpdateMediaProgress ).toHaveBeenCalledTimes( 0 ); + expect( onUpdateMediaUploadProgress ).toHaveBeenCalledTimes( 0 ); } ); it( 'upload: listens media upload success', () => { From e1f9c0df52909a459baf3579b3d64502d90b7917 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 13:50:06 -0300 Subject: [PATCH 05/11] fixed mediaFiles const passing for saving, using tempMediaFiles --- .../block-media-update-progress/test/index.native.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 index 49c5867b1aad2c..5a7f05e1f13e26 100644 --- 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 @@ -303,7 +303,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const wrapper = shallow( {} } /> ); @@ -338,7 +338,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const wrapper = shallow( {} } /> ); @@ -374,7 +374,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const wrapper = shallow( {} } /> ); @@ -409,7 +409,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const wrapper = shallow( {} } /> ); @@ -444,7 +444,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const wrapper = shallow( {} } /> ); @@ -480,7 +480,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const wrapper = shallow( {} } /> ); From 5171320f30fd346d2ac45b8ddb490c10f819eb12 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 14:06:59 -0300 Subject: [PATCH 06/11] fixed state change for saveReset signal, was changing upload state instead --- .../src/components/block-media-update-progress/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index cdb10e1b26c967..279ef17d6e9987 100644 --- 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 @@ -153,7 +153,7 @@ export class BlockMediaUpdateProgress extends React.Component { } mediaSaveStateReset( payload ) { - this.setState( { isUploadInProgress: false, isUploadFailed: false } ); + this.setState( { isSaveInProgress: false, isSaveFailed: false } ); if ( this.props.onMediaSaveStateReset ) { this.props.onMediaSaveStateReset( payload ); } From d2d031a3f1963373055c5ed3400275500726379a Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 14:07:26 -0300 Subject: [PATCH 07/11] fixed typo --- .../components/block-media-update-progress/test/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 5a7f05e1f13e26..130f3b9c6fd81d 100644 --- 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 @@ -314,7 +314,7 @@ describe( 'BlockMediaUpdateProgress component', () => { sendMediaSave( payloadSuccess ); - expect( wrapper.instance().state.c ).toEqual( false ); + expect( wrapper.instance().state.isUploadInProgress ).toEqual( false ); expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledTimes( 1 ); expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledWith( payloadSuccess From 9dd50c7ad47b238cf9f70b6e43a8d00334121754 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Fri, 23 Oct 2020 14:08:45 -0300 Subject: [PATCH 08/11] fixed using save state var --- .../components/block-media-update-progress/test/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 130f3b9c6fd81d..fe7b4f98dbbb7d 100644 --- 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 @@ -314,7 +314,7 @@ describe( 'BlockMediaUpdateProgress component', () => { sendMediaSave( payloadSuccess ); - expect( wrapper.instance().state.isUploadInProgress ).toEqual( false ); + expect( wrapper.instance().state.isSaveInProgress ).toEqual( false ); expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledTimes( 1 ); expect( onFinishMediaSaveWithSuccess ).toHaveBeenCalledWith( payloadSuccess From 1f57e1d7e625d01e7009c9f61f2b859fd2d9b815 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 26 Oct 2020 10:45:35 -0300 Subject: [PATCH 09/11] changed to more descriptive test names --- .../test/index.native.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 index fe7b4f98dbbb7d..72c8595a54423e 100644 --- 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 @@ -106,7 +106,7 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( wrapper ).toBeTruthy(); } ); - it( 'upload: listens media upload progress for local file', () => { + it( 'upload: onUpdateMediaUploadProgress is called when a progress update payload is received', () => { const progress = 10; const payload = { state: MEDIA_UPLOAD_STATE_UPLOADING, @@ -155,7 +155,7 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( onUpdateMediaUploadProgress ).toHaveBeenCalledTimes( 0 ); } ); - it( 'upload: listens media upload success', () => { + it( 'upload: onFinishMediaUploadWithSuccess is called when a success payload is received', () => { const progress = 10; const payloadSuccess = { state: MEDIA_UPLOAD_STATE_SUCCEEDED, @@ -192,7 +192,7 @@ describe( 'BlockMediaUpdateProgress component', () => { ); } ); - it( 'upload: listens media upload fail', () => { + it( 'upload: onFinishMediaUploadWithFailure is called when a failed payload is received', () => { const progress = 10; const payloadFail = { state: MEDIA_UPLOAD_STATE_FAILED, @@ -230,7 +230,7 @@ describe( 'BlockMediaUpdateProgress component', () => { ); } ); - it( 'upload: listens media upload reset', () => { + it( 'upload: onMediaUploadStateReset is called when a reset payload is received', () => { const progress = 10; const payloadReset = { state: MEDIA_UPLOAD_STATE_RESET, @@ -265,7 +265,7 @@ describe( 'BlockMediaUpdateProgress component', () => { } ); // SAVE tests - it( 'save does not get affected by unrelated media uploads', () => { + 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 @@ -286,7 +286,7 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( onUpdateMediaSaveProgress ).toHaveBeenCalledTimes( 0 ); } ); - it( 'save: listens media save success', () => { + it( 'save: onFinishMediaSaveWithSuccess is called when a success payload is received', () => { const progress = 10; const payloadSuccess = { state: MEDIA_SAVE_STATE_SUCCEEDED, @@ -321,7 +321,7 @@ describe( 'BlockMediaUpdateProgress component', () => { ); } ); - it( 'save: listens media save fail', () => { + it( 'save: onFinishMediaSaveWithFailure is called when a failed payload is received', () => { const progress = 10; const payloadFail = { state: MEDIA_SAVE_STATE_FAILED, @@ -357,7 +357,7 @@ describe( 'BlockMediaUpdateProgress component', () => { ); } ); - it( 'save: listens media save reset', () => { + it( 'save: onMediaSaveStateReset is called when a reset payload is received', () => { const progress = 10; const payloadReset = { state: MEDIA_SAVE_STATE_RESET, @@ -391,7 +391,7 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( onMediaSaveStateReset ).toHaveBeenCalledWith( payloadReset ); } ); - it( 'save: listens total media save result, with result: fail', () => { + it( 'save: onFinalSaveResult is called with fail result when fail result is received', () => { const progress = 10; const payloadFail = { state: MEDIA_SAVE_FINAL_STATE_RESULT, @@ -426,7 +426,7 @@ describe( 'BlockMediaUpdateProgress component', () => { expect( onFinalSaveResult ).toHaveBeenCalledWith( payloadFail ); } ); - it( 'save: listens total media save result, with result: success', () => { + it( 'save: onFinalSaveResult is called with success result when success result is received', () => { const progress = 10; const payloadSuccess = { state: MEDIA_SAVE_FINAL_STATE_RESULT, From 94be698e8ccf359df17b593a0cbe4617df959544 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 28 Oct 2020 11:59:45 -0300 Subject: [PATCH 10/11] removed commented line --- .../components/block-media-update-progress/test/index.native.js | 1 - 1 file changed, 1 deletion(-) 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 index 72c8595a54423e..bc30a8f42183e7 100644 --- 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 @@ -52,7 +52,6 @@ jest.mock( '@wordpress/react-native-bridge', () => { }; } ); -// const MEDIA_ID_REMOTE = 123; const MEDIA_ID_LOCAL = 2; const MEDIA_ID_TEMP = 'tempid-0-1'; From 453e0d0ea194546383439015de12eca9e639bec9 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Wed, 28 Oct 2020 12:10:51 -0300 Subject: [PATCH 11/11] renamed vars to match bridge signal name --- .../test/index.native.js | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) 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 index bc30a8f42183e7..82016ab68d9b6d 100644 --- 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 @@ -52,8 +52,8 @@ jest.mock( '@wordpress/react-native-bridge', () => { }; } ); -const MEDIA_ID_LOCAL = 2; -const MEDIA_ID_TEMP = 'tempid-0-1'; +const MEDIAID_LOCAL = 2; +const MEDIAID_TEMP = 'tempid-0-1'; const tempMediaFiles = [ { @@ -109,7 +109,7 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payload = { state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, progress, }; @@ -158,11 +158,11 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadSuccess = { state: MEDIA_UPLOAD_STATE_SUCCEEDED, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, }; const payloadUploading = { state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, progress, }; @@ -195,11 +195,11 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadFail = { state: MEDIA_UPLOAD_STATE_FAILED, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, }; const payloadUploading = { state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, progress, }; @@ -233,11 +233,11 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadReset = { state: MEDIA_UPLOAD_STATE_RESET, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, }; const payloadUploading = { state: MEDIA_UPLOAD_STATE_UPLOADING, - mediaId: MEDIA_ID_LOCAL, + mediaId: MEDIAID_LOCAL, progress, }; @@ -289,11 +289,11 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadSuccess = { state: MEDIA_SAVE_STATE_SUCCEEDED, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key }; const payloadSaving = { state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key progress, }; @@ -324,11 +324,11 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadFail = { state: MEDIA_SAVE_STATE_FAILED, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key }; const payloadSaving = { state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key progress, }; @@ -360,11 +360,11 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadReset = { state: MEDIA_SAVE_STATE_RESET, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key }; const payloadSaving = { state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key progress, }; @@ -394,12 +394,12 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadFail = { state: MEDIA_SAVE_FINAL_STATE_RESULT, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key success: false, }; const payloadSaving = { state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key progress, }; @@ -429,12 +429,12 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadSuccess = { state: MEDIA_SAVE_FINAL_STATE_RESULT, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key success: true, }; const payloadSaving = { state: MEDIA_SAVE_STATE_SAVING, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key progress, }; @@ -464,13 +464,13 @@ describe( 'BlockMediaUpdateProgress component', () => { const progress = 10; const payloadMediaIdChange = { state: MEDIA_SAVE_MEDIAID_CHANGED, - mediaId: MEDIA_ID_TEMP, // while saving, we have a tempid key - newId: MEDIA_ID_LOCAL, + 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: MEDIA_ID_TEMP, // while saving, we have a tempid key + mediaId: MEDIAID_TEMP, // while saving, we have a tempid key progress, };