Skip to content

Commit 620a67b

Browse files
committed
Add UI tests for trend chart in project action with custom ID
1 parent 4d49992 commit 620a67b

File tree

2 files changed

+64
-23
lines changed

2 files changed

+64
-23
lines changed

ui-tests/src/main/java/io/jenkins/plugins/analysis/warnings/IssuesRecorder.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package io.jenkins.plugins.analysis.warnings;
22

3+
import org.openqa.selenium.WebElement;
4+
35
import java.util.List;
46
import java.util.function.Consumer;
57
import java.util.stream.Collectors;
68

7-
import org.openqa.selenium.WebElement;
8-
99
import org.jenkinsci.test.acceptance.po.AbstractStep;
1010
import org.jenkinsci.test.acceptance.po.Control;
1111
import org.jenkinsci.test.acceptance.po.Describable;
@@ -676,6 +676,7 @@ public static class StaticAnalysisTool extends PageAreaImpl {
676676
private final Control highThreshold = control("tool/highThreshold");
677677
private final Control id = control("tool/id");
678678
private final Control name = control("tool/name");
679+
private final Control icon = control("tool/icon");
679680
private final Control analysisModelId = control("tool/analysisModelId");
680681
private final Control skipSymbolicLinks = control("tool/skipSymbolicLinks");
681682

@@ -724,6 +725,20 @@ public StaticAnalysisTool setName(final String name) {
724725
return this;
725726
}
726727

728+
/**
729+
* Sets the custom name of the tool.
730+
*
731+
* @param icon
732+
* the icon
733+
*
734+
* @return this
735+
*/
736+
public StaticAnalysisTool setIcon(final String icon) {
737+
this.icon.set(icon);
738+
739+
return this;
740+
}
741+
727742
/**
728743
* Sets the pattern of the files to parse.
729744
*

ui-tests/src/test/java/io/jenkins/plugins/analysis/warnings/TrendChartsUiTest.java

+47-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.jenkins.plugins.analysis.warnings;
22

33
import org.junit.Test;
4+
import org.openqa.selenium.By;
45

56
import org.jenkinsci.test.acceptance.junit.WithPlugins;
67
import org.jenkinsci.test.acceptance.po.Build;
@@ -45,19 +46,59 @@ public void shouldDisplayDifferentTrendChartsOnClick() {
4546
assertThat(analysisResultPage.trendChartIsDisplayed(NEW_VERSUS_FIXED_TREND_CHART)).isTrue();
4647
}
4748

48-
/** Verifies all Charts after a series of 2 builds. */
49+
/** Verifies the charts after a series of 2 builds. */
4950
@Test
5051
public void shouldShowTrendChartsWithCorrectResults() {
51-
Build build = buildFreeStyleJobTwiceWithJavacIssues();
52-
AnalysisResult analysisResultPage = new AnalysisResult(build, "java");
52+
FreeStyleJob job = createFreeStyleJob(SOURCE_VIEW_FOLDER + "build_01");
53+
job.addPublisher(IssuesRecorder.class,
54+
recorder -> recorder.setToolWithPattern(JAVA_COMPILER, "**/*.txt")
55+
);
56+
job.save();
57+
58+
verifyTrendCharts(job, JAVA_ID, "java.svg");
59+
}
60+
61+
/** Verifies the charts with a custom ID after a series of 2 builds. */
62+
@Test
63+
public void shouldShowTrendChartsWithCustomId() {
64+
FreeStyleJob job = createFreeStyleJob(SOURCE_VIEW_FOLDER + "build_01");
65+
var id = "custom-id";
66+
var icon = "plugin/warnings-ng/icons/checkstyle.svg";
67+
job.addPublisher(IssuesRecorder.class, recorder ->
68+
recorder.setTool(JAVA_COMPILER, "**/*.txt")
69+
.setName("custom-name")
70+
.setIcon(icon)
71+
.setId(id)
72+
);
73+
job.save();
74+
75+
verifyTrendCharts(job, id, icon);
76+
}
77+
78+
private void verifyTrendCharts(final FreeStyleJob job, final String id, final String icon) {
79+
buildSuccessfully(job);
80+
81+
assertThat(job.all(By.className("echarts-trend"))).isEmpty();
82+
83+
reconfigureJobWithResource(job);
84+
Build build = buildSuccessfully(job);
85+
86+
job.open();
87+
assertThat(job.all(By.className("echarts-trend"))).hasSize(1)
88+
.first().satisfies(c -> assertThat(c.getDomAttribute("tool")).isEqualTo(id));
89+
assertThat(job.all(By.className("task-icon-link")))
90+
.anyMatch(c ->
91+
!c.findElements(By.xpath(".//img[contains(@src, '" + icon + "')]")).isEmpty());
92+
93+
AnalysisResult analysisResultPage = new AnalysisResult(build, id);
5394
analysisResultPage.open();
5495

5596
String severitiesTrendChart = analysisResultPage.getTrendChartById(SEVERITIES_TREND_CHART);
5697
String toolsTrendChart = analysisResultPage.getTrendChartById(TOOLS_TREND_CHART);
5798
String newVersusFixedTrendChart = analysisResultPage.getTrendChartById(NEW_VERSUS_FIXED_TREND_CHART);
5899

59100
verifySeveritiesChart(severitiesTrendChart);
60-
verifyToolsChart(toolsTrendChart);
101+
verifyToolsChart(toolsTrendChart, id);
61102
verifyNewVersusFixedChart(newVersusFixedTrendChart);
62103
}
63104

@@ -93,20 +134,14 @@ private void verifySeveritiesChart(final String severitiesTrendChart) {
93134
);
94135
}
95136

96-
/**
97-
* Verifies Tools Chart after a series of 2 builds.
98-
*
99-
* @param toolsTrendChart
100-
* JSONString with values from Severities Tools TrendChart
101-
*/
102-
private void verifyToolsChart(final String toolsTrendChart) {
137+
private void verifyToolsChart(final String toolsTrendChart, final String id) {
103138
assertThatJson(toolsTrendChart)
104139
.inPath("$.xAxis[*].data[*]")
105140
.isArray()
106141
.hasSize(2);
107142

108143
assertThatJson(toolsTrendChart)
109-
.node("series[0].name").isEqualTo("java");
144+
.node("series[0].name").isEqualTo(id);
110145

111146
assertThatJson(toolsTrendChart)
112147
.node("series[0].data")
@@ -145,13 +180,4 @@ private void verifyNewVersusFixedChart(final String newVersusFixedTrendChart) {
145180
private void reconfigureJobWithResource(final FreeStyleJob job) {
146181
job.configure(() -> job.copyResource("/" + SOURCE_VIEW_FOLDER + "build_02"));
147182
}
148-
149-
private Build buildFreeStyleJobTwiceWithJavacIssues() {
150-
FreeStyleJob job = createFreeStyleJob(SOURCE_VIEW_FOLDER + "build_01");
151-
job.addPublisher(IssuesRecorder.class, recorder -> recorder.setToolWithPattern(JAVA_COMPILER, "**/*.txt"));
152-
job.save();
153-
buildSuccessfully(job);
154-
reconfigureJobWithResource(job);
155-
return buildSuccessfully(job);
156-
}
157183
}

0 commit comments

Comments
 (0)