33 */
44import {
55 clickButton ,
6- getAllBlocks ,
76 openDocumentSettingsSidebar ,
87 switchUserToAdmin ,
8+ getAllBlocks ,
99} from '@wordpress/e2e-test-utils' ;
1010import {
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
3031describe ( `${ 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} ) ;
0 commit comments