/** * External dependencies */ import { act, render, screen, waitFor, waitForElementToBeRemoved, } from '@testing-library/react'; import { previewCart } from '@woocommerce/resource-previews'; import { dispatch } from '@wordpress/data'; import { CART_STORE_KEY as storeKey } from '@woocommerce/block-data'; import { SlotFillProvider } from '@woocommerce/blocks-checkout'; import { default as fetchMock } from 'jest-fetch-mock'; import userEvent from '@testing-library/user-event'; /** * Internal dependencies */ import Block from '../block'; import { defaultCartState } from '../../../../data/default-states'; const MiniCartBlock = ( props ) => ( ); const mockEmptyCart = () => { fetchMock.mockResponse( ( req ) => { if ( req.url.match( /wc\/store\/cart/ ) ) { return Promise.resolve( JSON.stringify( defaultCartState.cartData ) ); } return Promise.resolve( '' ); } ); }; const mockFullCart = () => { fetchMock.mockResponse( ( req ) => { if ( req.url.match( /wc\/store\/cart/ ) ) { return Promise.resolve( JSON.stringify( previewCart ) ); } return Promise.resolve( '' ); } ); }; describe( 'Testing Mini Cart', () => { beforeEach( () => { act( () => { mockFullCart(); // need to clear the store resolution state between tests. dispatch( storeKey ).invalidateResolutionForStore(); dispatch( storeKey ).receiveCart( defaultCartState.cartData ); } ); } ); afterEach( () => { fetchMock.resetMocks(); } ); it( 'opens Mini Cart drawer when clicking on button', async () => { render( ); await waitFor( () => expect( fetchMock ).toHaveBeenCalled() ); act( () => { userEvent.click( screen.getByLabelText( /items/i ) ); } ); expect( fetchMock ).toHaveBeenCalledTimes( 1 ); // ["`select` control in `@wordpress/data-controls` is deprecated. Please use built-in `resolveSelect` control in `@wordpress/data` instead."] expect( console ).toHaveWarned(); } ); it( 'renders empty cart if there are no items in the cart', async () => { mockEmptyCart(); render( ); await waitFor( () => expect( fetchMock ).toHaveBeenCalled() ); act( () => { userEvent.click( screen.getByLabelText( /items/i ) ); } ); expect( fetchMock ).toHaveBeenCalledTimes( 1 ); } ); it( 'updates contents when removed from cart event is triggered', async () => { render( ); await waitFor( () => expect( fetchMock ).toHaveBeenCalled() ); mockEmptyCart(); // eslint-disable-next-line no-undef const removedFromCartEvent = new Event( 'wc-blocks_removed_from_cart' ); act( () => { document.body.dispatchEvent( removedFromCartEvent ); } ); await waitForElementToBeRemoved( () => screen.queryByLabelText( /3 items in cart/i ) ); await waitFor( () => expect( screen.getByLabelText( /0 items in cart/i ) ).toBeInTheDocument() ); } ); it( 'updates contents when added to cart event is triggered', async () => { mockEmptyCart(); render( ); await waitFor( () => expect( fetchMock ).toHaveBeenCalled() ); mockFullCart(); // eslint-disable-next-line no-undef const addedToCartEvent = new Event( 'wc-blocks_added_to_cart' ); act( () => { document.body.dispatchEvent( addedToCartEvent ); } ); await waitForElementToBeRemoved( () => screen.queryByLabelText( /0 items in cart/i ) ); await waitFor( () => expect( screen.getByLabelText( /3 items in cart/i ) ).toBeInTheDocument() ); } ); } ); - PONDOK MODERN ASSHOFWAN KLARI KARAWANG

2024-2025 مدرسة أشوفان الإسلامية الداخلية الحديثةجميع الحقوق محفوظة تصميم بواسطة Ust أسيب سونان أمبو

Donasi Sekarang

Related articles

Greatest Internet poker Websites for all of us Players 2025 Upgrade

ArticlesRanged Limits and you may Online game ModelsBankroll AdministrationThe...

Dolphin’s Pearl Luxury Trial Play Totally free Slot Online game

BlogsA couple of Models to pick fromDolphins Pearl 100...

Finest On line Blackjack 2025 : Canada’s Greatest Black-jack Websites

PostsPreferred HyperlinksDifferent types of Blackjack Game On line I published...

The newest 25 Wealthiest Somebody to the Egyptian Replace in the July 2024

ArticlesDouble Ruby Greatest Based on VegasSlotsOnline ProfessionalsRupert meets Dangote,...

Case Studies

روتين

أنشطة التمارين الصباحية لمستوى RA

أنشطة التمارين الصباحية لمستوى RA في مدرسة أشوان الإسلامية الداخلية، مدرسة أشوان الداخلية الحديثة— لدعم نمو وتطور الطفولة المبكرة وتكوين عادات معيشية صحية منذ الصغر.