File size: 4,394 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
/**
* @group gutenberg
*/
import {
envVariables,
MediaHelper,
EditorPage,
TestFile,
ClicktoTweetBlock,
DynamicHRBlock,
HeroBlock,
LogosBlock,
PricingTableBlock,
TestAccount,
getTestAccountByFeature,
envToFeatureKey,
} from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
import { TEST_IMAGE_PATH } from '../constants';
declare const browser: Browser;
const features = envToFeatureKey( envVariables );
// For this spec, all Atomic testing is always edge.
// See https://github.com/Automattic/wp-calypso/pull/73052
if ( envVariables.TEST_ON_ATOMIC ) {
features.coblocks = 'edge';
}
/**
* This spec requires the following:
* - theme: a non-block-based theme (eg. Twenty-Twenty One)
*/
describe( 'CoBlocks: Blocks', function () {
const accountName = getTestAccountByFeature( features );
let page: Page;
let testAccount: TestAccount;
let editorPage: EditorPage;
let pricingTableBlock: PricingTableBlock;
let logoImage: TestFile;
// Test data
const pricingTableBlockPrices = [ 4.99, 9.99 ];
const heroBlockHeading = 'Hero heading';
const clicktoTweetBlockTweet = 'Tweet text';
beforeAll( async () => {
page = await browser.newPage();
logoImage = await MediaHelper.createTestFile( TEST_IMAGE_PATH );
testAccount = new TestAccount( accountName );
editorPage = new EditorPage( page );
await testAccount.authenticate( page );
} );
it( 'Go to the new post page', async () => {
await editorPage.visit( 'post' );
} );
it( `Insert ${ PricingTableBlock.blockName } block and enter prices`, async function () {
const blockHandle = await editorPage.addBlockFromSidebar(
PricingTableBlock.blockName,
PricingTableBlock.blockEditorSelector
);
pricingTableBlock = new PricingTableBlock( page, blockHandle );
await pricingTableBlock.enterPrice( 1, pricingTableBlockPrices[ 0 ] );
await pricingTableBlock.enterPrice( 2, pricingTableBlockPrices[ 1 ] );
} );
it( `Insert ${ DynamicHRBlock.blockName } block`, async function () {
// Manual override of the Dyanmic HR/Separator block that comes with CoBlocks.
// On AT, the block is called Dynamic Separator.
// On Simple, the block is called Dynamic HR.
// See: https://github.com/Automattic/wp-calypso/issues/75092
if ( features.siteType === 'atomic' ) {
await editorPage.addBlockFromSidebar(
'Dynamic Separator',
'[aria-label="Block: Dynamic Separator"]'
);
} else {
await editorPage.addBlockFromSidebar(
DynamicHRBlock.blockName,
DynamicHRBlock.blockEditorSelector
);
}
} );
it( `Insert ${ HeroBlock.blockName } block and enter heading`, async function () {
const blockHandle = await editorPage.addBlockFromSidebar(
HeroBlock.blockName,
HeroBlock.blockEditorSelector
);
const heroBlock = new HeroBlock( blockHandle );
await heroBlock.enterHeading( heroBlockHeading );
} );
it( `Insert ${ ClicktoTweetBlock.blockName } block and enter tweet content`, async function () {
const blockHandle = await editorPage.addBlockFromSidebar(
ClicktoTweetBlock.blockName,
ClicktoTweetBlock.blockEditorSelector
);
const clickToTweetBlock = new ClicktoTweetBlock( blockHandle );
await clickToTweetBlock.enterTweetContent( clicktoTweetBlockTweet );
} );
it( `Insert ${ LogosBlock.blockName } block and set image`, async function () {
const blockHandle = await editorPage.addBlockFromSidebar(
LogosBlock.blockName,
LogosBlock.blockEditorSelector
);
const logosBlock = new LogosBlock( blockHandle );
await logosBlock.upload( logoImage.fullpath );
} );
it( 'Publish and visit the post', async function () {
await editorPage.publish( { visit: true } );
} );
// Pass in a 1D array of values or text strings to validate each block.
it.each`
block | content
${ PricingTableBlock } | ${ pricingTableBlockPrices }
${ DynamicHRBlock } | ${ null }
${ HeroBlock } | ${ [ heroBlockHeading ] }
${ ClicktoTweetBlock } | ${ [ clicktoTweetBlockTweet ] }
`(
'Confirm $block.blockName block is visible in published post',
async ( { block, content } ) => {
// Pass the Block object class here then call the static method to validate.
await block.validatePublishedContent( page, content );
}
);
it( 'Confirm Logos block is visible in published post', async () => {
await LogosBlock.validatePublishedContent( page, [ logoImage.filename ] );
} );
} );
|