Skip to content

Commit e01c0d1

Browse files
Add improvement for icon on sidebar report action (#334)
* Updated getIconFileName method to handle non existing files
1 parent b4b9dd1 commit e01c0d1

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/main/java/htmlpublisher/HtmlPublisherTarget.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ public String getIconFileName() {
286286
icon = actualHtmlPublisherTarget.icon;
287287
}
288288
else {
289-
icon = project.getUrl() + dir().getName() + "/" + actualHtmlPublisherTarget.icon;
289+
File iconFile = new File(dir(), actualHtmlPublisherTarget.icon);
290+
291+
if(iconFile.exists()){
292+
icon = project.getUrl() + dir().getName() + "/" + actualHtmlPublisherTarget.icon;
293+
}else{
294+
icon = "symbol-document-text";
295+
}
290296
}
291297
} else {
292298
icon = "symbol-document-text";

src/test/java/htmlpublisher/workflow/PublishHTMLStepTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,57 @@ public void publishMissingReport_allowMissing() throws Exception {
182182
assertNull("Report should be missing", report);
183183
}
184184

185+
@Test
186+
public void testGetIconFileNameSymbolIcon() throws Exception {
187+
// Prepare the environment
188+
writeTestHTML("index.html");
189+
190+
// Run the project
191+
HtmlPublisherTarget target = new HtmlPublisherTarget("testReport", TEST_REPORT_DIR, "index.html", true, false, false);
192+
target.setIcon("symbol-custom-icon");
193+
setupAndRunProject(target);
194+
195+
// Verify that getIconFileName() correctly returns the custom icon
196+
HtmlPublisherTarget.HTMLAction jobReport = target.new HTMLAction(job, target);
197+
assertNotNull("Report should exist", jobReport);
198+
assertEquals("symbol-custom-icon", jobReport.getIconFileName());
199+
}
200+
201+
@Test
202+
public void testGetIconFileNameCustomPath() throws Exception {
203+
// Prepare the environment
204+
writeTestHTML("index.html");
205+
testReportDir.mkdirs();
206+
File customIconFile = new File(testReportDir, "custom-icon.png");
207+
customIconFile.createNewFile();
208+
209+
// Run the project
210+
HtmlPublisherTarget target = new HtmlPublisherTarget("testReport", TEST_REPORT_DIR, "index.html", true, false, false);
211+
target.setIcon("custom-icon.png");
212+
setupAndRunProject(target);
213+
214+
// Verify that getIconFileName() correctly returns the specified file
215+
HtmlPublisherTarget.HTMLAction jobReport = target.new HTMLAction(job, target);
216+
assertNotNull("Report should exist", jobReport);
217+
assertTrue("Icon should contain project URL", jobReport.getIconFileName().contains("custom-icon.png"));
218+
}
219+
220+
@Test
221+
public void testGetIconFileNameDefaultIfMissingFile() throws Exception {
222+
// Prepare the environment
223+
writeTestHTML("index.html");
224+
225+
// Run the project
226+
HtmlPublisherTarget target = new HtmlPublisherTarget("testReport", TEST_REPORT_DIR, "index.html", true, false, false);
227+
target.setIcon("custom-icon.png");
228+
setupAndRunProject(target);
229+
230+
// Verify that getIconFileName() correctly returns the default icon
231+
HtmlPublisherTarget.HTMLAction jobReport = target.new HTMLAction(job, target);
232+
assertNotNull("Report should exist", jobReport);
233+
assertEquals("symbol-document-text", jobReport.getIconFileName());
234+
}
235+
185236
private void writeTestHTML(String fileName) throws Exception {
186237
// Prepare the test file
187238
if (!testReportDir.exists() && !testReportDir.mkdirs()) {

0 commit comments

Comments
 (0)