diff --git a/projects/plugins/jetpack/changelog/e2e-subscription-block b/projects/plugins/jetpack/changelog/e2e-subscription-block new file mode 100644 index 000000000000..c12916dd8b16 --- /dev/null +++ b/projects/plugins/jetpack/changelog/e2e-subscription-block @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +E2E tests: add test for subscribe block diff --git a/projects/plugins/jetpack/tests/e2e/specs/blocks/free-blocks.test.js b/projects/plugins/jetpack/tests/e2e/specs/blocks/free-blocks.test.js index 495d8a3256ed..54b11e7f39ad 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/blocks/free-blocks.test.js +++ b/projects/plugins/jetpack/tests/e2e/specs/blocks/free-blocks.test.js @@ -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'; @@ -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(); + } ); + } ); } ); diff --git a/tools/e2e-commons/pages/wp-admin/blocks/subscribe.js b/tools/e2e-commons/pages/wp-admin/blocks/subscribe.js new file mode 100644 index 000000000000..f4a67561b7ef --- /dev/null +++ b/tools/e2e-commons/pages/wp-admin/blocks/subscribe.js @@ -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' ); + } +} diff --git a/tools/e2e-commons/pages/wp-admin/index.js b/tools/e2e-commons/pages/wp-admin/index.js index 56921e618ceb..cf86ba9c78cf 100644 --- a/tools/e2e-commons/pages/wp-admin/index.js +++ b/tools/e2e-commons/pages/wp-admin/index.js @@ -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';