Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ private void initModel() {
Asset overrideAsset = assetResource.adaptTo(Asset.class);
assetOverride.put(categoryId, overrideAsset);
}
}

if (categoryIds.size() > 0) {
MagentoGraphqlClient magentoGraphqlClient = MagentoGraphqlClient.create(resource);
categoriesRetriever = new CategoriesRetriever(magentoGraphqlClient);
categoriesRetriever.setIdentifiers(categoryIds);
} else {
LOGGER.debug("There are no categories configured for CategoryList Component.");
if (categoryIds.size() > 0) {
MagentoGraphqlClient magentoGraphqlClient = MagentoGraphqlClient.create(resource);
categoriesRetriever = new CategoriesRetriever(magentoGraphqlClient);
categoriesRetriever.setIdentifiers(categoryIds);
}
}
}

Expand Down Expand Up @@ -138,6 +136,11 @@ public List<CategoryTree> getCategories() {
return categories;
}

@Override
public boolean isConfigured() {
return resource.getChild(ITEMS_PROP) != null;
}

@Override
public AbstractCategoriesRetriever getCategoriesRetriever() {
return this.categoriesRetriever;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public interface FeaturedCategoryList {
*/
AbstractCategoriesRetriever getCategoriesRetriever();

/**
* Returns true if the component is correctly configured, false otherwise.
*
* @return true or false
*/
boolean isConfigured();
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ public void setup() throws Exception {
@Test
public void verifyModel() {
Assert.assertNotNull(slingModelConfigured);
Assert.assertTrue(slingModelConfigured.isConfigured());
List<CategoryTree> list = slingModelConfigured.getCategories();
Assert.assertNotNull(list);
Assert.assertEquals(list.size(), 3);
}

@Test
public void verifyCategory() {
Assert.assertNotNull(slingModelConfigured);
Assert.assertTrue(slingModelConfigured.isConfigured());
categories = slingModelConfigured.getCategories();
Assert.assertNotNull(categories);
Assert.assertEquals(categories.get(0).getName(), TEST_CATEGORY_NAME);
Expand All @@ -146,6 +149,7 @@ public void verifyAssetOverride() {
public void verifyNotConfigired() {
Assert.assertNotNull(slingModelNotConfigured);
Assert.assertNull(slingModelNotConfigured.getCategoriesRetriever());
Assert.assertFalse(slingModelNotConfigured.isConfigured());
categories = slingModelNotConfigured.getCategories();
Assert.assertNotNull(categories);
Assert.assertEquals(categories.size(), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/-->

<sly data-sly-use.clientlib="/libs/granite/sightly/templates/clientlib.html"
data-sly-use.category="com.adobe.cq.commerce.core.components.models.categorylist.FeaturedCategoryList">
<sly data-sly-test.isConfigured="${category.categories.size}">
data-sly-use.category="com.adobe.cq.commerce.core.components.models.categorylist.FeaturedCategoryList"
data-sly-use.templates="core/wcm/components/commons/v1/templates.html">
<sly data-sly-test.hasCategories="${category.categories.size}">
<div class="cmp-categorylist">
<div class="cmp-categorylist__header">
<h2 class="cmp-categorylist__title">
Expand All @@ -33,10 +34,7 @@ <h2 class="cmp-categorylist__title">
</div>
</div>
</sly>
<div data-sly-test="${!isConfigured}" class="placeholder__empty">
<strong>${'Featured Category List' @ i18n}</strong><br>
<p>${'Please configure categories' @ i18n}</p>
</div>
<sly data-sly-call="${templates.placeholder @ isEmpty = !category.isConfigured, emptyTextAppend = 'Please configure categories'}" />
<sly data-sly-call="${templates.placeholder @ isEmpty = category.isConfigured && !hasCategories, emptyTextAppend = 'Configured, no categories were loaded'}" />
</sly>
</sly>