From edb390617449c0e1331512d4dc6e2ded110806ba Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 1 Jun 2023 16:28:45 +0200 Subject: [PATCH] Mock VideoPress metadata of initial video before each replace test --- .../videopress/__snapshots__/replace.js.snap | 12 ++--- src/test/videopress/replace.js | 46 ++++++------------- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/test/videopress/__snapshots__/replace.js.snap b/src/test/videopress/__snapshots__/replace.js.snap index dfca6edd69..30d5bda23f 100644 --- a/src/test/videopress/__snapshots__/replace.js.snap +++ b/src/test/videopress/__snapshots__/replace.js.snap @@ -2,20 +2,20 @@ exports[`VideoPress block - Replace replaces with a local video: after replacing video 1`] = `""`; -exports[`VideoPress block - Replace replaces with a local video: before replacing video 1`] = `""`; +exports[`VideoPress block - Replace replaces with a local video: before replacing video 1`] = `""`; exports[`VideoPress block - Replace replaces with new URL: after replacing video 1`] = `""`; -exports[`VideoPress block - Replace replaces with new URL: before replacing video 1`] = `""`; +exports[`VideoPress block - Replace replaces with new URL: before replacing video 1`] = `""`; exports[`VideoPress block - Replace replaces with video from media library: after replacing video 1`] = `""`; -exports[`VideoPress block - Replace replaces with video from media library: before replacing video 1`] = `""`; +exports[`VideoPress block - Replace replaces with video from media library: before replacing video 1`] = `""`; -exports[`VideoPress block - Replace restores previous video when canceling a video replacement: after canceling replacement 1`] = `""`; +exports[`VideoPress block - Replace restores previous video when canceling a video replacement: after canceling replacement 1`] = `""`; -exports[`VideoPress block - Replace restores previous video when canceling a video replacement: before replacing video 1`] = `""`; +exports[`VideoPress block - Replace restores previous video when canceling a video replacement: before replacing video 1`] = `""`; exports[`VideoPress block - Replace takes a new video: after replacing video 1`] = `""`; -exports[`VideoPress block - Replace takes a new video: before replacing video 1`] = `""`; +exports[`VideoPress block - Replace takes a new video: before replacing video 1`] = `""`; diff --git a/src/test/videopress/replace.js b/src/test/videopress/replace.js index 49555b1b10..52f8c5c63e 100644 --- a/src/test/videopress/replace.js +++ b/src/test/videopress/replace.js @@ -60,6 +60,16 @@ beforeEach( () => { dispatch( coreStore ).invalidateResolutionForStoreSelector( 'getEmbedPreview' ); + + // Mock API responses for initial block. + setupApiFetch( + generateFetchMocks( { + guid: GUID_INITIAL_VIDEO, + metadata: { + title: 'Video to be replaced', + }, + } ) + ); } ); describe( 'VideoPress block - Replace', () => { @@ -86,10 +96,7 @@ describe( 'VideoPress block - Replace', () => { it( 'replaces with a local video', async () => { const screen = await initializeEditor( { - initialHtml: generateBlockHTML( { - guid: GUID_INITIAL_VIDEO, - title: 'Video to be replaced', - } ), + initialHtml: generateBlockHTML( { guid: GUID_INITIAL_VIDEO } ), } ); const { getByLabelText, getByTestId } = screen; @@ -138,10 +145,7 @@ describe( 'VideoPress block - Replace', () => { it( 'takes a new video', async () => { const screen = await initializeEditor( { - initialHtml: generateBlockHTML( { - guid: GUID_INITIAL_VIDEO, - title: 'Video to be replaced', - } ), + initialHtml: generateBlockHTML( { guid: GUID_INITIAL_VIDEO } ), } ); const { getByLabelText, getByTestId } = screen; @@ -190,10 +194,7 @@ describe( 'VideoPress block - Replace', () => { it( 'replaces with video from media library', async () => { const screen = await initializeEditor( { - initialHtml: generateBlockHTML( { - guid: GUID_INITIAL_VIDEO, - title: 'Video to be replaced', - } ), + initialHtml: generateBlockHTML( { guid: GUID_INITIAL_VIDEO } ), } ); const { getByLabelText, getByTestId } = screen; @@ -237,10 +238,7 @@ describe( 'VideoPress block - Replace', () => { it( 'replaces with new URL', async () => { const screen = await initializeEditor( { - initialHtml: generateBlockHTML( { - guid: GUID_INITIAL_VIDEO, - title: 'Video to be replaced', - } ), + initialHtml: generateBlockHTML( { guid: GUID_INITIAL_VIDEO } ), } ); const { getByLabelText, getByTestId } = screen; @@ -285,22 +283,8 @@ describe( 'VideoPress block - Replace', () => { } ); it( 'restores previous video when canceling a video replacement', async () => { - // Mock API responses for initial block. This will make the embed preview - // for the initial block to be cached. - setupApiFetch( - generateFetchMocks( { - guid: GUID_INITIAL_VIDEO, - metadata: { - title: 'Initial video', - }, - } ) - ); - const screen = await initializeEditor( { - initialHtml: generateBlockHTML( { - guid: GUID_INITIAL_VIDEO, - title: 'Video to be replaced', - } ), + initialHtml: generateBlockHTML( { guid: GUID_INITIAL_VIDEO } ), } ); const { getByLabelText, getByTestId } = screen;