Skip to content

Commit 8d16dd1

Browse files
committed
SITES-28693 - Teaser Component Renders Broken HTML When Title is Empty
* Added integration test * Added test content
1 parent 66f9553 commit 8d16dd1

File tree

2 files changed

+225
-0
lines changed
  • testing/it
    • http/src/test/java/com/adobe/cq/wcm/core/components/it/http

2 files changed

+225
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.adobe.cq.wcm.core.components.it.http;
2+
3+
import org.apache.sling.testing.clients.ClientException;
4+
import org.jsoup.Jsoup;
5+
import org.jsoup.select.Elements;
6+
import org.junit.Assert;
7+
import org.junit.BeforeClass;
8+
import org.junit.ClassRule;
9+
import org.junit.Rule;
10+
import org.junit.Test;
11+
import org.junit.rules.ErrorCollector;
12+
13+
import com.adobe.cq.testing.client.CQClient;
14+
import com.adobe.cq.testing.junit.rules.CQAuthorPublishClassRule;
15+
import com.adobe.cq.testing.junit.rules.CQRule;
16+
17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertNotNull;
19+
20+
public class TeaserIT {
21+
@ClassRule
22+
public static final CQAuthorPublishClassRule cqBaseClassRule = new CQAuthorPublishClassRule();
23+
24+
@Rule
25+
public CQRule cqBaseRule = new CQRule(cqBaseClassRule.authorRule, cqBaseClassRule.publishRule);
26+
27+
@Rule
28+
public ErrorCollector collector = new ErrorCollector();
29+
30+
static CQClient adminPublish;
31+
32+
@BeforeClass
33+
public static void beforeClass() {
34+
adminPublish = cqBaseClassRule.publishRule.getAdminClient(CQClient.class);
35+
}
36+
37+
@Test
38+
public void testNoNestedLinkElements() throws ClientException {
39+
String content = adminPublish.doGet("/content/core-components/teaser/teaser-links.html", 200).getContent();
40+
Elements html = Jsoup.parse(content).select("html");
41+
assertNotNull(html);
42+
// Expect no nesting of <a> tags
43+
assertEquals("Expected no nested links", 0, html.select("a a").size());
44+
// Expect only teaser with not CTAs and not content to have image link
45+
assertEquals("Mismatched image links", 1, html.select("a > img").size());
46+
// Expect only teaser with no CTAs and content to have global link
47+
assertEquals("Mismatched teaser content links", 1, html.select("a .cmp-teaser__content").size());
48+
// Expect teasers with CTAs to have CTA links
49+
assertEquals("Mismatched teaser content links", 2, html.select("a.cmp-teaser__action-link").size());
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
3+
jcr:primaryType="cq:Page">
4+
<jcr:content
5+
cq:template="/conf/core-components/settings/wcm/templates/responsive-template"
6+
jcr:primaryType="cq:PageContent"
7+
jcr:title="Teaser Links"
8+
sling:resourceType="core/wcm/components/page/v2/page">
9+
<root
10+
jcr:primaryType="nt:unstructured"
11+
sling:resourceType="core/wcm/components/container/v1/container"
12+
layout="responsiveGrid">
13+
<main
14+
jcr:primaryType="nt:unstructured"
15+
sling:resourceType="core/wcm/components/container/v1/container"
16+
layout="responsiveGrid">
17+
<container_v1
18+
jcr:primaryType="nt:unstructured"
19+
sling:resourceType="core-component/components/container-v1">
20+
<cq:responsive jcr:primaryType="nt:unstructured">
21+
<default
22+
jcr:primaryType="nt:unstructured"
23+
offset="0"
24+
width="4"/>
25+
</cq:responsive>
26+
<title_v3_176962574
27+
jcr:primaryType="nt:unstructured"
28+
jcr:title="Teasers With CTAs"
29+
sling:resourceType="core-component/components/title-v3"
30+
linkTarget="_self"
31+
type="h2"/>
32+
<title_v3
33+
jcr:primaryType="nt:unstructured"
34+
jcr:title="No Title"
35+
sling:resourceType="core-component/components/title-v3"
36+
linkTarget="_self"
37+
type="h3"/>
38+
<teaser_v2
39+
jcr:description="&lt;p>Teaser description&lt;/p>&#xd;&#xa;"
40+
jcr:primaryType="nt:unstructured"
41+
sling:resourceType="core-component/components/teaser-v2"
42+
altValueFromDAM="true"
43+
descriptionFromPage="false"
44+
fileReference="/content/dam/core-components/core-comp-test-image.jpg"
45+
id="no-title-teaser"
46+
imageFromPageImage="false"
47+
isDecorative="false"
48+
linkTarget="_self"
49+
linkURL="/content/core-components/teaser"
50+
pretitle="Teaser Pretitle"
51+
textIsRich="true"
52+
titleFromPage="false">
53+
<actions jcr:primaryType="nt:unstructured">
54+
<item0
55+
jcr:primaryType="nt:unstructured"
56+
link="/content/core-components/teaser"
57+
linkTarget="_self"
58+
text="Teaser"/>
59+
</actions>
60+
</teaser_v2>
61+
<title_v3_1270847366
62+
jcr:primaryType="nt:unstructured"
63+
jcr:title="No Title, No Description"
64+
sling:resourceType="core-component/components/title-v3"
65+
linkTarget="_self"
66+
type="h3"/>
67+
<teaser_v2_1192909202
68+
jcr:primaryType="nt:unstructured"
69+
sling:resourceType="core-component/components/teaser-v2"
70+
altValueFromDAM="true"
71+
descriptionFromPage="false"
72+
fileReference="/content/dam/core-components/core-comp-test-image.jpg"
73+
id="no-title-no-description-teaser"
74+
imageFromPageImage="false"
75+
isDecorative="false"
76+
linkTarget="_self"
77+
linkURL="/content/core-components/teaser"
78+
textIsRich="true"
79+
titleFromPage="false">
80+
<actions jcr:primaryType="nt:unstructured">
81+
<item0
82+
jcr:primaryType="nt:unstructured"
83+
link="/content/core-components/teaser"
84+
linkTarget="_self"
85+
text="Teaser"/>
86+
</actions>
87+
</teaser_v2_1192909202>
88+
</container_v1>
89+
<container_v1_667737784
90+
jcr:primaryType="nt:unstructured"
91+
sling:resourceType="core-component/components/container-v1">
92+
<cq:responsive jcr:primaryType="nt:unstructured">
93+
<default
94+
jcr:primaryType="nt:unstructured"
95+
offset="1"
96+
width="4"/>
97+
</cq:responsive>
98+
<title_v3
99+
jcr:primaryType="nt:unstructured"
100+
jcr:title="Teasers Without CTAs"
101+
sling:resourceType="core-component/components/title-v3"
102+
linkTarget="_self"
103+
type="h2"/>
104+
<title_v3_111614642
105+
jcr:primaryType="nt:unstructured"
106+
jcr:title="No Title, No CTAs"
107+
sling:resourceType="core-component/components/title-v3"
108+
linkTarget="_self"
109+
type="h3"/>
110+
<teaser_v2_1776259748
111+
jcr:description="&lt;p>Teaser descriptiom&lt;/p>&#xd;&#xa;"
112+
jcr:primaryType="nt:unstructured"
113+
sling:resourceType="core-component/components/teaser-v2"
114+
altValueFromDAM="true"
115+
descriptionFromPage="false"
116+
fileReference="/content/dam/core-components/core-comp-test-image.jpg"
117+
imageFromPageImage="false"
118+
isDecorative="false"
119+
linkTarget="_self"
120+
linkURL="/content/core-components/teaser"
121+
pretitle="Teaser Pretitle"
122+
textIsRich="true"
123+
titleFromPage="false"/>
124+
<title_v3_319733326
125+
jcr:primaryType="nt:unstructured"
126+
jcr:title="No Title, No Description, No CTAs"
127+
sling:resourceType="core-component/components/title-v3"
128+
linkTarget="_self"
129+
type="h3"/>
130+
<teaser_v2_1868491878
131+
jcr:primaryType="nt:unstructured"
132+
sling:resourceType="core-component/components/teaser-v2"
133+
altValueFromDAM="true"
134+
descriptionFromPage="false"
135+
fileReference="/content/dam/core-components/core-comp-test-image.jpg"
136+
id="no-title-no-description-no-ctas-teaser"
137+
imageFromPageImage="false"
138+
isDecorative="false"
139+
linkTarget="_self"
140+
linkURL="/content/core-components/teaser"
141+
textIsRich="true"
142+
titleFromPage="false"/>
143+
<title_v3_2083027106
144+
jcr:primaryType="nt:unstructured"
145+
jcr:title="Empty Teaser"
146+
sling:resourceType="core-component/components/title-v3"
147+
linkTarget="_self"
148+
type="h3"/>
149+
<teaser_v2_125774266
150+
jcr:primaryType="nt:unstructured"
151+
sling:resourceType="core-component/components/teaser-v2"
152+
descriptionFromPage="false"
153+
id="empty-teaser"
154+
imageFromPageImage="true"
155+
isDecorative="true"
156+
linkTarget="_self"
157+
linkURL="/content/core-components/teaser"
158+
textIsRich="true"
159+
titleFromPage="false"/>
160+
</container_v1_667737784>
161+
</main>
162+
<aside
163+
jcr:primaryType="nt:unstructured"
164+
sling:resourceType="core/wcm/components/container/v1/container">
165+
<tableofcontents_v1
166+
jcr:primaryType="nt:unstructured"
167+
sling:resourceType="core-component/components/tableofcontents-v1"
168+
listType="bulleted"
169+
startLevel="h2"
170+
stopLevel="h6"/>
171+
</aside>
172+
</root>
173+
</jcr:content>
174+
</jcr:root>

0 commit comments

Comments
 (0)