Skip to content

Commit 67c625b

Browse files
committed
Add tests for grid layout for nesting and em - rem values
DEVSIX-8338
1 parent 02e5599 commit 67c625b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1774
-0
lines changed

src/test/java/com/itextpdf/html2pdf/css/grid/GridAreaTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public void templateAreasWithDotsTest() throws IOException, InterruptedException
7171
runTest("templateAreasWithDots");
7272
}
7373

74+
@Test
75+
public void templateAreasSwitchedPlacesTest() throws IOException, InterruptedException {
76+
runTest("grid-area-switched-places");
77+
}
78+
7479
@Test
7580
@LogMessages(messages = @LogMessage(messageTemplate = Html2PdfLogMessageConstant.GRID_TEMPLATE_AREAS_IS_INVALID))
7681
public void invalidTemplateAreasTest() throws IOException, InterruptedException {
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2024 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.html2pdf.css.grid;
24+
25+
import com.itextpdf.forms.logs.FormsLogMessageConstants;
26+
import com.itextpdf.html2pdf.ConverterProperties;
27+
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
28+
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
29+
import com.itextpdf.io.logs.IoLogMessageConstant;
30+
import com.itextpdf.test.annotations.LogMessage;
31+
import com.itextpdf.test.annotations.LogMessages;
32+
33+
import java.io.IOException;
34+
import org.junit.jupiter.api.BeforeAll;
35+
import org.junit.jupiter.api.Tag;
36+
import org.junit.jupiter.api.Test;
37+
38+
@Tag("IntegrationTest")
39+
public class GridTemplateNestedTest extends ExtendedHtmlConversionITextTest {
40+
public static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/css/grid"
41+
+ "/GridTemplateNestedTest/";
42+
public static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/html2pdf/css/grid"
43+
+ "/GridTemplateNestedTest/";
44+
45+
//TODO DEVSIX-3340 change cmp files when GRID LAYOUT is supported
46+
47+
@BeforeAll
48+
public static void beforeClass() {
49+
createOrClearDestinationFolder(DESTINATION_FOLDER);
50+
}
51+
52+
53+
@Test
54+
public void templateNestedAreasTest() throws IOException, InterruptedException {
55+
runTest("grid-nested-areas");
56+
}
57+
58+
@Test
59+
public void templateNestedArticlesTest() throws IOException, InterruptedException {
60+
runTest("grid-nested-articles");
61+
}
62+
63+
@Test
64+
public void templateNestedFormsTest() throws IOException, InterruptedException {
65+
runTest("grid-nested-forms");
66+
}
67+
68+
@Test
69+
public void templateNestedGridTest() throws IOException, InterruptedException {
70+
runTest("grid-nested-grid");
71+
}
72+
73+
@Test
74+
public void templateNestedListsTest() throws IOException, InterruptedException {
75+
runTest("grid-nested-lists");
76+
}
77+
78+
@Test
79+
public void templateNestedListsOddEvenTest() throws IOException, InterruptedException {
80+
runTest("grid-nested-lists-odd-even");
81+
}
82+
83+
@Test
84+
public void templateNestedMixedContentTest() throws IOException, InterruptedException {
85+
runTest("grid-nested-mixed-content");
86+
}
87+
88+
@Test
89+
public void templateNestedParagraphsTest() throws IOException, InterruptedException {
90+
runTest("grid-nested-paragraphs");
91+
}
92+
93+
@Test
94+
public void templateNestedImagesTest() throws IOException, InterruptedException {
95+
runTest("grid-nested-images");
96+
}
97+
98+
@Test
99+
public void templateNestedTableTest() throws IOException, InterruptedException {
100+
runTest("grid-nested-table");
101+
}
102+
103+
@LogMessages(messages = @LogMessage(
104+
messageTemplate = IoLogMessageConstant.TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH, count = 2))
105+
@Test
106+
public void templateNestedTableNestedGridTest() throws IOException, InterruptedException {
107+
runTest("grid-nested-table-nested-grid");
108+
}
109+
110+
@Test
111+
public void templateNestedTableMixedContentTest() throws IOException, InterruptedException {
112+
runTest("grid-nested-table-with-mixed-content");
113+
}
114+
115+
@Test
116+
public void templateNested2LevelsWithAreasTest() throws IOException, InterruptedException {
117+
runTest("grid-nested-2-levels-areas");
118+
}
119+
120+
@LogMessages(messages = {
121+
@LogMessage(messageTemplate = IoLogMessageConstant.CLIP_ELEMENT, count = 5)
122+
})
123+
@Test
124+
public void templateNested3LevelsFormsTest() throws IOException, InterruptedException {
125+
runTest("grid-nested-3-forms");
126+
}
127+
128+
@Test
129+
public void templateNested3LevelsTest() throws IOException, InterruptedException {
130+
runTest("grid-nested-3-levels");
131+
}
132+
133+
@Test
134+
public void templateNested3LevelsMultipleTest() throws IOException, InterruptedException {
135+
runTest("grid-nested-3-levels-multiple");
136+
}
137+
138+
@Test
139+
public void templateNested3LevelsTablesTest() throws IOException, InterruptedException {
140+
runTest("grid-nested-3-levels-tables");
141+
}
142+
143+
144+
private void runTest(String testName) throws IOException, InterruptedException {
145+
convertToPdfAndCompare(testName,
146+
SOURCE_FOLDER, DESTINATION_FOLDER, false,
147+
new ConverterProperties().setBaseUri(SOURCE_FOLDER).setCssGridEnabled(true));
148+
}
149+
}

src/test/java/com/itextpdf/html2pdf/css/grid/GridTemplatesTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ public void gridWithTableTest() throws IOException, InterruptedException {
330330
runTest("gridWithTableTest");
331331
}
332332

333+
@Test
334+
public void basicGridRemValuesTest() throws IOException, InterruptedException {
335+
runTest("grid-layout-rem");
336+
}
337+
338+
@Test
339+
public void basicGridEmValuesTest() throws IOException, InterruptedException {
340+
runTest("grid-layout-em");
341+
}
342+
333343
@Test
334344
public void gridLayoutDisablingTest() throws IOException, InterruptedException {
335345
convertToPdfAndCompare("basicColumnFewDivsTest",
Binary file not shown.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<style>
5+
.container {
6+
display: grid;
7+
grid-template-columns: 300px 300px;
8+
grid-template-rows: auto;
9+
row-gap: 10px;
10+
column-gap: 10px;
11+
padding: 15px;
12+
}
13+
.grid-elem {
14+
color: white;
15+
font-size: 20px;
16+
background-color: darkblue;
17+
padding: 20px;
18+
border-radius: 0.5rem;
19+
}
20+
.third {
21+
grid-area: 1;
22+
background-color: #81b29a;
23+
}
24+
.fourth {
25+
grid-area: 3 / 2;
26+
background-color: #81b29a;
27+
}
28+
29+
</style>
30+
</head>
31+
<body>
32+
<div class="container">
33+
<div class="grid-elem">
34+
<p>1st elem</p>
35+
</div>
36+
<div class="grid-elem">
37+
<p>2nd elem</p>
38+
</div>
39+
<div class="grid-elem third">
40+
<p>3rd elem</p>
41+
</div>
42+
<div class="grid-elem fourth">
43+
<p>4th elem</p>
44+
</div>
45+
<div class="grid-elem">
46+
<p>5th elem</p>
47+
</div>
48+
<div class="grid-elem">
49+
<p>6th elem</p>
50+
</div>
51+
</div>
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)