Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix/cart backend test (#4153)
Browse files Browse the repository at this point in the history
* Fix backend cart e2e test

* Adjust test structure

* Fix e2e checkout backend test.

Make sure the confirmation window is closed
  • Loading branch information
ralucaStan committed May 5, 2021
1 parent e14bda2 commit 36e316c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
70 changes: 36 additions & 34 deletions tests/e2e/specs/backend/cart.test.js
Expand Up @@ -3,9 +3,9 @@
*/
import {
clickButton,
getAllBlocks,
openDocumentSettingsSidebar,
switchUserToAdmin,
getAllBlocks,
} from '@wordpress/e2e-test-utils';
import {
findLabelWithText,
Expand All @@ -23,25 +23,14 @@ const block = {
class: '.wc-block-cart',
};

if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 )
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 ) {
// eslint-disable-next-line jest/no-focused-tests
test.only( `skipping ${ block.name } tests`, () => {} );
}

describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
} );

afterEach( async () => {
await page.evaluate( () => {
localStorage.removeItem(
'wc-blocks_dismissed_compatibility_notices'
);
} );
} );

describe( 'before compatibility notice is dismissed', () => {
beforeEach( async () => {
describe( `before compatibility notice is dismissed`, () => {
beforeAll( async () => {
await page.evaluate( () => {
localStorage.setItem(
'wc-blocks_dismissed_compatibility_notices',
Expand All @@ -51,6 +40,14 @@ describe( `${ block.name } Block`, () => {
await visitBlockPage( `${ block.name } Block` );
} );

afterEach( async () => {
await page.evaluate( () => {
localStorage.removeItem(
'wc-blocks_dismissed_compatibility_notices'
);
} );
} );

it( 'shows compatibility notice', async () => {
const compatibilityNoticeTitle = await page.$x(
`//h1[contains(text(), 'Compatibility notice')]`
Expand All @@ -59,42 +56,32 @@ describe( `${ block.name } Block`, () => {
} );
} );

describe( 'once compatibility notice is dismissed', () => {
beforeEach( async () => {
describe( 'after compatibility notice is dismissed', () => {
beforeAll( async () => {
await page.evaluate( () => {
localStorage.removeItem(
'wc-blocks_dismissed_compatibility_notices'
);
} );
await page.evaluate( () => {
localStorage.setItem(
'wc-blocks_dismissed_compatibility_notices',
'["cart"]'
);
} );
await switchUserToAdmin();
await visitBlockPage( `${ block.name } Block` );
} );

it( 'can only be inserted once', async () => {
await insertBlockDontWaitForInsertClose( block.name );
await closeInserter();
expect( await getAllBlocks() ).toHaveLength( 1 );
} );

it( 'renders without crashing', async () => {
await expect( page ).toRenderBlock( block );
} );

describe( 'attributes', () => {
beforeEach( async () => {
await openDocumentSettingsSidebar();
await page.click( block.class );
} );

it( 'can toggle Shipping calculator', async () => {
const selector = `${ block.class } .wc-block-components-totals-shipping__change-address-button`;
const toggleLabel = await findLabelWithText(
'Shipping calculator'
);
await expect( toggleLabel ).toToggleElement( selector );
} );
} );

it( 'shows empty cart when changing the view', async () => {
await page.waitForSelector( block.class ).catch( () => {
throw new Error(
Expand All @@ -121,5 +108,20 @@ describe( `${ block.name } Block`, () => {
'[hidden] .wc-block-cart__empty-cart__title'
);
} );

describe( 'attributes', () => {
beforeEach( async () => {
await openDocumentSettingsSidebar();
await page.click( block.class );
} );

it( 'can toggle Shipping calculator', async () => {
const selector = `${ block.class } .wc-block-components-totals-shipping__change-address-button`;
const toggleLabel = await findLabelWithText(
'Shipping calculator'
);
await expect( toggleLabel ).toToggleElement( selector );
} );
} );
} );
} );
37 changes: 20 additions & 17 deletions tests/e2e/specs/backend/checkout.test.js
Expand Up @@ -22,25 +22,14 @@ const block = {
class: '.wc-block-checkout',
};

if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 )
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 ) {
// eslint-disable-next-line jest/no-focused-tests
test.only( `skipping ${ block.name } tests`, () => {} );
}

describe( `${ block.name } Block`, () => {
beforeAll( async () => {
await switchUserToAdmin();
} );

afterEach( async () => {
await page.evaluate( () => {
localStorage.removeItem(
'wc-blocks_dismissed_compatibility_notices'
);
} );
} );

describe( 'before compatibility notice is dismissed', () => {
beforeEach( async () => {
describe( `before compatibility notice is dismissed`, () => {
beforeAll( async () => {
await page.evaluate( () => {
localStorage.setItem(
'wc-blocks_dismissed_compatibility_notices',
Expand All @@ -50,6 +39,14 @@ describe( `${ block.name } Block`, () => {
await visitBlockPage( `${ block.name } Block` );
} );

afterEach( async () => {
await page.evaluate( () => {
localStorage.removeItem(
'wc-blocks_dismissed_compatibility_notices'
);
} );
} );

it( 'shows compatibility notice', async () => {
const compatibilityNoticeTitle = await page.$x(
`//h1[contains(text(), 'Compatibility notice')]`
Expand All @@ -58,14 +55,20 @@ describe( `${ block.name } Block`, () => {
} );
} );

describe( 'once compatibility notice is dismissed', () => {
beforeEach( async () => {
describe( 'after compatibility notice is dismissed', () => {
beforeAll( async () => {
await page.evaluate( () => {
localStorage.removeItem(
'wc-blocks_dismissed_compatibility_notices'
);
} );
await page.evaluate( () => {
localStorage.setItem(
'wc-blocks_dismissed_compatibility_notices',
'["checkout"]'
);
} );
await switchUserToAdmin();
await visitBlockPage( `${ block.name } Block` );
} );

Expand Down

0 comments on commit 36e316c

Please sign in to comment.