@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
1 lines • 4.01 kB
JavaScript
import _cloneDeep from"lodash/cloneDeep";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{getProductReviews,getProductReviewsExcerpt,getReviewsTotalCount,getCurrentReviewCount,getReviewsFetchingState,getProductReviewCount,getUserReviewForProduct,getDefaultAuthorName}from"./index";import{REVIEW_PREVIEW_COUNT}from"../constants";import{emptyState,finalState,testReviews}from"./mock";describe('Reviews selectors',function(){var propsProductId={productId:'9209597131'};var propsEmpty={productId:null};describe('getProductReviews',function(){it('should return reviews when reviews are available',function(){var reviews=getProductReviews(finalState,propsProductId);expect(reviews).toEqual(testReviews);});it('should return empty array when state has no reviews for current product',function(){var state=_cloneDeep(finalState);var reviews=getProductReviews(state,propsEmpty);expect(reviews).toEqual([]);});it('should return empty array when state is empty',function(){var reviews=getProductReviews(emptyState,propsProductId);expect(reviews).toEqual([]);});});describe('getProductReviewsExcerpt',function(){it('should return product reviews when reviews are available',function(){var reviews=getProductReviewsExcerpt(finalState,propsProductId);expect(reviews).toEqual(testReviews.slice(0,REVIEW_PREVIEW_COUNT));});it('should return null when state has no reviews for current product',function(){var state=_cloneDeep(finalState);var reviews=getProductReviewsExcerpt(state,propsEmpty);expect(reviews).toBe(null);});it('should return null when state has no reviews for current product',function(){var reviews=getProductReviewsExcerpt(emptyState,propsProductId);expect(reviews).toBe(null);});});describe('getReviewsTotalCount',function(){it('should return null when no reviews are available',function(){var totalCount=getReviewsTotalCount(emptyState,propsProductId);expect(totalCount).toBe(null);});it('should return number when reviews are available',function(){var totalCount=getReviewsTotalCount(finalState,propsProductId);expect(totalCount).toBeGreaterThan(1);});});describe('getCurrentReviewCount',function(){it('should return null when no reviews are available',function(){var totalCount=getCurrentReviewCount(emptyState,propsProductId);expect(totalCount).toBe(null);});it('should return number when reviews are available',function(){var totalCount=getCurrentReviewCount(finalState,propsProductId);expect(totalCount).toBeGreaterThan(1);});});describe('getReviewsFetchingState',function(){it('should return fetching state',function(){var result=getReviewsFetchingState(finalState,propsProductId);expect(result).toEqual(false);});});describe('getProductReviewCount',function(){it('should return review count',function(){var result=getProductReviewCount(finalState,propsProductId);expect(result).toBe(finalState.reviews.reviewsByProductId[9209597131].totalReviewCount);});it('should return null when there is no reviews',function(){var result=getProductReviewCount(emptyState,propsProductId);expect(result).toBe(null);});});describe('getUserReviewForProduct',function(){it('should return user review',function(){var result=getUserReviewForProduct(finalState,propsProductId);expect(result).toEqual(_extends({},finalState.reviews.reviewsById[1]));});it('should return empty object when no user review is available',function(){var result=getUserReviewForProduct(emptyState,propsProductId);expect(result).toEqual({});});});describe('getDefaultAuthorName',function(){it('should return author name when user is logged in',function(){var result=getDefaultAuthorName(finalState,propsProductId);expect(result).toBe('Foo Bar');});it('should return empty string, when user it not logged in',function(){var result=getDefaultAuthorName(emptyState,propsProductId);expect(result).toBe('');});});});