Skip to content
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
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/e2e-subscription-block
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

E2E tests: add test for subscribe block
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EventbriteBlock,
FormBlock,
TiledGalleryBlock,
SubscribeBlock,
} from 'jetpack-e2e-commons/pages/wp-admin/index.js';
import { PostFrontendPage } from 'jetpack-e2e-commons/pages/index.js';
import config from 'config';
Expand Down Expand Up @@ -139,4 +140,31 @@ test.describe.parallel( 'Free blocks', () => {
).toBeTruthy();
} );
} );

test( 'Subscribe block', async ( { page } ) => {
await prerequisitesBuilder( page ).withActiveModules( [ 'subscriptions' ] ).build();

await test.step( 'Can visit the block editor and add a Subscribe block', async () => {
const blockId = await blockEditor.insertBlock(
SubscribeBlock.name(),
SubscribeBlock.title()
);
const block = new SubscribeBlock( blockId, page );
await block.checkBlock();
} );

await test.step( 'Can publish a post with a Subscribe block', async () => {
await blockEditor.selectPostTitle();
await blockEditor.publishPost();
await blockEditor.viewPost();
} );

await test.step( 'Can assert that Subscribe block is rendered', async () => {
const frontend = await PostFrontendPage.init( page );
expect(
await frontend.isRenderedBlockPresent( SubscribeBlock ),
'Block should be displayed'
).toBeTruthy();
} );
} );
} );
36 changes: 36 additions & 0 deletions tools/e2e-commons/pages/wp-admin/blocks/subscribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import PageActions from '../../page-actions.js';

export default class SubscribeBlock extends PageActions {
constructor( blockId, page ) {
super( page, 'Subscribe' );
this.blockTitle = SubscribeBlock.title();
this.page = page;
this.blockSelector = '#block-' + blockId;
}

static name() {
return 'subscriptions';
}

static title() {
return 'Subscribe';
}

async checkBlock() {
await this.page.waitForResponse(
r =>
decodeURIComponent( r.url() ).match( /wpcom\/v2\/subscribers\/counts/ ) &&
r.status() === 200
);
}

/**
* Checks whether block is rendered on frontend
*
* @param {page} page Playwright page instance
*/
static async isRendered( page ) {
await page.waitForSelector( '.wp-block-jetpack-subscriptions__container #subscribe-field-1' );
await page.waitForSelector( '.wp-block-jetpack-subscriptions__container button' );
}
}
1 change: 1 addition & 0 deletions tools/e2e-commons/pages/wp-admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { default as SimplePaymentBlock } from './blocks/simple-payments.js';
export { default as WordAdsBlock } from './blocks/word-ads.js';
export { default as FormBlock } from './blocks/form.js';
export { default as TiledGalleryBlock } from './blocks/tilled-gallery.js';
export { default as SubscribeBlock } from './blocks/subscribe.js';

export { default as DashboardPage } from './dashboard.js';
export { default as InPlacePlansPage } from './in-place-plans.js';
Expand Down