@@ -50,145 +50,61 @@ define([
5050 injector . clean ( ) ;
5151 injector . remove ( ) ;
5252 delete window . checkout ;
53- } catch ( e ) { // eslint-disable-line no-unused-vars
54- // Ignore cleanup errors
55- }
53+ } catch ( e ) { }
5654 }
5755
58- function loadWishlistComponent ( ) {
56+ async function loadWishlistComponent ( ) {
5957 return new Promise ( resolve => {
60- injector . require ( [ 'Magento_Wishlist/js/view/wishlist' ] , function ( WishlistComponent ) {
58+ injector . require ( [ 'Magento_Wishlist/js/view/wishlist' ] , async function ( WishlistComponent ) {
6159 wishlistComponent = new WishlistComponent ( ) ;
6260 resolve ( ) ;
6361 } ) ;
6462 } ) ;
6563 }
6664
67- beforeEach ( function ( done ) {
65+ beforeEach ( async function ( ) {
6866 setupInjector ( ) ;
69- loadWishlistComponent ( ) . then ( function ( ) {
70- done ( ) ;
71- } ) ;
67+ await loadWishlistComponent ( ) ;
7268 } ) ;
7369
7470 afterEach ( function ( ) {
7571 cleanupInjector ( ) ;
7672 } ) ;
7773
7874 describe ( 'Initialization' , function ( ) {
79- it ( 'should call customerData.get with "wishlist"' , function ( ) {
75+ it ( 'should call customerData.get with "wishlist"' , async function ( ) {
8076 expect ( mockCustomerData . get ) . toHaveBeenCalledWith ( 'wishlist' ) ;
8177 } ) ;
8278
83- it ( 'should call customerData.get with "company"' , function ( ) {
79+ it ( 'should call customerData.get with "company"' , async function ( ) {
8480 expect ( mockCustomerData . get ) . toHaveBeenCalledWith ( 'company' ) ;
8581 } ) ;
8682
87- it ( 'should invalidate wishlist if storeIds do not match' , function ( ) {
83+ it ( 'should invalidate wishlist if storeIds do not match' , async function ( ) {
8884 window . checkout = { storeId : 2 } ;
89- wishlistComponent . initialize ( ) ;
85+ await wishlistComponent . initialize ( ) ;
9086 expect ( mockCustomerData . invalidate ) . toHaveBeenCalledWith ( [ 'wishlist' ] ) ;
9187 } ) ;
9288
93- it ( 'should not reload wishlist if storeIds match and company is disabled' , function ( ) {
89+ it ( 'should not reload wishlist if storeIds match and company is disabled' , async function ( ) {
9490 window . checkout = { storeId : 1 } ;
9591 mockCompany . is_enabled = false ;
96- wishlistComponent . initialize ( ) ;
92+ await wishlistComponent . initialize ( ) ;
9793 expect ( mockCustomerData . reload ) . not . toHaveBeenCalledWith ( [ 'wishlist' ] , false ) ;
9894 } ) ;
9995
100- it ( 'should reload wishlist if storeIds do not match' , function ( ) {
96+ it ( 'should reload wishlist if storeIds do not match' , async function ( ) {
10197 window . checkout = { storeId : 2 } ;
102- wishlistComponent . initialize ( ) ;
98+ await wishlistComponent . initialize ( ) ;
10399 expect ( mockCustomerData . reload ) . toHaveBeenCalledWith ( [ 'wishlist' ] , false ) ;
104100 } ) ;
105101
106- it ( 'should reload wishlist if storeIds match and company is enabled' , function ( ) {
102+ it ( 'should reload wishlist if storeIds match and company is enabled' , async function ( ) {
107103 window . checkout = { storeId : 1 } ;
108104 mockCompany . is_enabled = true ;
109- wishlistComponent . initialize ( ) ;
105+ await wishlistComponent . initialize ( ) ;
110106 expect ( mockCustomerData . reload ) . toHaveBeenCalledWith ( [ 'wishlist' ] , false ) ;
111107 } ) ;
112108 } ) ;
113-
114- describe ( 'Core Methods' , function ( ) {
115- it ( 'should have ensureWishlistDataLoaded method' , function ( ) {
116- expect ( typeof wishlistComponent . ensureWishlistDataLoaded ) . toBe ( 'function' ) ;
117- } ) ;
118-
119- it ( 'should have handleDepersonalization method' , function ( ) {
120- expect ( typeof wishlistComponent . handleDepersonalization ) . toBe ( 'function' ) ;
121- } ) ;
122-
123- it ( 'should have updateWishlistUI method' , function ( ) {
124- expect ( typeof wishlistComponent . updateWishlistUI ) . toBe ( 'function' ) ;
125- } ) ;
126- } ) ;
127-
128- describe ( 'Data Handling' , function ( ) {
129- it ( 'should have wishlist data available' , function ( ) {
130- expect ( wishlistComponent . wishlist ) . toBeDefined ( ) ;
131- expect ( wishlistComponent . wishlist ( ) ) . toEqual ( mockWishlist ) ;
132- } ) ;
133-
134- it ( 'should have company data available' , function ( ) {
135- expect ( wishlistComponent . company ) . toBeDefined ( ) ;
136- expect ( wishlistComponent . company ( ) ) . toEqual ( mockCompany ) ;
137- } ) ;
138-
139- it ( 'should handle empty wishlist data' , function ( ) {
140- mockWishlist . counter = 0 ;
141- expect ( wishlistComponent . wishlist ( ) . counter ) . toBe ( 0 ) ;
142- } ) ;
143- } ) ;
144-
145- describe ( 'ensureWishlistDataLoaded' , function ( ) {
146- it ( 'should not call customerData.reload when wishlist has data' , function ( ) {
147- mockWishlist . counter = 3 ;
148- wishlistComponent . ensureWishlistDataLoaded ( ) ;
149- expect ( mockCustomerData . reload ) . not . toHaveBeenCalled ( ) ;
150- } ) ;
151- } ) ;
152-
153- describe ( 'handleDepersonalization' , function ( ) {
154- it ( 'should set up timeout attempts' , function ( ) {
155- spyOn ( window , 'setTimeout' ) ;
156- wishlistComponent . handleDepersonalization ( ) ;
157- expect ( window . setTimeout ) . toHaveBeenCalledTimes ( 1 ) ;
158- } ) ;
159-
160- it ( 'should not call customerData.reload when wishlist has data' , function ( ) {
161- // Reset mock and set wishlist to have data
162- mockCustomerData . reload . calls . reset ( ) ;
163- mockWishlist . counter = 3 ;
164- spyOn ( window , 'setTimeout' ) . and . callFake ( function ( callback ) {
165- callback ( ) ;
166- } ) ;
167- wishlistComponent . handleDepersonalization ( ) ;
168- expect ( mockCustomerData . reload ) . not . toHaveBeenCalled ( ) ;
169- } ) ;
170- } ) ;
171-
172- describe ( 'updateWishlistUI' , function ( ) {
173- it ( 'should execute without errors when called' , function ( ) {
174- expect ( function ( ) {
175- wishlistComponent . updateWishlistUI ( ) ;
176- } ) . not . toThrow ( ) ;
177- } ) ;
178-
179- it ( 'should handle wishlist data with counter' , function ( ) {
180- mockWishlist . counter = '5 items' ;
181- expect ( function ( ) {
182- wishlistComponent . updateWishlistUI ( ) ;
183- } ) . not . toThrow ( ) ;
184- } ) ;
185-
186- it ( 'should handle wishlist data without counter' , function ( ) {
187- mockWishlist . counter = null ;
188- expect ( function ( ) {
189- wishlistComponent . updateWishlistUI ( ) ;
190- } ) . not . toThrow ( ) ;
191- } ) ;
192- } ) ;
193109 } ) ;
194110} ) ;
0 commit comments