Skip to content

Commit

Permalink
Mock API requests in VideoPress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed Jun 16, 2023
1 parent f79971e commit b123334
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/test/videopress/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
act,
within,
typeInRichText,
setupApiFetch,
generateFetchMocks,
} from 'test/helpers';

/**
Expand All @@ -37,12 +39,20 @@ import {
pressSettingInPicker,
} from './local-helpers/utils';

const FETCH_ITEMS = generateFetchMocks();

setupCoreBlocks();

beforeAll( () => {
// Register Jetpack blocks
setupJetpackEditor( { blogId: 1, isJetpackActive: true } );
setupJetpackEditor( {
blogId: 1,
isJetpackActive: true,
} );
registerJetpackBlocks( DEFAULT_PROPS );

// Mock request reponses
setupApiFetch( FETCH_ITEMS );
} );

describe( 'VideoPress block', () => {
Expand Down
21 changes: 19 additions & 2 deletions src/test/videopress/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ setupCoreBlocks();

beforeAll( () => {
// Register VideoPress block
setupJetpackEditor( { blogId: 1, isJetpackActive: true } );
registerJetpackBlocks( { capabilities: { videoPressBlock: true } } );
setupJetpackEditor( {
blogId: 1,
isJetpackActive: true,
} );
registerJetpackBlocks( {
capabilities: { videoPressBlock: true },
} );
} );

beforeEach( () => {
Expand All @@ -74,6 +79,9 @@ beforeEach( () => {

describe( 'VideoPress block - Replace', () => {
it( 'displays media options picker when replacing the video', async () => {
// Mock API responses for default VideoPress GUID
setupApiFetch( generateFetchMocks() );

const screen = await initializeEditor( {
initialHtml: generateBlockHTML(),
} );
Expand Down Expand Up @@ -327,6 +335,15 @@ describe( 'VideoPress block - Replace', () => {
const uploadingVideoView = getByTestId( 'videopress-uploading-video' );
expect( uploadingVideoView ).toBeVisible();

// Restores mocks for API requests of initial video
setupApiFetch(
generateFetchMocks( {
guid: GUID_INITIAL_VIDEO,
metadata: {
title: 'Video to be replaced',
},
} )
);
// Cancel upload
fireEvent.press( uploadingVideoView );
expect( requestImageUploadCancelDialog ).toHaveBeenCalledWith(
Expand Down

0 comments on commit b123334

Please sign in to comment.