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

Commit 36e316c

Browse files
authored
Fix/cart backend test (#4153)
* Fix backend cart e2e test * Adjust test structure * Fix e2e checkout backend test. Make sure the confirmation window is closed
1 parent e14bda2 commit 36e316c

File tree

2 files changed

+56
-51
lines changed

2 files changed

+56
-51
lines changed

tests/e2e/specs/backend/cart.test.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44
import {
55
clickButton,
6-
getAllBlocks,
76
openDocumentSettingsSidebar,
87
switchUserToAdmin,
8+
getAllBlocks,
99
} from '@wordpress/e2e-test-utils';
1010
import {
1111
findLabelWithText,
@@ -23,25 +23,14 @@ const block = {
2323
class: '.wc-block-cart',
2424
};
2525

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

3031
describe( `${ block.name } Block`, () => {
31-
beforeAll( async () => {
32-
await switchUserToAdmin();
33-
} );
34-
35-
afterEach( async () => {
36-
await page.evaluate( () => {
37-
localStorage.removeItem(
38-
'wc-blocks_dismissed_compatibility_notices'
39-
);
40-
} );
41-
} );
42-
43-
describe( 'before compatibility notice is dismissed', () => {
44-
beforeEach( async () => {
32+
describe( `before compatibility notice is dismissed`, () => {
33+
beforeAll( async () => {
4534
await page.evaluate( () => {
4635
localStorage.setItem(
4736
'wc-blocks_dismissed_compatibility_notices',
@@ -51,6 +40,14 @@ describe( `${ block.name } Block`, () => {
5140
await visitBlockPage( `${ block.name } Block` );
5241
} );
5342

43+
afterEach( async () => {
44+
await page.evaluate( () => {
45+
localStorage.removeItem(
46+
'wc-blocks_dismissed_compatibility_notices'
47+
);
48+
} );
49+
} );
50+
5451
it( 'shows compatibility notice', async () => {
5552
const compatibilityNoticeTitle = await page.$x(
5653
`//h1[contains(text(), 'Compatibility notice')]`
@@ -59,42 +56,32 @@ describe( `${ block.name } Block`, () => {
5956
} );
6057
} );
6158

62-
describe( 'once compatibility notice is dismissed', () => {
63-
beforeEach( async () => {
59+
describe( 'after compatibility notice is dismissed', () => {
60+
beforeAll( async () => {
61+
await page.evaluate( () => {
62+
localStorage.removeItem(
63+
'wc-blocks_dismissed_compatibility_notices'
64+
);
65+
} );
6466
await page.evaluate( () => {
6567
localStorage.setItem(
6668
'wc-blocks_dismissed_compatibility_notices',
6769
'["cart"]'
6870
);
6971
} );
72+
await switchUserToAdmin();
7073
await visitBlockPage( `${ block.name } Block` );
7174
} );
7275

7376
it( 'can only be inserted once', async () => {
7477
await insertBlockDontWaitForInsertClose( block.name );
75-
await closeInserter();
7678
expect( await getAllBlocks() ).toHaveLength( 1 );
7779
} );
7880

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

83-
describe( 'attributes', () => {
84-
beforeEach( async () => {
85-
await openDocumentSettingsSidebar();
86-
await page.click( block.class );
87-
} );
88-
89-
it( 'can toggle Shipping calculator', async () => {
90-
const selector = `${ block.class } .wc-block-components-totals-shipping__change-address-button`;
91-
const toggleLabel = await findLabelWithText(
92-
'Shipping calculator'
93-
);
94-
await expect( toggleLabel ).toToggleElement( selector );
95-
} );
96-
} );
97-
9885
it( 'shows empty cart when changing the view', async () => {
9986
await page.waitForSelector( block.class ).catch( () => {
10087
throw new Error(
@@ -121,5 +108,20 @@ describe( `${ block.name } Block`, () => {
121108
'[hidden] .wc-block-cart__empty-cart__title'
122109
);
123110
} );
111+
112+
describe( 'attributes', () => {
113+
beforeEach( async () => {
114+
await openDocumentSettingsSidebar();
115+
await page.click( block.class );
116+
} );
117+
118+
it( 'can toggle Shipping calculator', async () => {
119+
const selector = `${ block.class } .wc-block-components-totals-shipping__change-address-button`;
120+
const toggleLabel = await findLabelWithText(
121+
'Shipping calculator'
122+
);
123+
await expect( toggleLabel ).toToggleElement( selector );
124+
} );
125+
} );
124126
} );
125127
} );

tests/e2e/specs/backend/checkout.test.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,14 @@ const block = {
2222
class: '.wc-block-checkout',
2323
};
2424

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

2930
describe( `${ block.name } Block`, () => {
30-
beforeAll( async () => {
31-
await switchUserToAdmin();
32-
} );
33-
34-
afterEach( async () => {
35-
await page.evaluate( () => {
36-
localStorage.removeItem(
37-
'wc-blocks_dismissed_compatibility_notices'
38-
);
39-
} );
40-
} );
41-
42-
describe( 'before compatibility notice is dismissed', () => {
43-
beforeEach( async () => {
31+
describe( `before compatibility notice is dismissed`, () => {
32+
beforeAll( async () => {
4433
await page.evaluate( () => {
4534
localStorage.setItem(
4635
'wc-blocks_dismissed_compatibility_notices',
@@ -50,6 +39,14 @@ describe( `${ block.name } Block`, () => {
5039
await visitBlockPage( `${ block.name } Block` );
5140
} );
5241

42+
afterEach( async () => {
43+
await page.evaluate( () => {
44+
localStorage.removeItem(
45+
'wc-blocks_dismissed_compatibility_notices'
46+
);
47+
} );
48+
} );
49+
5350
it( 'shows compatibility notice', async () => {
5451
const compatibilityNoticeTitle = await page.$x(
5552
`//h1[contains(text(), 'Compatibility notice')]`
@@ -58,14 +55,20 @@ describe( `${ block.name } Block`, () => {
5855
} );
5956
} );
6057

61-
describe( 'once compatibility notice is dismissed', () => {
62-
beforeEach( async () => {
58+
describe( 'after compatibility notice is dismissed', () => {
59+
beforeAll( async () => {
60+
await page.evaluate( () => {
61+
localStorage.removeItem(
62+
'wc-blocks_dismissed_compatibility_notices'
63+
);
64+
} );
6365
await page.evaluate( () => {
6466
localStorage.setItem(
6567
'wc-blocks_dismissed_compatibility_notices',
6668
'["checkout"]'
6769
);
6870
} );
71+
await switchUserToAdmin();
6972
await visitBlockPage( `${ block.name } Block` );
7073
} );
7174

0 commit comments

Comments
 (0)