Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cover block replace media e2e test #30306

Merged
merged 3 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-library/src/cover/controls.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ function Controls( {
</>
) : (
<TextControl
accessibilityLabel={ __( 'Add image or video' ) }
label={ __( 'Add image or video' ) }
labelStyle={ addMediaButtonStyle }
leftAlign
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { withSelect, withDispatch } from '@wordpress/data';
import { useEffect, useState, useRef, useCallback } from '@wordpress/element';
import { cover as icon, replace, image, warning } from '@wordpress/icons';
import { getProtocol } from '@wordpress/url';
import { store as editPostStore } from '@wordpress/edit-post';

/**
* Internal dependencies
Expand Down Expand Up @@ -575,13 +576,13 @@ export default compose( [
};
} ),
withDispatch( ( dispatch, { clientId } ) => {
const { openGeneralSidebar } = dispatch( 'core/edit-post' );
const { openGeneralSidebar } = dispatch( editPostStore );
const { selectBlock } = dispatch( blockEditorStore );

return {
openGeneralSidebar: () => openGeneralSidebar( 'edit-post/block' ),
closeSettingsBottomSheet() {
dispatch( 'core/edit-post' ).closeGeneralSidebar();
dispatch( editPostStore ).closeGeneralSidebar();
},
selectBlock: () => selectBlock( clientId ),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,61 @@ describe( 'Gutenberg Editor Cover Block test', () => {
expect( coverBlock ).toBeTruthy();
await editorPage.removeBlockAtPosition( blockNames.cover );
} );

// Testing this for iOS on a device is valuable to ensure that it properly
// handles opening multiple modals, as only one can be open at a time
it( 'allows modifying media from within block settings', async () => {
await editorPage.setHtmlContent( testData.coverHeightWithRemUnit );

const coverBlock = await editorPage.getBlockAtPosition(
blockNames.cover
);
await coverBlock.click();

// Can only add image from media library on iOS
if ( ! isAndroid() ) {
// Open block settings
const settingsButton = await editorPage.driver.elementByAccessibilityId(
'Open Settings'
);
await settingsButton.click();

// Add initial media via button within bottom sheet
const mediaSection = await editorPage.driver.elementByAccessibilityId(
'Media Add image or video'
);
const addMediaButton = await mediaSection.elementByAccessibilityId(
'Add image or video'
);
await addMediaButton.click();
await editorPage.chooseMediaLibrary();

// Edit media within block settings
await settingsButton.click();
await editorPage.driver.sleep( 2000 ); // Await media load
const editImageButton = await editorPage.driver.elementsByAccessibilityId(
'Edit image'
);
await editImageButton[ editImageButton.length - 1 ].click();

// Replace image
const replaceButton = await editorPage.driver.elementByAccessibilityId(
'Replace'
);
await replaceButton.click();

// First modal should no longer be presented
const replaceButtons = await editorPage.driver.elementsByAccessibilityId(
'Replace'
);
// eslint-disable-next-line jest/no-conditional-expect
expect( replaceButtons.length ).toBe( 0 );

// Select different media
await editorPage.chooseMediaLibrary();
}

expect( coverBlock ).toBeTruthy();
await editorPage.removeBlockAtPosition( blockNames.cover );
} );
} );