@shopgate/pwa-common-commerce 7.30.0-alpha.6 → 7.30.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cart/action-creators/addCouponsToCart.js +9 -2
- package/cart/action-creators/addProductsToCart.js +9 -2
- package/cart/action-creators/deleteCouponsFromCart.js +9 -2
- package/cart/action-creators/deleteProductsFromCart.js +9 -2
- package/cart/action-creators/errorAddCouponsToCart.js +10 -2
- package/cart/action-creators/errorAddProductsToCart.js +10 -2
- package/cart/action-creators/errorCart.js +8 -2
- package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
- package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
- package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
- package/cart/action-creators/receiveCart.js +9 -2
- package/cart/action-creators/requestCart.js +8 -2
- package/cart/action-creators/setCartProductPendingCount.js +9 -2
- package/cart/action-creators/setCouponFieldError.js +9 -2
- package/cart/action-creators/setCouponFieldValue.js +9 -2
- package/cart/action-creators/setFulfillmentSlot.js +9 -2
- package/cart/action-creators/successAddCouponsToCart.js +10 -2
- package/cart/action-creators/successAddProductsToCart.js +8 -2
- package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
- package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
- package/cart/action-creators/successUpdateProductsInCart.js +8 -2
- package/cart/action-creators/updateProductsInCart.js +9 -2
- package/cart/actions/addCouponsToCart.js +52 -8
- package/cart/actions/addProductsToCart.js +80 -11
- package/cart/actions/deleteCouponsFromCart.js +39 -6
- package/cart/actions/deleteProductsFromCart.js +38 -6
- package/cart/actions/fetchCart.js +52 -8
- package/cart/actions/updateProductsInCart.js +44 -6
- package/cart/constants/PipelineErrors.js +6 -1
- package/cart/constants/Pipelines.js +6 -1
- package/cart/constants/Portals.js +85 -1
- package/cart/constants/index.js +39 -2
- package/cart/helpers/config.js +47 -2
- package/cart/helpers/createPipelineErrorList.js +30 -4
- package/cart/helpers/fulfillmentSlots.js +37 -4
- package/cart/helpers/index.js +14 -3
- package/cart/helpers/quantity.js +23 -4
- package/cart/helpers/shipping.js +57 -2
- package/cart/helpers/tax.js +26 -2
- package/cart/index.js +25 -5
- package/cart/mock.js +130 -1
- package/cart/reducers/couponField.js +30 -2
- package/cart/reducers/data.js +98 -6
- package/cart/reducers/index.js +7 -1
- package/cart/selectors/index.js +181 -31
- package/cart/selectors/spec.js +189 -2
- package/cart/streams/index.js +176 -29
- package/cart/subscriptions/index.js +307 -30
- package/category/action-creators/errorCategory.js +10 -2
- package/category/action-creators/errorCategoryChildren.js +9 -2
- package/category/action-creators/errorRootCategories.js +8 -2
- package/category/action-creators/receiveCategory.js +12 -2
- package/category/action-creators/receiveCategoryChildren.js +10 -2
- package/category/action-creators/receiveRootCategories.js +9 -2
- package/category/action-creators/requestCategory.js +9 -2
- package/category/action-creators/requestCategoryChildren.js +9 -2
- package/category/action-creators/requestRootCategories.js +8 -2
- package/category/actions/fetchCategory.js +47 -5
- package/category/actions/fetchCategoryChildren.js +30 -2
- package/category/actions/fetchCategoryOrRootCategories.js +16 -2
- package/category/actions/fetchCategoryProducts.js +36 -2
- package/category/actions/fetchRootCategories.js +31 -2
- package/category/actions/getCategory.js +10 -2
- package/category/constants/Pipelines.js +3 -1
- package/category/constants/Portals.js +56 -3
- package/category/constants/index.js +17 -2
- package/category/helpers/index.js +27 -3
- package/category/index.js +19 -5
- package/category/mock.js +176 -1
- package/category/reducers/categoriesById.js +65 -3
- package/category/reducers/childrenByCategoryId.js +55 -4
- package/category/reducers/helpers/handleCategoryCollection.js +24 -3
- package/category/reducers/helpers/handleReceivedCategories.js +3 -1
- package/category/reducers/index.js +12 -2
- package/category/reducers/rootCategories.js +31 -2
- package/category/selectors/index.js +115 -16
- package/category/streams/index.js +82 -4
- package/category/subscriptions/index.js +96 -3
- package/checkout/action-creators/successCheckout.js +9 -2
- package/checkout/actions/fetchCheckoutUrl.js +28 -3
- package/checkout/constants/Pipelines.js +1 -1
- package/checkout/constants/index.js +3 -2
- package/checkout/index.js +11 -4
- package/checkout/selectors/index.js +7 -2
- package/checkout/streams/index.js +8 -2
- package/checkout/subscriptions/index.js +35 -6
- package/favorites/action-creators/index.js +206 -24
- package/favorites/actions/addFavorites.js +41 -3
- package/favorites/actions/addFavoritesList.js +27 -2
- package/favorites/actions/fetchFavoriteIds.js +49 -5
- package/favorites/actions/fetchFavorites.js +60 -5
- package/favorites/actions/fetchFavoritesList.js +47 -3
- package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
- package/favorites/actions/getFavorites.js +6 -2
- package/favorites/actions/removeFavorites.js +32 -3
- package/favorites/actions/removeFavoritesList.js +24 -2
- package/favorites/actions/toggleFavorites.js +68 -10
- package/favorites/actions/updateFavorites.js +39 -3
- package/favorites/actions/updateFavoritesList.js +26 -2
- package/favorites/constants/Pipelines.js +9 -1
- package/favorites/constants/Portals.js +32 -4
- package/favorites/constants/index.js +37 -5
- package/favorites/index.js +14 -4
- package/favorites/mock.js +89 -4
- package/favorites/reducers/index.js +7 -1
- package/favorites/reducers/lists.js +74 -2
- package/favorites/reducers/products.js +231 -24
- package/favorites/selectors/index.js +188 -24
- package/favorites/streams/index.js +135 -23
- package/favorites/streams/spec.js +517 -8
- package/favorites/subscriptions/index.js +260 -25
- package/favorites/subscriptions/spec.js +701 -28
- package/filter/action-creators/errorFilters.js +9 -2
- package/filter/action-creators/index.js +4 -1
- package/filter/action-creators/receiveFilters.js +10 -2
- package/filter/action-creators/requestFilters.js +9 -2
- package/filter/action-creators/updateFilters.js +8 -2
- package/filter/actions/fetchFilters.js +46 -3
- package/filter/actions/getFilters.js +6 -2
- package/filter/actions/helpers/buildFilterParams.js +34 -2
- package/filter/actions/helpers/buildRequestFilters.js +35 -2
- package/filter/actions/helpers/processFilters.js +10 -2
- package/filter/actions/helpers/processParams.js +26 -2
- package/filter/constants/Pipelines.js +1 -1
- package/filter/constants/Portals.js +39 -3
- package/filter/constants/index.js +8 -1
- package/filter/index.js +12 -4
- package/filter/reducers/helpers/enrichFilters.js +11 -3
- package/filter/reducers/index.js +5 -1
- package/filter/reducers/resultsByHash.js +43 -3
- package/filter/selectors/index.js +47 -6
- package/filter/streams/index.js +30 -1
- package/filter/subscriptions/index.js +34 -2
- package/market/constants/Portals.js +22 -4
- package/market/constants/index.js +2 -1
- package/market/helpers/showReturnPolicy.js +3 -1
- package/market/helpers/showTaxDisclaimer.js +3 -1
- package/market/index.js +6 -2
- package/orders/constants.js +2 -1
- package/package.json +3 -3
- package/product/action-creators/deleteProductsByIds.js +10 -2
- package/product/action-creators/errorProduct.js +10 -2
- package/product/action-creators/errorProductDescription.js +10 -2
- package/product/action-creators/errorProductImages.js +10 -2
- package/product/action-creators/errorProductMedia.js +10 -2
- package/product/action-creators/errorProductOptions.js +10 -2
- package/product/action-creators/errorProductProperties.js +10 -2
- package/product/action-creators/errorProductRelations.js +9 -2
- package/product/action-creators/errorProductShipping.js +10 -2
- package/product/action-creators/errorProductVariants.js +10 -2
- package/product/action-creators/errorProducts.js +9 -2
- package/product/action-creators/expireProductById.js +10 -2
- package/product/action-creators/expireProductData.js +11 -2
- package/product/action-creators/expireProductsByHash.js +9 -2
- package/product/action-creators/productNotAvailable.js +10 -2
- package/product/action-creators/provideProduct.js +9 -2
- package/product/action-creators/receiveProduct.js +10 -2
- package/product/action-creators/receiveProductCached.js +9 -2
- package/product/action-creators/receiveProductDescription.js +10 -2
- package/product/action-creators/receiveProductImages.js +10 -2
- package/product/action-creators/receiveProductMedia.js +10 -2
- package/product/action-creators/receiveProductOptions.js +10 -2
- package/product/action-creators/receiveProductProperties.js +10 -2
- package/product/action-creators/receiveProductRelations.js +12 -2
- package/product/action-creators/receiveProductShipping.js +10 -2
- package/product/action-creators/receiveProductVariants.js +10 -2
- package/product/action-creators/receiveProducts.js +16 -2
- package/product/action-creators/receiveProductsCached.js +9 -2
- package/product/action-creators/refreshExpiredPDPData.js +8 -2
- package/product/action-creators/requestProduct.js +10 -2
- package/product/action-creators/requestProductDescription.js +9 -2
- package/product/action-creators/requestProductImages.js +9 -2
- package/product/action-creators/requestProductMedia.js +9 -2
- package/product/action-creators/requestProductOptions.js +9 -2
- package/product/action-creators/requestProductProperties.js +9 -2
- package/product/action-creators/requestProductRelations.js +10 -2
- package/product/action-creators/requestProductShipping.js +9 -2
- package/product/action-creators/requestProductVariants.js +9 -2
- package/product/action-creators/requestProducts.js +9 -2
- package/product/action-creators/setProductId.js +9 -2
- package/product/action-creators/setProductQuantity.js +9 -2
- package/product/action-creators/setProductVariantId.js +9 -2
- package/product/actions/changeSortOrder.js +21 -2
- package/product/actions/fetchHighlightProducts.js +18 -2
- package/product/actions/fetchLiveshoppingProducts.js +14 -2
- package/product/actions/fetchProduct.js +52 -3
- package/product/actions/fetchProductDescription.js +30 -2
- package/product/actions/fetchProductImages.js +31 -2
- package/product/actions/fetchProductMedia.js +35 -2
- package/product/actions/fetchProductOptions.js +31 -2
- package/product/actions/fetchProductProperties.js +30 -2
- package/product/actions/fetchProductRelations.js +63 -2
- package/product/actions/fetchProductShipping.js +31 -2
- package/product/actions/fetchProductVariants.js +31 -2
- package/product/actions/fetchProducts.js +189 -17
- package/product/actions/fetchProductsById.js +68 -8
- package/product/actions/fetchProductsByQuery.js +102 -18
- package/product/actions/getHighlightProducts.js +6 -2
- package/product/actions/getLiveshoppingProducts.js +6 -2
- package/product/actions/getProduct.js +6 -2
- package/product/actions/getProductDescription.js +6 -2
- package/product/actions/getProductImages.js +6 -2
- package/product/actions/getProductOptions.js +6 -2
- package/product/actions/getProductProperties.js +6 -2
- package/product/actions/getProductRelations.js +6 -2
- package/product/actions/getProductShipping.js +6 -2
- package/product/actions/getProductVariants.js +6 -2
- package/product/actions/getProducts.js +6 -2
- package/product/actions/getProductsById.js +6 -2
- package/product/actions/getProductsByQuery.js +6 -2
- package/product/actions/processProductFlags.js +35 -3
- package/product/actions/updateMetadata.js +17 -2
- package/product/collections/ProductImageFormats.js +48 -8
- package/product/collections/index.js +1 -1
- package/product/constants/Pipelines.js +12 -1
- package/product/constants/Portals.js +200 -33
- package/product/constants/index.js +90 -18
- package/product/helpers/index.js +61 -8
- package/product/index.js +36 -6
- package/product/mock.js +1002 -2
- package/product/reducers/descriptionsByProductId.js +54 -5
- package/product/reducers/helpers/formatOptions.js +17 -2
- package/product/reducers/helpers/handleProductCollection.js +19 -2
- package/product/reducers/imagesByProductId.js +51 -4
- package/product/reducers/index.js +23 -1
- package/product/reducers/mediaByProductId.js +55 -3
- package/product/reducers/optionsByProductId.js +41 -2
- package/product/reducers/productRelationsByHash.js +43 -2
- package/product/reducers/productsById.js +122 -7
- package/product/reducers/propertiesByProductId.js +48 -2
- package/product/reducers/resultsByHash.js +125 -9
- package/product/reducers/shippingByProductId.js +37 -2
- package/product/reducers/variantsByProductId.js +56 -2
- package/product/selectors/options.js +90 -13
- package/product/selectors/page.js +62 -13
- package/product/selectors/price.js +81 -18
- package/product/selectors/product.js +549 -59
- package/product/selectors/product.mock.js +327 -12
- package/product/selectors/relations.js +35 -5
- package/product/selectors/variants.js +91 -15
- package/product/streams/index.js +167 -13
- package/product/subscriptions/index.js +210 -4
- package/reviews/action-creators/errorProductReviews.js +9 -2
- package/reviews/action-creators/errorReviews.js +9 -2
- package/reviews/action-creators/errorSubmitReview.js +9 -2
- package/reviews/action-creators/errorUserReview.js +9 -2
- package/reviews/action-creators/flushUserReview.js +8 -2
- package/reviews/action-creators/receiveProductReviews.js +11 -2
- package/reviews/action-creators/receiveReviews.js +12 -2
- package/reviews/action-creators/receiveSubmitReview.js +9 -2
- package/reviews/action-creators/receiveUserReview.js +10 -2
- package/reviews/action-creators/requestProductReviews.js +10 -2
- package/reviews/action-creators/requestReviews.js +9 -2
- package/reviews/action-creators/requestSubmitReview.js +9 -2
- package/reviews/action-creators/requestUserReview.js +9 -2
- package/reviews/action-creators/resetSubmittedReview.js +9 -2
- package/reviews/action-creators/spec.js +40 -1
- package/reviews/actions/fetchProductReviews.js +37 -2
- package/reviews/actions/fetchReviews.js +38 -2
- package/reviews/actions/fetchUserReview.js +31 -2
- package/reviews/actions/flushUserReview.js +5 -1
- package/reviews/actions/getProductReviews.js +6 -2
- package/reviews/actions/getUserReview.js +6 -2
- package/reviews/actions/spec.js +241 -4
- package/reviews/actions/submitReview.js +63 -3
- package/reviews/constants/Pipelines.js +4 -1
- package/reviews/constants/Portals.js +4 -1
- package/reviews/constants/index.js +26 -7
- package/reviews/index.js +15 -4
- package/reviews/mock.js +172 -11
- package/reviews/reducers/index.js +11 -1
- package/reviews/reducers/mock.js +14 -2
- package/reviews/reducers/reviewsByHash.js +52 -6
- package/reviews/reducers/reviewsById.js +27 -2
- package/reviews/reducers/reviewsByProductId.js +47 -2
- package/reviews/reducers/spec.js +211 -2
- package/reviews/reducers/userReviewsByProductId.js +68 -2
- package/reviews/selectors/index.js +123 -19
- package/reviews/selectors/mock.js +100 -1
- package/reviews/selectors/spec.js +100 -1
- package/reviews/streams/index.js +37 -5
- package/reviews/streams/spec.js +25 -1
- package/reviews/subscriptions/index.js +27 -2
- package/scanner/action-creators/errorHandleScanner.js +11 -2
- package/scanner/action-creators/scannerFinished.js +11 -2
- package/scanner/action-creators/startScanner.js +8 -2
- package/scanner/action-creators/successHandleScanner.js +11 -2
- package/scanner/actions/handleBarCode.js +22 -2
- package/scanner/actions/handleNoResults.js +23 -2
- package/scanner/actions/handleQrCode.js +116 -6
- package/scanner/actions/handleSearch.js +33 -2
- package/scanner/constants/Portals.js +22 -1
- package/scanner/constants/index.js +17 -1
- package/scanner/helpers/index.js +115 -5
- package/scanner/index.js +19 -5
- package/scanner/streams/index.js +36 -1
- package/scanner/subscriptions/index.js +78 -8
- package/search/action-creators/errorSearchResults.js +10 -2
- package/search/action-creators/receiveSearchResults.js +11 -2
- package/search/action-creators/receiveSearchSuggestions.js +10 -2
- package/search/action-creators/requestSearchResults.js +10 -2
- package/search/action-creators/requestSearchSuggestions.js +9 -2
- package/search/actions/fetchSearchResults.js +66 -8
- package/search/actions/fetchSearchSuggestions.js +36 -2
- package/search/constants/Pipelines.js +1 -1
- package/search/constants/Portals.js +9 -2
- package/search/constants/index.js +10 -2
- package/search/helpers/index.js +5 -2
- package/search/helpers/removeHighlightingPlaceholders.js +4 -1
- package/search/helpers/spec.js +19 -1
- package/search/index.js +17 -5
- package/search/reducers/index.js +38 -2
- package/search/selectors/index.js +23 -4
- package/search/streams/index.js +51 -3
- package/search/subscriptions/index.js +132 -5
|
@@ -1,8 +1,517 @@
|
|
|
1
|
-
/* eslint-disable extra-rules/no-single-line-objects */
|
|
2
|
-
jest.mock('@shopgate/pwa-core',function(){return{UIEvents:{emit:jest.fn(),on:jest.fn(),addListener:jest.fn(),removeListener:jest.fn()}};});describe('Favorites streams',function(){var DUMMY_ACTION='DUMMY_ACTION';var subscriber;beforeEach(function(){subscriber=jest.fn();});describe('favoritesWillEnter$',function(){it('should call subscribers when the favorites page will open',function(){favoritesWillEnter$.subscribe(subscriber);mainSubject.next({action:{type:ROUTE_WILL_ENTER,route:{pattern:FAVORITES_PATH}}});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the path does not match',function(){favoritesWillEnter$.subscribe(subscriber);mainSubject.next({action:{type:ROUTE_WILL_ENTER,route:{pattern:'/other_path'}}});expect(subscriber).toHaveBeenCalledTimes(0);});it('should not call subscribers when the action does not match',function(){favoritesWillEnter$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION,route:{pattern:FAVORITES_PATH}}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('addProductToFavoritesDebounced$',function(){afterEach(function(){jest.useRealTimers();});it('should call subscribers only once, when the action is triggered multiple times',function(){jest.useFakeTimers();addProductToFavoritesDebounced$.subscribe(subscriber);var action=addProductToFavorites('product1');mainSubject.next({action:action});mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);expect(subscriber).toHaveBeenCalledTimes(1);});it('should call subscribers twice, when debounce time has passed',function(){jest.useFakeTimers();addProductToFavoritesDebounced$.subscribe(subscriber);var action=addProductToFavorites('product1');mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);expect(subscriber).toHaveBeenCalledTimes(2);});it('should not call subscribers when the action does not match',function(){addProductToFavoritesDebounced$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('removeProductFromFavoritesDebounced$',function(){afterEach(function(){jest.useRealTimers();});it('should call subscribers only once, when the action is triggered multiple times',function(){jest.useFakeTimers();removeProductFromFavoritesDebounced$.subscribe(subscriber);var action=removeProductFromFavorites('product1',true);mainSubject.next({action:action});mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);expect(subscriber).toHaveBeenCalledTimes(1);});it('should call subscribers twice, when debounce time has passed',function(){jest.useFakeTimers();removeProductFromFavoritesDebounced$.subscribe(subscriber);var action=removeProductFromFavorites('product1',true);mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);expect(subscriber).toHaveBeenCalledTimes(2);});it('should not call subscribers when the action does not match',function(){removeProductFromFavoritesDebounced$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('favoritesError$',function(){var actionTypes=[ERROR_FETCH_FAVORITES,ERROR_ADD_FAVORITES,ERROR_REMOVE_FAVORITES,ERROR_FAVORITES,DUMMY_ACTION];it('should call subscribers for every dispatched favorites error and no others',function(){favoritesError$.subscribe(subscriber);actionTypes.forEach(function(type){mainSubject.next({action:{type:type}});});expect(subscriber).toHaveBeenCalledTimes(4);});});describe('errorFavoritesLimit$',function(){it('should call subscribers only for the internal favorites limit error and no others',function(){errorFavoritesLimit$.subscribe(subscriber);mainSubject.next({action:{type:ERROR_FAVORITES,error:{code:FAVORITES_LIMIT_ERROR}}});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){errorFavoritesLimit$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});it('should not call subscribers on any other internal favorites error',function(){errorFavoritesLimit$.subscribe(subscriber);mainSubject.next({action:{type:ERROR_FAVORITES,error:{code:'SOME_OTHER_CODE'}}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('shouldFetchFavorites$',function(){it('should call subscribers to fetch favorites on every app start and on route enter',function(){shouldFetchFavorites$.subscribe(subscriber);mainSubject.next({action:{type:APP_DID_START}});mainSubject.next({action:{type:ROUTE_WILL_ENTER,route:{pattern:FAVORITES_PATH}}});expect(subscriber).toHaveBeenCalledTimes(2);});it('should call subscribers on any other action',function(){shouldFetchFavorites$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('shouldFetchFreshFavorites$',function(){it('should call subscribers to fetch fresh favorites on every login and logout',function(){shouldFetchFreshFavorites$.subscribe(subscriber);mainSubject.next({action:{type:SUCCESS_LOGIN}});mainSubject.next({action:{type:SUCCESS_LOGOUT}});expect(subscriber).toHaveBeenCalledTimes(2);});it('should call subscribers on any other action',function(){shouldFetchFreshFavorites$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('favoritesDidUpdate$',function(){var actionTypes=[REQUEST_ADD_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,RECEIVE_FAVORITES,ERROR_FETCH_FAVORITES,DUMMY_ACTION];it('should call subscribers for every dispatched favorites update and no others',function(){favoritesDidUpdate$.subscribe(subscriber);actionTypes.forEach(function(type){mainSubject.next({action:{type:type}});});expect(subscriber).toHaveBeenCalledTimes(6);});});describe('favoritesWillAddItem$',function(){it('should call subscribers for every favorite to be added',function(){favoritesWillAddItem$.subscribe(subscriber);mainSubject.next({action:requestAddFavorites('product1')});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){favoritesWillAddItem$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('favoritesDidAddItem$',function(){it('should call subscribers for every favorite that was added',function(){favoritesDidAddItem$.subscribe(subscriber);mainSubject.next({action:successAddFavorites('product1')});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){favoritesDidAddItem$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('favoritesWillRemoveItem$',function(){it('should call subscribers for every favorite to be removed',function(){favoritesWillRemoveItem$.subscribe(subscriber);mainSubject.next({action:requestRemoveFavorites('product1')(function(action){return action;},function(){return{};})});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){favoritesWillRemoveItem$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('favoritesDidRemoveItem$',function(){it('should call subscribers for every favorite that was removed',function(){favoritesDidRemoveItem$.subscribe(subscriber);mainSubject.next({action:successRemoveFavorites('product1')});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){favoritesDidRemoveItem$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('receiveFavorites$',function(){it('should call subscribers for every receive favorites action',function(){receiveFavorites$.subscribe(subscriber);mainSubject.next({action:receiveFavorites()});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){receiveFavorites$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('favoritesSyncIdle$',function(){it('should call subscribers for every sync idle call',function(){favoritesSyncIdle$.subscribe(subscriber);mainSubject.next({action:idleSyncFavorites()});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){favoritesSyncIdle$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('refreshFavorites$',function(){afterEach(function(){jest.useRealTimers();});it('should call subscribers only once, when the action is triggered multiple times',function(){jest.useFakeTimers();refreshFavorites$.subscribe(subscriber);var action=idleSyncFavorites();mainSubject.next({action:action});mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);expect(subscriber).toHaveBeenCalledTimes(1);});it('should call subscribers twice, when debounce time has passed',function(){jest.useFakeTimers();refreshFavorites$.subscribe(subscriber);var action=idleSyncFavorites();mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);mainSubject.next({action:action});jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);expect(subscriber).toHaveBeenCalledTimes(2);});it('should not call subscribers when the action does not match',function(){refreshFavorites$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('didRequestChangeFavorites$',function(){it('should call subscribers for every actual add or remove request',function(){didRequestChangeFavorites$.subscribe(subscriber);mainSubject.next({action:requestAddFavorites('product1')});mainSubject.next({action:requestRemoveFavorites('product2',false)(function(actionInner){return actionInner;},function(){return{};})});expect(subscriber).toHaveBeenCalledTimes(2);});it('should not call subscribers when the action does not match',function(){didRequestChangeFavorites$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('didRequestFlushFavoritesBuffer$',function(){it('should call subscribers for every buffer flush request',function(){didRequestFlushFavoritesBuffer$.subscribe(subscriber);mainSubject.next({action:requestFlushFavoritesBuffer()});expect(subscriber).toHaveBeenCalledTimes(1);});it('should not call subscribers when the action does not match',function(){didRequestFlushFavoritesBuffer$.subscribe(subscriber);mainSubject.next({action:{type:DUMMY_ACTION}});expect(subscriber).toHaveBeenCalledTimes(0);});});describe('didReceiveFlushFavoritesBuffer$',function(){it('should call subscribers with the full action buffer when the buffer period has passed',function(){jest.useFakeTimers();var bufferedActions=[{action:requestAddFavorites('product1')},{action:requestAddFavorites('product2')},{action:requestRemoveFavorites('product2',false)},{action:requestAddFavorites('product2')}];didReceiveFlushFavoritesBuffer$.subscribe(subscriber);// Pump all actions into the buffer
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/* eslint-disable extra-rules/no-single-line-objects */
|
|
2
|
+
import { mainSubject } from '@shopgate/pwa-common/store/middelwares/streams';
|
|
3
|
+
import { APP_DID_START, ROUTE_WILL_ENTER, SUCCESS_LOGIN, SUCCESS_LOGOUT } from '@shopgate/pwa-common/constants/ActionTypes';
|
|
4
|
+
import { favoritesWillEnter$, addProductToFavoritesDebounced$, removeProductFromFavoritesDebounced$, favoritesError$, errorFavoritesLimit$, shouldFetchFavorites$, shouldFetchFreshFavorites$, favoritesDidUpdate$, favoritesWillAddItem$, favoritesDidAddItem$, favoritesWillRemoveItem$, favoritesDidRemoveItem$, receiveFavorites$, favoritesSyncIdle$, refreshFavorites$, didRequestChangeFavorites$, didRequestFlushFavoritesBuffer$, didReceiveFlushFavoritesBuffer$ } from "./index";
|
|
5
|
+
import { FAVORITES_PATH, RECEIVE_FAVORITES, ERROR_FAVORITES, ERROR_FETCH_FAVORITES, REQUEST_ADD_FAVORITES, ERROR_ADD_FAVORITES, REQUEST_REMOVE_FAVORITES, ERROR_REMOVE_FAVORITES, FAVORITES_LIMIT_ERROR, FAVORITE_ACTION_BUFFER_TIME, FAVORITE_BUTTON_DEBOUNCE_TIME } from "../constants";
|
|
6
|
+
import { addProductToFavorites, removeProductFromFavorites, requestAddFavorites, requestRemoveFavorites, successAddFavorites, successRemoveFavorites, receiveFavorites, idleSyncFavorites, requestFlushFavoritesBuffer } from "../action-creators";
|
|
7
|
+
|
|
8
|
+
// Required for custom runner without env-setup
|
|
9
|
+
jest.mock('@shopgate/pwa-core', () => ({
|
|
10
|
+
UIEvents: {
|
|
11
|
+
emit: jest.fn(),
|
|
12
|
+
on: jest.fn(),
|
|
13
|
+
addListener: jest.fn(),
|
|
14
|
+
removeListener: jest.fn()
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
describe('Favorites streams', () => {
|
|
18
|
+
const DUMMY_ACTION = 'DUMMY_ACTION';
|
|
19
|
+
let subscriber;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
subscriber = jest.fn();
|
|
22
|
+
});
|
|
23
|
+
describe('favoritesWillEnter$', () => {
|
|
24
|
+
it('should call subscribers when the favorites page will open', () => {
|
|
25
|
+
favoritesWillEnter$.subscribe(subscriber);
|
|
26
|
+
mainSubject.next({
|
|
27
|
+
action: {
|
|
28
|
+
type: ROUTE_WILL_ENTER,
|
|
29
|
+
route: {
|
|
30
|
+
pattern: FAVORITES_PATH
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
35
|
+
});
|
|
36
|
+
it('should not call subscribers when the path does not match', () => {
|
|
37
|
+
favoritesWillEnter$.subscribe(subscriber);
|
|
38
|
+
mainSubject.next({
|
|
39
|
+
action: {
|
|
40
|
+
type: ROUTE_WILL_ENTER,
|
|
41
|
+
route: {
|
|
42
|
+
pattern: '/other_path'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
47
|
+
});
|
|
48
|
+
it('should not call subscribers when the action does not match', () => {
|
|
49
|
+
favoritesWillEnter$.subscribe(subscriber);
|
|
50
|
+
mainSubject.next({
|
|
51
|
+
action: {
|
|
52
|
+
type: DUMMY_ACTION,
|
|
53
|
+
route: {
|
|
54
|
+
pattern: FAVORITES_PATH
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('addProductToFavoritesDebounced$', () => {
|
|
62
|
+
afterEach(() => {
|
|
63
|
+
jest.useRealTimers();
|
|
64
|
+
});
|
|
65
|
+
it('should call subscribers only once, when the action is triggered multiple times', () => {
|
|
66
|
+
jest.useFakeTimers();
|
|
67
|
+
addProductToFavoritesDebounced$.subscribe(subscriber);
|
|
68
|
+
const action = addProductToFavorites('product1');
|
|
69
|
+
mainSubject.next({
|
|
70
|
+
action
|
|
71
|
+
});
|
|
72
|
+
mainSubject.next({
|
|
73
|
+
action
|
|
74
|
+
});
|
|
75
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
76
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
77
|
+
});
|
|
78
|
+
it('should call subscribers twice, when debounce time has passed', () => {
|
|
79
|
+
jest.useFakeTimers();
|
|
80
|
+
addProductToFavoritesDebounced$.subscribe(subscriber);
|
|
81
|
+
const action = addProductToFavorites('product1');
|
|
82
|
+
mainSubject.next({
|
|
83
|
+
action
|
|
84
|
+
});
|
|
85
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
86
|
+
mainSubject.next({
|
|
87
|
+
action
|
|
88
|
+
});
|
|
89
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
90
|
+
expect(subscriber).toHaveBeenCalledTimes(2);
|
|
91
|
+
});
|
|
92
|
+
it('should not call subscribers when the action does not match', () => {
|
|
93
|
+
addProductToFavoritesDebounced$.subscribe(subscriber);
|
|
94
|
+
mainSubject.next({
|
|
95
|
+
action: {
|
|
96
|
+
type: DUMMY_ACTION
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('removeProductFromFavoritesDebounced$', () => {
|
|
103
|
+
afterEach(() => {
|
|
104
|
+
jest.useRealTimers();
|
|
105
|
+
});
|
|
106
|
+
it('should call subscribers only once, when the action is triggered multiple times', () => {
|
|
107
|
+
jest.useFakeTimers();
|
|
108
|
+
removeProductFromFavoritesDebounced$.subscribe(subscriber);
|
|
109
|
+
const action = removeProductFromFavorites('product1', true);
|
|
110
|
+
mainSubject.next({
|
|
111
|
+
action
|
|
112
|
+
});
|
|
113
|
+
mainSubject.next({
|
|
114
|
+
action
|
|
115
|
+
});
|
|
116
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
117
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
it('should call subscribers twice, when debounce time has passed', () => {
|
|
120
|
+
jest.useFakeTimers();
|
|
121
|
+
removeProductFromFavoritesDebounced$.subscribe(subscriber);
|
|
122
|
+
const action = removeProductFromFavorites('product1', true);
|
|
123
|
+
mainSubject.next({
|
|
124
|
+
action
|
|
125
|
+
});
|
|
126
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
127
|
+
mainSubject.next({
|
|
128
|
+
action
|
|
129
|
+
});
|
|
130
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
131
|
+
expect(subscriber).toHaveBeenCalledTimes(2);
|
|
132
|
+
});
|
|
133
|
+
it('should not call subscribers when the action does not match', () => {
|
|
134
|
+
removeProductFromFavoritesDebounced$.subscribe(subscriber);
|
|
135
|
+
mainSubject.next({
|
|
136
|
+
action: {
|
|
137
|
+
type: DUMMY_ACTION
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe('favoritesError$', () => {
|
|
144
|
+
const actionTypes = [ERROR_FETCH_FAVORITES, ERROR_ADD_FAVORITES, ERROR_REMOVE_FAVORITES, ERROR_FAVORITES, DUMMY_ACTION // This should not trigger the subscriber
|
|
145
|
+
];
|
|
146
|
+
it('should call subscribers for every dispatched favorites error and no others', () => {
|
|
147
|
+
favoritesError$.subscribe(subscriber);
|
|
148
|
+
actionTypes.forEach(type => {
|
|
149
|
+
mainSubject.next({
|
|
150
|
+
action: {
|
|
151
|
+
type
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
expect(subscriber).toHaveBeenCalledTimes(4);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('errorFavoritesLimit$', () => {
|
|
159
|
+
it('should call subscribers only for the internal favorites limit error and no others', () => {
|
|
160
|
+
errorFavoritesLimit$.subscribe(subscriber);
|
|
161
|
+
mainSubject.next({
|
|
162
|
+
action: {
|
|
163
|
+
type: ERROR_FAVORITES,
|
|
164
|
+
error: {
|
|
165
|
+
code: FAVORITES_LIMIT_ERROR
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
170
|
+
});
|
|
171
|
+
it('should not call subscribers when the action does not match', () => {
|
|
172
|
+
errorFavoritesLimit$.subscribe(subscriber);
|
|
173
|
+
mainSubject.next({
|
|
174
|
+
action: {
|
|
175
|
+
type: DUMMY_ACTION
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
179
|
+
});
|
|
180
|
+
it('should not call subscribers on any other internal favorites error', () => {
|
|
181
|
+
errorFavoritesLimit$.subscribe(subscriber);
|
|
182
|
+
mainSubject.next({
|
|
183
|
+
action: {
|
|
184
|
+
type: ERROR_FAVORITES,
|
|
185
|
+
error: {
|
|
186
|
+
code: 'SOME_OTHER_CODE'
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe('shouldFetchFavorites$', () => {
|
|
194
|
+
it('should call subscribers to fetch favorites on every app start and on route enter', () => {
|
|
195
|
+
shouldFetchFavorites$.subscribe(subscriber);
|
|
196
|
+
mainSubject.next({
|
|
197
|
+
action: {
|
|
198
|
+
type: APP_DID_START
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
mainSubject.next({
|
|
202
|
+
action: {
|
|
203
|
+
type: ROUTE_WILL_ENTER,
|
|
204
|
+
route: {
|
|
205
|
+
pattern: FAVORITES_PATH
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
expect(subscriber).toHaveBeenCalledTimes(2);
|
|
210
|
+
});
|
|
211
|
+
it('should call subscribers on any other action', () => {
|
|
212
|
+
shouldFetchFavorites$.subscribe(subscriber);
|
|
213
|
+
mainSubject.next({
|
|
214
|
+
action: {
|
|
215
|
+
type: DUMMY_ACTION
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe('shouldFetchFreshFavorites$', () => {
|
|
222
|
+
it('should call subscribers to fetch fresh favorites on every login and logout', () => {
|
|
223
|
+
shouldFetchFreshFavorites$.subscribe(subscriber);
|
|
224
|
+
mainSubject.next({
|
|
225
|
+
action: {
|
|
226
|
+
type: SUCCESS_LOGIN
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
mainSubject.next({
|
|
230
|
+
action: {
|
|
231
|
+
type: SUCCESS_LOGOUT
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
expect(subscriber).toHaveBeenCalledTimes(2);
|
|
235
|
+
});
|
|
236
|
+
it('should call subscribers on any other action', () => {
|
|
237
|
+
shouldFetchFreshFavorites$.subscribe(subscriber);
|
|
238
|
+
mainSubject.next({
|
|
239
|
+
action: {
|
|
240
|
+
type: DUMMY_ACTION
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
describe('favoritesDidUpdate$', () => {
|
|
247
|
+
const actionTypes = [REQUEST_ADD_FAVORITES, ERROR_ADD_FAVORITES, REQUEST_REMOVE_FAVORITES, ERROR_REMOVE_FAVORITES, RECEIVE_FAVORITES, ERROR_FETCH_FAVORITES, DUMMY_ACTION // This should not trigger the subscriber
|
|
248
|
+
];
|
|
249
|
+
it('should call subscribers for every dispatched favorites update and no others', () => {
|
|
250
|
+
favoritesDidUpdate$.subscribe(subscriber);
|
|
251
|
+
actionTypes.forEach(type => {
|
|
252
|
+
mainSubject.next({
|
|
253
|
+
action: {
|
|
254
|
+
type
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
expect(subscriber).toHaveBeenCalledTimes(6);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
describe('favoritesWillAddItem$', () => {
|
|
262
|
+
it('should call subscribers for every favorite to be added', () => {
|
|
263
|
+
favoritesWillAddItem$.subscribe(subscriber);
|
|
264
|
+
mainSubject.next({
|
|
265
|
+
action: requestAddFavorites('product1')
|
|
266
|
+
});
|
|
267
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
268
|
+
});
|
|
269
|
+
it('should not call subscribers when the action does not match', () => {
|
|
270
|
+
favoritesWillAddItem$.subscribe(subscriber);
|
|
271
|
+
mainSubject.next({
|
|
272
|
+
action: {
|
|
273
|
+
type: DUMMY_ACTION
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
describe('favoritesDidAddItem$', () => {
|
|
280
|
+
it('should call subscribers for every favorite that was added', () => {
|
|
281
|
+
favoritesDidAddItem$.subscribe(subscriber);
|
|
282
|
+
mainSubject.next({
|
|
283
|
+
action: successAddFavorites('product1')
|
|
284
|
+
});
|
|
285
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
286
|
+
});
|
|
287
|
+
it('should not call subscribers when the action does not match', () => {
|
|
288
|
+
favoritesDidAddItem$.subscribe(subscriber);
|
|
289
|
+
mainSubject.next({
|
|
290
|
+
action: {
|
|
291
|
+
type: DUMMY_ACTION
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
describe('favoritesWillRemoveItem$', () => {
|
|
298
|
+
it('should call subscribers for every favorite to be removed', () => {
|
|
299
|
+
favoritesWillRemoveItem$.subscribe(subscriber);
|
|
300
|
+
mainSubject.next({
|
|
301
|
+
action: requestRemoveFavorites('product1')(action => action, () => ({}))
|
|
302
|
+
});
|
|
303
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
304
|
+
});
|
|
305
|
+
it('should not call subscribers when the action does not match', () => {
|
|
306
|
+
favoritesWillRemoveItem$.subscribe(subscriber);
|
|
307
|
+
mainSubject.next({
|
|
308
|
+
action: {
|
|
309
|
+
type: DUMMY_ACTION
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
describe('favoritesDidRemoveItem$', () => {
|
|
316
|
+
it('should call subscribers for every favorite that was removed', () => {
|
|
317
|
+
favoritesDidRemoveItem$.subscribe(subscriber);
|
|
318
|
+
mainSubject.next({
|
|
319
|
+
action: successRemoveFavorites('product1')
|
|
320
|
+
});
|
|
321
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
322
|
+
});
|
|
323
|
+
it('should not call subscribers when the action does not match', () => {
|
|
324
|
+
favoritesDidRemoveItem$.subscribe(subscriber);
|
|
325
|
+
mainSubject.next({
|
|
326
|
+
action: {
|
|
327
|
+
type: DUMMY_ACTION
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
describe('receiveFavorites$', () => {
|
|
334
|
+
it('should call subscribers for every receive favorites action', () => {
|
|
335
|
+
receiveFavorites$.subscribe(subscriber);
|
|
336
|
+
mainSubject.next({
|
|
337
|
+
action: receiveFavorites()
|
|
338
|
+
});
|
|
339
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
340
|
+
});
|
|
341
|
+
it('should not call subscribers when the action does not match', () => {
|
|
342
|
+
receiveFavorites$.subscribe(subscriber);
|
|
343
|
+
mainSubject.next({
|
|
344
|
+
action: {
|
|
345
|
+
type: DUMMY_ACTION
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
describe('favoritesSyncIdle$', () => {
|
|
352
|
+
it('should call subscribers for every sync idle call', () => {
|
|
353
|
+
favoritesSyncIdle$.subscribe(subscriber);
|
|
354
|
+
mainSubject.next({
|
|
355
|
+
action: idleSyncFavorites()
|
|
356
|
+
});
|
|
357
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
358
|
+
});
|
|
359
|
+
it('should not call subscribers when the action does not match', () => {
|
|
360
|
+
favoritesSyncIdle$.subscribe(subscriber);
|
|
361
|
+
mainSubject.next({
|
|
362
|
+
action: {
|
|
363
|
+
type: DUMMY_ACTION
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
describe('refreshFavorites$', () => {
|
|
370
|
+
afterEach(() => {
|
|
371
|
+
jest.useRealTimers();
|
|
372
|
+
});
|
|
373
|
+
it('should call subscribers only once, when the action is triggered multiple times', () => {
|
|
374
|
+
jest.useFakeTimers();
|
|
375
|
+
refreshFavorites$.subscribe(subscriber);
|
|
376
|
+
const action = idleSyncFavorites();
|
|
377
|
+
mainSubject.next({
|
|
378
|
+
action
|
|
379
|
+
});
|
|
380
|
+
mainSubject.next({
|
|
381
|
+
action
|
|
382
|
+
});
|
|
383
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
384
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
385
|
+
});
|
|
386
|
+
it('should call subscribers twice, when debounce time has passed', () => {
|
|
387
|
+
jest.useFakeTimers();
|
|
388
|
+
refreshFavorites$.subscribe(subscriber);
|
|
389
|
+
const action = idleSyncFavorites();
|
|
390
|
+
mainSubject.next({
|
|
391
|
+
action
|
|
392
|
+
});
|
|
393
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
394
|
+
mainSubject.next({
|
|
395
|
+
action
|
|
396
|
+
});
|
|
397
|
+
jest.advanceTimersByTime(FAVORITE_BUTTON_DEBOUNCE_TIME);
|
|
398
|
+
expect(subscriber).toHaveBeenCalledTimes(2);
|
|
399
|
+
});
|
|
400
|
+
it('should not call subscribers when the action does not match', () => {
|
|
401
|
+
refreshFavorites$.subscribe(subscriber);
|
|
402
|
+
mainSubject.next({
|
|
403
|
+
action: {
|
|
404
|
+
type: DUMMY_ACTION
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
describe('didRequestChangeFavorites$', () => {
|
|
411
|
+
it('should call subscribers for every actual add or remove request', () => {
|
|
412
|
+
didRequestChangeFavorites$.subscribe(subscriber);
|
|
413
|
+
mainSubject.next({
|
|
414
|
+
action: requestAddFavorites('product1')
|
|
415
|
+
});
|
|
416
|
+
mainSubject.next({
|
|
417
|
+
action: requestRemoveFavorites('product2', false)(actionInner => actionInner, () => ({}))
|
|
418
|
+
});
|
|
419
|
+
expect(subscriber).toHaveBeenCalledTimes(2);
|
|
420
|
+
});
|
|
421
|
+
it('should not call subscribers when the action does not match', () => {
|
|
422
|
+
didRequestChangeFavorites$.subscribe(subscriber);
|
|
423
|
+
mainSubject.next({
|
|
424
|
+
action: {
|
|
425
|
+
type: DUMMY_ACTION
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
describe('didRequestFlushFavoritesBuffer$', () => {
|
|
432
|
+
it('should call subscribers for every buffer flush request', () => {
|
|
433
|
+
didRequestFlushFavoritesBuffer$.subscribe(subscriber);
|
|
434
|
+
mainSubject.next({
|
|
435
|
+
action: requestFlushFavoritesBuffer()
|
|
436
|
+
});
|
|
437
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
438
|
+
});
|
|
439
|
+
it('should not call subscribers when the action does not match', () => {
|
|
440
|
+
didRequestFlushFavoritesBuffer$.subscribe(subscriber);
|
|
441
|
+
mainSubject.next({
|
|
442
|
+
action: {
|
|
443
|
+
type: DUMMY_ACTION
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
describe('didReceiveFlushFavoritesBuffer$', () => {
|
|
450
|
+
it('should call subscribers with the full action buffer when the buffer period has passed', () => {
|
|
451
|
+
jest.useFakeTimers();
|
|
452
|
+
const bufferedActions = [{
|
|
453
|
+
action: requestAddFavorites('product1')
|
|
454
|
+
}, {
|
|
455
|
+
action: requestAddFavorites('product2')
|
|
456
|
+
}, {
|
|
457
|
+
action: requestRemoveFavorites('product2', false)
|
|
458
|
+
}, {
|
|
459
|
+
action: requestAddFavorites('product2')
|
|
460
|
+
}];
|
|
461
|
+
didReceiveFlushFavoritesBuffer$.subscribe(subscriber);
|
|
462
|
+
|
|
463
|
+
// Pump all actions into the buffer
|
|
464
|
+
bufferedActions.forEach(action => {
|
|
465
|
+
if (typeof action?.action === 'function') {
|
|
466
|
+
// eslint-disable-next-line no-param-reassign
|
|
467
|
+
action.action = action.action(actionInner => actionInner, () => ({}));
|
|
468
|
+
}
|
|
469
|
+
mainSubject.next(action);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// Trigger flush by timeout
|
|
473
|
+
jest.advanceTimersByTime(FAVORITE_ACTION_BUFFER_TIME);
|
|
474
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
475
|
+
expect(subscriber).toHaveBeenCalledWith(bufferedActions);
|
|
476
|
+
jest.useRealTimers();
|
|
477
|
+
});
|
|
478
|
+
it('should call subscribers with the full action buffer when the buffer is cleared by manual request', () => {
|
|
479
|
+
const bufferedActions = [{
|
|
480
|
+
action: requestAddFavorites('product1')
|
|
481
|
+
}, {
|
|
482
|
+
action: requestAddFavorites('product2')
|
|
483
|
+
}, {
|
|
484
|
+
action: requestRemoveFavorites('product2', false)
|
|
485
|
+
}, {
|
|
486
|
+
action: requestAddFavorites('product2')
|
|
487
|
+
}];
|
|
488
|
+
didReceiveFlushFavoritesBuffer$.subscribe(subscriber);
|
|
489
|
+
|
|
490
|
+
// Pump all actions into the buffer
|
|
491
|
+
bufferedActions.forEach(action => {
|
|
492
|
+
if (typeof action?.action === 'function') {
|
|
493
|
+
// eslint-disable-next-line no-param-reassign
|
|
494
|
+
action.action = action.action(actionInner => actionInner, () => ({}));
|
|
495
|
+
}
|
|
496
|
+
mainSubject.next(action);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// Trigger flush via manual request action
|
|
500
|
+
mainSubject.next({
|
|
501
|
+
action: requestFlushFavoritesBuffer()
|
|
502
|
+
});
|
|
503
|
+
expect(subscriber).toHaveBeenCalledTimes(1);
|
|
504
|
+
expect(subscriber).toHaveBeenCalledWith(bufferedActions);
|
|
505
|
+
});
|
|
506
|
+
it('should not call subscribers when the action does not match', () => {
|
|
507
|
+
didReceiveFlushFavoritesBuffer$.subscribe(subscriber);
|
|
508
|
+
mainSubject.next({
|
|
509
|
+
action: {
|
|
510
|
+
type: DUMMY_ACTION
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
expect(subscriber).toHaveBeenCalledTimes(0);
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
/* eslint-enable extra-rules/no-single-line-objects */
|