Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITES-28693 - Teaser Component Renders Broken HTML When Title is Empty #2921

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -81,7 +81,8 @@ protected void initImage() {
overriddenImageResourceProperties.put(Teaser.PN_ACTIONS_ENABLED, Boolean.valueOf(actionsEnabled).toString());
overriddenImageResourceProperties.put(PN_ID, String.join(ID_SEPARATOR, this.getId(), IMAGE_ID_PREFIX));

if (StringUtils.isNotEmpty(getTitle()) || getTeaserActions().size() > 0) {
// Only allow image to render links if all other elements are empty
if (!(StringUtils.isAllEmpty(getTitle(), getPretitle(), getDescription()) && getTeaserActions().isEmpty())) {
overriddenImageResourceProperties.put(Teaser.PN_IMAGE_LINK_HIDDEN, Boolean.TRUE.toString());
}
super.initImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

import java.util.Objects;

import com.adobe.cq.ui.wcm.commons.config.NextGenDynamicMediaConfig;
import com.adobe.cq.wcm.core.components.models.Component;
import com.adobe.cq.wcm.core.components.testing.MockNextGenDynamicMediaConfig;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -28,23 +25,26 @@

import com.adobe.cq.wcm.core.components.Utils;
import com.adobe.cq.wcm.core.components.commons.link.Link;
import com.adobe.cq.wcm.core.components.models.Component;
import com.adobe.cq.wcm.core.components.models.ListItem;
import com.adobe.cq.wcm.core.components.models.Teaser;
import com.adobe.cq.wcm.core.components.testing.MockNextGenDynamicMediaConfig;
import com.day.cq.wcm.foundation.Image;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

import static com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertValidLink;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

@ExtendWith(AemContextExtension.class)
public class TeaserImplTest extends com.adobe.cq.wcm.core.components.internal.models.v1.TeaserImplTest {

private static final String TEST_BASE = "/teaser/v2";
private static final String TEASER_25 = TEST_ROOT_PAGE + TEST_ROOT_PAGE_GRID + "/teaser-25";
private static final String TEASER_26 = TEST_ROOT_PAGE + TEST_ROOT_PAGE_GRID + "/teaser-26";
private static final String TEASER_27 = TEST_ROOT_PAGE + TEST_ROOT_PAGE_GRID + "/teaser-27";
private static final String TEASER_28 = TEST_ROOT_PAGE + TEST_ROOT_PAGE_GRID + "/teaser-28";

@BeforeEach
protected void setUp() {
Expand Down Expand Up @@ -206,4 +206,28 @@ protected void testTeaserWithNgdmImage() {
assertEquals("Teasers Test", teaser.getTitle());
Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser26"));
}

@Test
protected void testTeaserWithImageAndLinkAndNoTitleAndPretitleAndNoDescription() {
Teaser teaser = getTeaserUnderTest(TEASER_27);
assertEquals("Teaser Pre-title", teaser.getPretitle());
assertNull(teaser.getTitle());
assertNull(teaser.getDescription());
ValueMap imageValueMap = teaser.getImageResource().getValueMap();
assertEquals("/content/page1", imageValueMap.get(Image.PN_LINK_URL));
assertTrue(imageValueMap.get(Teaser.PN_IMAGE_LINK_HIDDEN, Boolean.class));
Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser27"));
}

@Test
protected void testTeaserWithImageAndLinkAndNoTitleAndNoPretitleAndNoDescription() {
Teaser teaser = getTeaserUnderTest(TEASER_28);
assertNull(teaser.getPretitle());
assertNull(teaser.getTitle());
assertNull(teaser.getDescription());
ValueMap imageValueMap = teaser.getImageResource().getValueMap();
assertEquals("/content/page1", imageValueMap.get(Image.PN_LINK_URL));
assertNull(imageValueMap.get(Teaser.PN_IMAGE_LINK_HIDDEN, Boolean.class));
Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser28"));
}
}
20 changes: 20 additions & 0 deletions bundles/core/src/test/resources/teaser/v2/exporter-teaser27.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id" : "teaser-721d56e29c",
"pretitle" : "Teaser Pre-title",
"actionsEnabled" : true,
"imageLinkHidden": false,
"titleLinkHidden": false,
"actions" : [],
"link" : {
"valid": true,
"url" : "/core/content/page1.html"
},
"imagePath" : "/core/content/teasers/_jcr_content/root/responsivegrid/teaser-27.coreimg.png/1490005239000/adobe-systems-logo-and-wordmark.png",
":type" : "core/wcm/components/teaser/v2/teaser",
"dataLayer" : {
"teaser-721d56e29c": {
"@type" : "core/wcm/components/teaser/v2/teaser",
"xdm:linkURL" : "/core/content/page1.html"
}
}
}
19 changes: 19 additions & 0 deletions bundles/core/src/test/resources/teaser/v2/exporter-teaser28.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id" : "teaser-2dda15a9bc",
"actionsEnabled" : true,
"imageLinkHidden": false,
"titleLinkHidden": false,
"actions" : [],
"link" : {
"valid": true,
"url" : "/core/content/page1.html"
},
"imagePath" : "/core/content/teasers/_jcr_content/root/responsivegrid/teaser-28.coreimg.png/1490005239000/adobe-systems-logo-and-wordmark.png",
":type" : "core/wcm/components/teaser/v2/teaser",
"dataLayer" : {
"teaser-2dda15a9bc": {
"@type" : "core/wcm/components/teaser/v2/teaser",
"xdm:linkURL" : "/core/content/page1.html"
}
}
}
17 changes: 17 additions & 0 deletions bundles/core/src/test/resources/teaser/v2/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,23 @@
"sling:resourceType": "core/wcm/components/teaser/v2/teaser",
"titleFromPage": true,
"descriptionFromPage": true
},
"teaser-27" : {
"jcr:primaryType" : "nt:unstructured",
"linkURL" : "/content/page1",
"fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png",
"sling:resourceType" : "core/wcm/components/teaser/v2/teaser",
"pretitle" : "Teaser Pre-title",
"titleFromPage" : false,
"descriptionFromPage" : false
},
"teaser-28" : {
"jcr:primaryType" : "nt:unstructured",
"linkURL" : "/content/page1",
"fileReference" : "/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png",
"sling:resourceType" : "core/wcm/components/teaser/v2/teaser",
"titleFromPage" : false,
"descriptionFromPage" : false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
data-cmp-data-layer="${teaser.data.json}">
<a class="cmp-teaser__link"
data-sly-attribute="${teaser.link.htmlAttributes}"
data-sly-unwrap="${!teaser.link.valid || !teaser.actions.empty}"
data-sly-unwrap="${!teaser.link.valid || !teaser.actions.empty || !(teaser.pretitle || teaser.title || teaser.description)}"
data-cmp-clickable="${teaser.data ? true : false}">
<div class="cmp-teaser__content">
<sly data-sly-call="${pretitleTemplate.pretitle @ teaser=teaser}"></sly>
Expand Down
Loading