From df7bb8d7b9a2685e950795b721209fb6a4ac8e6d Mon Sep 17 00:00:00 2001 From: Bart Kalisz Date: Tue, 28 May 2024 17:44:06 +0200 Subject: [PATCH] Blocks E2E: Clean up eslint comments after rules update (#47875) --- ...heckout-block.merchant.block_theme.spec.ts | 24 ++++++++++++------- .../product-button.block_theme.spec.ts | 24 +++++++------------ .../product-button.classic_theme.spec.ts | 12 ++++------ ...ge-image-next-previous.block_theme.spec.ts | 10 -------- ...uct-gallery-thumbnails.block_theme.spec.ts | 6 ----- .../products/products.block_theme.spec.ts | 2 -- ...oduct-template-compatibility-layer.spec.ts | 1 - .../templates/shop-page.block_theme.spec.ts | 8 +++---- .../changelog/47875-clean-up-eslint-comments | 4 ++++ 9 files changed, 34 insertions(+), 57 deletions(-) create mode 100644 plugins/woocommerce/changelog/47875-clean-up-eslint-comments diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/checkout/checkout-block.merchant.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/checkout/checkout-block.merchant.block_theme.spec.ts index 74bd07ee4f7..8eefbe84d19 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/checkout/checkout-block.merchant.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/checkout/checkout-block.merchant.block_theme.spec.ts @@ -11,8 +11,12 @@ import { REGULAR_PRICED_PRODUCT_NAME } from './constants'; declare global { interface Window { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - wcSettings: { storePages: any }; + wcSettings: { + storePages: { + terms: { permalink: string }; + privacy: { permalink: string }; + }; + }; } } const blockData: BlockData = { @@ -99,6 +103,7 @@ test.describe( 'Merchant → Checkout', () => { } ); test( 'Merchant can see T&S and Privacy Policy links without checkbox', async ( { + page, frontendUtils, checkoutPageObject, } ) => { @@ -120,15 +125,16 @@ test.describe( 'Merchant → Checkout', () => { .getByText( 'Privacy Policy' ) .first(); - const { termsPageUrl, privacyPageUrl } = - await frontendUtils.page.evaluate( () => { + const { termsPageUrl, privacyPageUrl } = await page.evaluate( + () => { + const { terms, privacy } = window.wcSettings.storePages; + return { - termsPageUrl: - window.wcSettings.storePages.terms.permalink, - privacyPageUrl: - window.wcSettings.storePages.privacy.permalink, + termsPageUrl: terms.permalink, + privacyPageUrl: privacy.permalink, }; - } ); + } + ); await expect( termsAndConditions ).toHaveAttribute( 'href', termsPageUrl diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.block_theme.spec.ts index eebc3df8328..146a3895c39 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.block_theme.spec.ts @@ -41,15 +41,11 @@ test.describe( `${ blockData.name } Block`, () => { .locator( '[data-product_id]' ) .getAttribute( 'data-product_id' ); - const productName = await page - .locator( `li.post-${ productId } h3` ) - .textContent(); + const productNameLocator = page.locator( `li.post-${ productId } h3` ); + await expect( productNameLocator ).not.toBeEmpty(); - // We want to fail the test if the product name is not found. - // eslint-disable-next-line playwright/no-conditional-in-test - if ( ! productName ) { - return test.fail( ! productName, 'Product name was not found' ); - } + const productName = + ( await productNameLocator.textContent() ) as string; await block.locator( 'loading' ).waitFor( { state: 'detached', @@ -82,15 +78,11 @@ test.describe( `${ blockData.name } Block`, () => { const productId = await button.getAttribute( 'data-product_id' ); - const productName = await page - .locator( `li.post-${ productId } h3` ) - .textContent(); + const productNameLocator = page.locator( `li.post-${ productId } h3` ); + await expect( productNameLocator ).not.toBeEmpty(); - // We want to fail the test if the product name is not found. - // eslint-disable-next-line playwright/no-conditional-in-test - if ( ! productName ) { - return test.fail( ! productName, 'Product name was not found' ); - } + const productName = + ( await productNameLocator.textContent() ) as string; await block.click(); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.classic_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.classic_theme.spec.ts index 7c7b1d538cb..9ecad5f986b 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.classic_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/product-button/product-button.classic_theme.spec.ts @@ -47,15 +47,11 @@ test.describe( `${ blockData.name } Block`, () => { .locator( '[data-product_id]' ) .getAttribute( 'data-product_id' ); - const productName = await page - .locator( `li.post-${ productId } h3` ) - .textContent(); + const productNameLocator = page.locator( `li.post-${ productId } h3` ); + await expect( productNameLocator ).not.toBeEmpty(); - // We want to fail the test if the product name is not found. - // eslint-disable-next-line playwright/no-conditional-in-test - if ( ! productName ) { - return test.fail( ! productName, 'Product name was not found' ); - } + const productName = + ( await productNameLocator.textContent() ) as string; await block.locator( 'loading' ).waitFor( { state: 'detached', diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image-next-previous/product-gallery-large-image-next-previous.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image-next-previous/product-gallery-large-image-next-previous.block_theme.spec.ts index 585b4b416aa..4b155b301af 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image-next-previous/product-gallery-large-image-next-previous.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-large-image-next-previous/product-gallery-large-image-next-previous.block_theme.spec.ts @@ -183,10 +183,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); @@ -255,10 +253,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); @@ -327,10 +323,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); @@ -382,10 +376,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); @@ -434,10 +426,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-thumbnails/product-gallery-thumbnails.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-thumbnails/product-gallery-thumbnails.block_theme.spec.ts index 6489dd44ea9..da7bd697ac8 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-thumbnails/product-gallery-thumbnails.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/product-gallery/inner-blocks/product-gallery-thumbnails/product-gallery-thumbnails.block_theme.spec.ts @@ -160,10 +160,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); @@ -239,10 +237,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); @@ -319,10 +315,8 @@ test.describe( `${ blockData.name }`, () => { 'woocommerce/product-image-gallery' ); const clientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await parentBlock.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( parentBlock ); diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/products/products.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/products/products.block_theme.spec.ts index 6d39647599f..6b154a3da98 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/products/products.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/products/products.block_theme.spec.ts @@ -133,10 +133,8 @@ for ( const { await editor.canvas.locator( 'body' ).click(); const block = await editor.getBlockByName( blockData.name ); - // eslint-disable-next-line playwright/no-conditional-in-test const clientId = ( await block.getAttribute( 'data-block' ) ) ?? ''; const parentClientId = - // eslint-disable-next-line playwright/no-conditional-in-test ( await editor.getBlockRootClientId( clientId ) ) ?? ''; await editor.selectBlocks( block ); await editor.insertBlock( diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts index 3f217007a50..371e93eaefd 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts @@ -90,7 +90,6 @@ test.describe( 'Compatibility Layer with Product Collection block', () => { ); } ); - // eslint-disable-next-line playwright/valid-describe-callback test.describe( 'Product Archive with Product Collection block', () => { for ( const scenario of singleOccurranceScenarios ) { test( `${ scenario.title } is attached to the page`, async ( { diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/templates/shop-page.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/templates/shop-page.block_theme.spec.ts index 46d95f6df18..d6093b2a16f 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/templates/shop-page.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/templates/shop-page.block_theme.spec.ts @@ -8,15 +8,13 @@ test.describe( 'Shop page', () => { admin, page, } ) => { - // Get Shop page ID. const cliOutput = await wpCLI( 'option get woocommerce_shop_page_id' ); - const numberMatch = cliOutput.stdout.match( /\d+/ ); - // eslint-disable-next-line playwright/no-conditional-in-test - if ( numberMatch === null ) { + const shopPageId = cliOutput.stdout.match( /\d+/ )?.pop(); + if ( ! shopPageId ) { throw new Error( 'Shop page ID not found' ); } - await admin.editPost( numberMatch[ 0 ] ); + await admin.editPost( shopPageId ); await expect( page.getByText( 'Template' ) ).toBeHidden(); } ); diff --git a/plugins/woocommerce/changelog/47875-clean-up-eslint-comments b/plugins/woocommerce/changelog/47875-clean-up-eslint-comments new file mode 100644 index 00000000000..1048778b297 --- /dev/null +++ b/plugins/woocommerce/changelog/47875-clean-up-eslint-comments @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Clean up eslint comments after rules update in Blocks E2E tests.