|
1 | 1 | package io.jenkins.plugins.analysis.warnings;
|
2 | 2 |
|
3 | 3 | import org.junit.Test;
|
| 4 | +import org.openqa.selenium.By; |
4 | 5 |
|
5 | 6 | import org.jenkinsci.test.acceptance.junit.WithPlugins;
|
6 | 7 | import org.jenkinsci.test.acceptance.po.Build;
|
@@ -45,19 +46,59 @@ public void shouldDisplayDifferentTrendChartsOnClick() {
|
45 | 46 | assertThat(analysisResultPage.trendChartIsDisplayed(NEW_VERSUS_FIXED_TREND_CHART)).isTrue();
|
46 | 47 | }
|
47 | 48 |
|
48 |
| - /** Verifies all Charts after a series of 2 builds. */ |
| 49 | + /** Verifies the charts after a series of 2 builds. */ |
49 | 50 | @Test
|
50 | 51 | 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); |
53 | 94 | analysisResultPage.open();
|
54 | 95 |
|
55 | 96 | String severitiesTrendChart = analysisResultPage.getTrendChartById(SEVERITIES_TREND_CHART);
|
56 | 97 | String toolsTrendChart = analysisResultPage.getTrendChartById(TOOLS_TREND_CHART);
|
57 | 98 | String newVersusFixedTrendChart = analysisResultPage.getTrendChartById(NEW_VERSUS_FIXED_TREND_CHART);
|
58 | 99 |
|
59 | 100 | verifySeveritiesChart(severitiesTrendChart);
|
60 |
| - verifyToolsChart(toolsTrendChart); |
| 101 | + verifyToolsChart(toolsTrendChart, id); |
61 | 102 | verifyNewVersusFixedChart(newVersusFixedTrendChart);
|
62 | 103 | }
|
63 | 104 |
|
@@ -93,20 +134,14 @@ private void verifySeveritiesChart(final String severitiesTrendChart) {
|
93 | 134 | );
|
94 | 135 | }
|
95 | 136 |
|
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) { |
103 | 138 | assertThatJson(toolsTrendChart)
|
104 | 139 | .inPath("$.xAxis[*].data[*]")
|
105 | 140 | .isArray()
|
106 | 141 | .hasSize(2);
|
107 | 142 |
|
108 | 143 | assertThatJson(toolsTrendChart)
|
109 |
| - .node("series[0].name").isEqualTo("java"); |
| 144 | + .node("series[0].name").isEqualTo(id); |
110 | 145 |
|
111 | 146 | assertThatJson(toolsTrendChart)
|
112 | 147 | .node("series[0].data")
|
@@ -145,13 +180,4 @@ private void verifyNewVersusFixedChart(final String newVersusFixedTrendChart) {
|
145 | 180 | private void reconfigureJobWithResource(final FreeStyleJob job) {
|
146 | 181 | job.configure(() -> job.copyResource("/" + SOURCE_VIEW_FOLDER + "build_02"));
|
147 | 182 | }
|
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 |
| - } |
157 | 183 | }
|
0 commit comments