diff --git a/.circleci/config.yml b/.circleci/config.yml index c0a75fcc..8c94d6e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,14 +2,14 @@ version: 2.1 orbs: codecov: codecov/codecov@1.1.1 - browser-tools: circleci/browser-tools@1.2.4 + browser-tools: circleci/browser-tools@1.4.4 common: integration_test_steps: &integration_test_steps steps: - checkout - browser-tools/install-browser-tools: - chrome-version: 114.0.5735.90 # TODO: remove -> https://github.com/CircleCI-Public/browser-tools-orb/issues/75 + chrome-version: 116.0.5845.96 # TODO: remove -> https://github.com/CircleCI-Public/browser-tools-orb/issues/75 - restore_cache: keys: - maven-repo-{{ .Environment.CACHE_VERSION }}-its-{{ arch }}-{{ .Branch }}-{{ checksum "pom.xml" }} diff --git a/core/src/main/java/com/venia/core/models/commerce/MySearchResultsImpl.java b/core/src/main/java/com/venia/core/models/commerce/MySearchResultsImpl.java index 85f87f7e..ebb1ca65 100644 --- a/core/src/main/java/com/venia/core/models/commerce/MySearchResultsImpl.java +++ b/core/src/main/java/com/venia/core/models/commerce/MySearchResultsImpl.java @@ -121,6 +121,10 @@ public String getId() { @Override public ComponentData getData() { final ComponentData data = ((Component) searchResults).getData(); + if (data == null) { + return null; + } + final AtomicReference dataRef = new AtomicReference<>(); ComponentData componentData = (ComponentData) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{ComponentData.class}, (proxy, method, args) -> { diff --git a/core/src/test/java/com/venia/core/models/commerce/MyProductTeaserImplTest.java b/core/src/test/java/com/venia/core/models/commerce/MyProductTeaserImplTest.java index 7a42319b..4568c5d5 100644 --- a/core/src/test/java/com/venia/core/models/commerce/MyProductTeaserImplTest.java +++ b/core/src/test/java/com/venia/core/models/commerce/MyProductTeaserImplTest.java @@ -282,4 +282,10 @@ public void testDataLayerFeature() throws Exception { Assertions.assertEquals(dataLayerJson, underTest.getData().getJson()); } + + @Test + void testGetProductRetriever() throws Exception { + setup(PRODUCTTEASER_NO_BADGE); + Assertions.assertNotNull(underTest.getProductRetriever()); + } } diff --git a/core/src/test/java/com/venia/core/models/commerce/MySearchResultsImplTest.java b/core/src/test/java/com/venia/core/models/commerce/MySearchResultsImplTest.java index 91c755ab..6a15f793 100644 --- a/core/src/test/java/com/venia/core/models/commerce/MySearchResultsImplTest.java +++ b/core/src/test/java/com/venia/core/models/commerce/MySearchResultsImplTest.java @@ -13,16 +13,20 @@ ******************************************************************************/ package com.venia.core.models.commerce; -import com.adobe.cq.commerce.core.components.models.searchresults.SearchResults; import com.adobe.cq.commerce.core.components.services.urls.UrlProvider; import com.adobe.cq.commerce.core.search.models.SearchResultsSet; import com.adobe.cq.commerce.core.search.models.Sorter; import com.adobe.cq.commerce.core.search.models.SorterKey; import com.adobe.cq.commerce.core.search.services.SearchResultsService; +import com.adobe.cq.commerce.magento.graphql.FilterMatchTypeInput; import com.adobe.cq.commerce.magento.graphql.ProductAttributeFilterInput; +import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData; import com.day.cq.wcm.api.Page; import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.wrappers.ValueMapDecorator; +import org.apache.sling.caconfig.ConfigurationBuilder; import org.apache.sling.testing.mock.sling.ResourceResolverType; import org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest; import org.junit.jupiter.api.Assertions; @@ -38,8 +42,7 @@ import java.util.Map; import java.util.function.Function; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -49,7 +52,8 @@ public class MySearchResultsImplTest { private static final String PAGE = "/content/page"; private final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK); - private SearchResults underTest; + private MySearchResultsImpl underTest; + private HashMap dataLayerConfigMap; @BeforeEach void beforeEach() { @@ -79,6 +83,12 @@ void beforeEach() { context.registerService(UrlProvider.class, mock(UrlProvider.class)); context.addModelsForClasses(MySearchResultsImpl.class); + ConfigurationBuilder configurationBuilder = mock(ConfigurationBuilder.class); + when(configurationBuilder.name("com.adobe.cq.wcm.core.components.internal.DataLayerConfig")).thenReturn(configurationBuilder); + dataLayerConfigMap = new HashMap<>(); + when(configurationBuilder.asValueMap()).thenReturn(new ValueMapDecorator(dataLayerConfigMap)); + context.registerAdapter(Resource.class, ConfigurationBuilder.class, configurationBuilder); + MockSlingHttpServletRequest request = context.request(); request.addRequestParameter("search_query", "test"); @@ -86,6 +96,36 @@ void beforeEach() { Assertions.assertNotNull(underTest); } + @Test + void testInstance() { + assertEquals("paginationbar", underTest.getPaginationType()); + assertFalse(underTest.isAddToCartEnabled()); + assertFalse(underTest.isAddToWishListEnabled()); + assertTrue(underTest.loadClientPrice()); + assertNotNull(underTest.getSearchResultsStorefrontContext()); + assertNotNull(underTest.getSearchStorefrontContext()); + underTest.getAppliedCssClasses(); + assertEquals("venia/components/commerce/searchresults", underTest.getExportedType()); + ComponentData componentData = underTest.getData(); + assertNull(componentData); + assertEquals("searchresults-50df7e8869", underTest.getId()); + + underTest.extendProductQueryWith(p-> p.color()); + underTest.extendProductFilterWith(f -> f.setName(new FilterMatchTypeInput().setMatch("winter"))); + assertNotNull(underTest.getProducts()); + } + + @Test + void testComponentData() { + dataLayerConfigMap.put("enabled", true); + + ComponentData componentData = underTest.getData(); + assertNotNull(componentData); + assertEquals("venia/components/commerce/searchresults", componentData.getType()); + assertEquals("searchresults-50df7e8869", componentData.getId()); + } + + @Test void testSorterKeys() { List keys = underTest.getSearchResultsSet().getSorter().getKeys(); diff --git a/it.tests/src/main/resources/datalayer/grouped-product-65.json b/it.tests/src/main/resources/datalayer/grouped-product-65.json index 2ecaa222..b044eedf 100644 --- a/it.tests/src/main/resources/datalayer/grouped-product-65.json +++ b/it.tests/src/main/resources/datalayer/grouped-product-65.json @@ -1,34 +1,33 @@ { - "product-3c02043652": { - "xdm:listPrice": 78.0, - "xdm:SKU": "VA23", - "xdm:assets": [ - { - - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/a/va23_main.jpg", - "repo:id": "image-3d3553c5dc", - "@type": "image" - } - ], - "xdm:categories": [ - { - "repo:id": "category-8c01c593b9", - "xdm:name": "Accessories", - "xdm:asset": { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/category/carefree.jpg", - "repo:id": "image-6310f9e8a5", - "@type": "image" - } - }, - { - "repo:id": "category-f5a5c5aea0", - "xdm:name": "Jewelry", - "xdm:asset": null - } - ], - "xdm:currencyCode": "USD", - "dc:description": "This trio is designed for versatility. Brighten up a simple look or add another layer of “wow” to an already vibrant ensemble. Go as big and bold, or understated as you're in the mood to be.", - "dc:title": "Augusta Trio", - "@type": "venia/components/commerce/product" - } + "product-3c02043652": { + "xdm:listPrice": 78.0, + "xdm:SKU": "VA23", + "xdm:assets": [ + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/a/va23_main.jpg", + "repo:id": "image-daa709cd50", + "@type": "image" + } + ], + "xdm:categories": [ + { + "repo:id": "category-4c0609820d", + "xdm:name": "Accessories", + "xdm:asset": { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/category/carefree.jpg", + "repo:id": "image-11a31da9a5", + "@type": "image" + } + }, + { + "repo:id": "category-6e6f7c1718", + "xdm:name": "Jewelry", + "xdm:asset": null + } + ], + "xdm:currencyCode": "USD", + "dc:description": "This trio is designed for versatility. Brighten up a simple look or add another layer of “wow” to an already vibrant ensemble. Go as big and bold, or understated as you're in the mood to be.", + "dc:title": "Augusta Trio", + "@type": "venia/components/commerce/product" + } } \ No newline at end of file diff --git a/it.tests/src/main/resources/datalayer/grouped-product.json b/it.tests/src/main/resources/datalayer/grouped-product.json index 0c3827a6..17e4dd57 100644 --- a/it.tests/src/main/resources/datalayer/grouped-product.json +++ b/it.tests/src/main/resources/datalayer/grouped-product.json @@ -1,34 +1,33 @@ { - "product-3c02043652": { - "xdm:listPrice": 78.0, - "xdm:SKU": "VA23", - "xdm:assets": [ - { - - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/a/va23_main.jpg", - "repo:id": "image-3d3553c5dc", - "@type": "image" - } - ], - "xdm:categories": [ - { - "repo:id": "category-8c01c593b9", - "xdm:name": "Accessories", - "xdm:asset": { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/category/carefree.jpg", - "repo:id": "image-6310f9e8a5", - "@type": "image" - } - }, - { - "repo:id": "category-f5a5c5aea0", - "xdm:name": "Jewelry", - "xdm:asset": null - } - ], - "xdm:currencyCode": "USD", - "dc:description": "This trio is designed for versatility. Brighten up a simple look or add another layer of “wow” to an already vibrant ensemble. Go as big and bold, or understated as you're in the mood to be.", - "dc:title": "Augusta Trio", - "@type": "venia/components/commerce/product" - } + "product-3c02043652": { + "xdm:listPrice": 78.0, + "xdm:SKU": "VA23", + "xdm:assets": [ + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/a/va23_main.jpg", + "repo:id": "image-daa709cd50", + "@type": "image" + } + ], + "xdm:categories": [ + { + "repo:id": "category-4c0609820d", + "xdm:name": "Accessories", + "xdm:asset": { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/category/carefree.jpg", + "repo:id": "image-11a31da9a5", + "@type": "image" + } + }, + { + "repo:id": "category-6e6f7c1718", + "xdm:name": "Jewelry", + "xdm:asset": null + } + ], + "xdm:currencyCode": "USD", + "dc:description": "This trio is designed for versatility. Brighten up a simple look or add another layer of “wow” to an already vibrant ensemble. Go as big and bold, or understated as you're in the mood to be.", + "dc:title": "Augusta Trio", + "@type": "venia/components/commerce/product" + } } \ No newline at end of file diff --git a/it.tests/src/main/resources/datalayer/simple-product-65.json b/it.tests/src/main/resources/datalayer/simple-product-65.json index f776e951..9244dad7 100644 --- a/it.tests/src/main/resources/datalayer/simple-product-65.json +++ b/it.tests/src/main/resources/datalayer/simple-product-65.json @@ -1,62 +1,58 @@ { - "product-dc59ad50df": { - "xdm:listPrice": 78.0, - "xdm:SKU": "VP05", - "xdm:assets": [ - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05-rn_main_4.jpg", - "repo:id": "image-73439b9cf3", - "@type": "image" - }, - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05-rn_alt_2.jpg", - "repo:id": "image-2e75bb2439", - "@type": "image" - }, - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05-rn_back_2.jpg", - "repo:id": "image-40bcf141f9", - "@type": "image" - }, - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05_look_2.jpg", - "repo:id": "image-e049cce860", - "@type": "image" - } - ], - "xdm:categories": [ - { - "repo:id": "category-cf9d757f29", - "xdm:name": "Bottoms", - "xdm:asset": { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/category/minimalist.jpg", - "repo:id": "image-74c855fbf3", - "@type": "image" - } - }, - { - "repo:id": "category-6e60cf4797", - "xdm:name": "Pants & Shorts", - "xdm:asset": null - }, - { - "repo:id": "category-b8a3caa888", - "xdm:name": "Shop The Look", - "xdm:asset": { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/category/beachy.jpg", - "repo:id": "image-8a0806aaab", - "@type": "image" - } - }, - { - "repo:id": "category-df146c27a3", - "xdm:name": "Minimalist Sensibility", - "xdm:asset": null - } - ], - "xdm:currencyCode": "USD", - "dc:description": "

The Honora Wide Leg Pants definitely hold their own when it comes to standing out from the crowd. These pants feature a unique design and a varying color palette to make pairing a snap.

Features:

  • Elastic waistband
  • Drawstring waist
  • Sits just below the waist
  • 31" inseam
  • Machine wash, line dry
", - "dc:title": "Honora Wide Leg Pants", - "@type": "venia/components/commerce/product" - } + "product-dc59ad50df": { + "xdm:listPrice": 78.0, + "xdm:SKU": "VP05", + "xdm:assets": [ + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05-rn_main.jpg", + "repo:id": "image-2ea11abe0a", + "@type": "image" + }, + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05-rn_alt.jpg", + "repo:id": "image-35c39a6a6b", + "@type": "image" + }, + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05-rn_back.jpg", + "repo:id": "image-7ed6d7593b", + "@type": "image" + }, + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05_look.jpg", + "repo:id": "image-3b4d560585", + "@type": "image" + } + ], + "xdm:categories": [ + { + "repo:id": "category-2212426126", + "xdm:name": "Bottoms", + "xdm:asset": { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/category/minimalist.jpg", + "repo:id": "image-9d427bd572", + "@type": "image" + } + }, + { + "repo:id": "category-3c1d5daf00", + "xdm:name": "Pants & Shorts", + "xdm:asset": null + }, + { + "repo:id": "category-77640b4209", + "xdm:name": "Shop The Look", + "xdm:asset": null + }, + { + "repo:id": "category-077469fda4", + "xdm:name": "Minimalist Sensibility", + "xdm:asset": null + } + ], + "xdm:currencyCode": "USD", + "dc:description": "

The Honora Wide Leg Pants definitely hold their own when it comes to standing out from the crowd. These pants feature a unique design and a varying color palette to make pairing a snap.

Features:

  • Elastic waistband
  • Drawstring waist
  • Sits just below the waist
  • 31" inseam
  • Machine wash, line dry
", + "dc:title": "Honora Wide Leg Pants", + "@type": "venia/components/commerce/product" + } } \ No newline at end of file diff --git a/it.tests/src/main/resources/datalayer/simple-product.json b/it.tests/src/main/resources/datalayer/simple-product.json index f7cd1ec6..91f3e749 100644 --- a/it.tests/src/main/resources/datalayer/simple-product.json +++ b/it.tests/src/main/resources/datalayer/simple-product.json @@ -1,62 +1,58 @@ { - "product-dc59ad50df": { - "xdm:listPrice": 78.0, - "xdm:SKU": "VP05", - "xdm:assets": [ - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05-rn_main_4.jpg", - "repo:id": "image-73439b9cf3", - "@type": "image" - }, - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05-rn_alt_2.jpg", - "repo:id": "image-2e75bb2439", - "@type": "image" - }, - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05-rn_back_2.jpg", - "repo:id": "image-40bcf141f9", - "@type": "image" - }, - { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/product/cache/8735dd21982cf027014173d1affcf80c/v/p/vp05_look_2.jpg", - "repo:id": "image-e049cce860", - "@type": "image" - } - ], - "xdm:categories": [ - { - "repo:id": "category-cf9d757f29", - "xdm:name": "Bottoms", - "xdm:asset": { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/category/minimalist.jpg", - "repo:id": "image-74c855fbf3", - "@type": "image" - } - }, - { - "repo:id": "category-6e60cf4797", - "xdm:name": "Pants & Shorts", - "xdm:asset": null - }, - { - "repo:id": "category-b8a3caa888", - "xdm:name": "Shop The Look", - "xdm:asset": { - "repo:path": "https://mystage1-amspro120.amscommerce.cloud/media/catalog/category/beachy.jpg", - "repo:id": "image-8a0806aaab", - "@type": "image" - } - }, - { - "repo:id": "category-df146c27a3", - "xdm:name": "Minimalist Sensibility", - "xdm:asset": null - } - ], - "xdm:currencyCode": "USD", - "dc:description": "

The Honora Wide Leg Pants definitely hold their own when it comes to standing out from the crowd. These pants feature a unique design and a varying color palette to make pairing a snap.

Features:

  • Elastic waistband
  • Drawstring waist
  • Sits just below the waist
  • 31" inseam
  • Machine wash, line dry
", - "dc:title": "Honora Wide Leg Pants", - "@type": "venia/components/commerce/product" - } + "product-dc59ad50df": { + "xdm:listPrice": 78.0, + "xdm:SKU": "VP05", + "xdm:assets": [ + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05-rn_main.jpg", + "repo:id": "image-2ea11abe0a", + "@type": "image" + }, + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05-rn_alt.jpg", + "repo:id": "image-35c39a6a6b", + "@type": "image" + }, + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05-rn_back.jpg", + "repo:id": "image-7ed6d7593b", + "@type": "image" + }, + { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/product/cache/dbba4389ce8da2ab9399ca5f8b677aac/v/p/vp05_look.jpg", + "repo:id": "image-3b4d560585", + "@type": "image" + } + ], + "xdm:categories": [ + { + "repo:id": "category-2212426126", + "xdm:name": "Bottoms", + "xdm:asset": { + "repo:path": "https://mcprod.catalogservice4commerce.fun/media/catalog/category/minimalist.jpg", + "repo:id": "image-9d427bd572", + "@type": "image" + } + }, + { + "repo:id": "category-3c1d5daf00", + "xdm:name": "Pants & Shorts", + "xdm:asset": null + }, + { + "repo:id": "category-77640b4209", + "xdm:name": "Shop The Look", + "xdm:asset": null + }, + { + "repo:id": "category-077469fda4", + "xdm:name": "Minimalist Sensibility", + "xdm:asset": null + } + ], + "xdm:currencyCode": "USD", + "dc:description": "

The Honora Wide Leg Pants definitely hold their own when it comes to standing out from the crowd. These pants feature a unique design and a varying color palette to make pairing a snap.

Features:

  • Elastic waistband
  • Drawstring waist
  • Sits just below the waist
  • 31" inseam
  • Machine wash, line dry
", + "dc:title": "Honora Wide Leg Pants", + "@type": "venia/components/commerce/product" + } } \ No newline at end of file