Skip to content

Commit

Permalink
Mock VideoPress metadata of initial video before each replace test
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Jun 1, 2023
1 parent cdf73e0 commit edb3906
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
12 changes: 6 additions & 6 deletions src/test/videopress/__snapshots__/replace.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

exports[`VideoPress block - Replace replaces with a local video: after replacing video 1`] = `"<!-- wp:videopress/video {"title":"Local video from device","description":"video-description","useAverageColor":false,"id":34,"guid":"NEWxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace replaces with a local video: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"","useAverageColor":false,"id":1,"guid":"OLDxGUID","allowDownload":false,"rating":"G","isPrivate":false,"duration":2803} /-->"`;
exports[`VideoPress block - Replace replaces with a local video: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace replaces with new URL: after replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video from URL","description":"video-description","useAverageColor":false,"id":34,"guid":"NEWxGUID","src":"https://videopress.com/v/NEWxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace replaces with new URL: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"","useAverageColor":false,"id":1,"guid":"OLDxGUID","allowDownload":false,"rating":"G","isPrivate":false,"duration":2803} /-->"`;
exports[`VideoPress block - Replace replaces with new URL: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace replaces with video from media library: after replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video from media library","description":"video-description","useAverageColor":false,"id":34,"guid":"NEWxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace replaces with video from media library: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"","useAverageColor":false,"id":1,"guid":"OLDxGUID","allowDownload":false,"rating":"G","isPrivate":false,"duration":2803} /-->"`;
exports[`VideoPress block - Replace replaces with video from media library: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace restores previous video when canceling a video replacement: after canceling replacement 1`] = `"<!-- wp:videopress/video {"title":"Initial video","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","src":"file:///local-video-1.mp4","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;
exports[`VideoPress block - Replace restores previous video when canceling a video replacement: after canceling replacement 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","src":"file:///local-video-1.mp4","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace restores previous video when canceling a video replacement: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Initial video","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;
exports[`VideoPress block - Replace restores previous video when canceling a video replacement: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace takes a new video: after replacing video 1`] = `"<!-- wp:videopress/video {"title":"Recorded within the editor","description":"video-description","useAverageColor":false,"id":34,"guid":"NEWxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;

exports[`VideoPress block - Replace takes a new video: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"","useAverageColor":false,"id":1,"guid":"OLDxGUID","allowDownload":false,"rating":"G","isPrivate":false,"duration":2803} /-->"`;
exports[`VideoPress block - Replace takes a new video: before replacing video 1`] = `"<!-- wp:videopress/video {"title":"Video to be replaced","description":"video-description","useAverageColor":false,"id":34,"guid":"OLDxGUID","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":false,"duration":1200} /-->"`;
46 changes: 15 additions & 31 deletions src/test/videopress/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit edb3906

Please sign in to comment.