Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a tooltip with the full path for a file name table cell #56

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import edu.hm.hafner.coverage.Node;
import edu.hm.hafner.coverage.TestCount;

import j2html.tags.ContainerTag;

import hudson.Functions;

import io.jenkins.plugins.coverage.metrics.color.ColorProvider;
Expand Down Expand Up @@ -379,10 +381,20 @@ public void configureTable(final TableConfiguration tableConfiguration) {

@Override
public String renderFileName(final String fileName, final String path) {
ContainerTag cell;
if (SOURCE_CODE_FACADE.canRead(buildFolder, resultsId, path)) {
return a().withHref(String.valueOf(path.hashCode())).withText(fileName).render();
cell = a().withHref(String.valueOf(path.hashCode())).withText(fileName);
}
else {
cell = div().withText(fileName);
}
return fileName;
return renderWithToolTip(cell, path);
}

static String renderWithToolTip(final ContainerTag cell, final String path) {
return cell.attr("data-bs-toggle", "tooltip")
.attr("data-bs-placement", "top")
.withTitle(path).render();
}
}

Expand All @@ -397,7 +409,7 @@ public void configureTable(final TableConfiguration tableConfiguration) {

@Override
public String renderFileName(final String fileName, final String path) {
return fileName;
return LinkedRowRenderer.renderWithToolTip(div().withText(fileName), path);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import hudson.model.Run;

import io.jenkins.plugins.coverage.metrics.AbstractCoverageTest;
import io.jenkins.plugins.coverage.metrics.steps.CoverageTableModel.CoverageRow;
import io.jenkins.plugins.util.QualityGateResult;

import static io.jenkins.plugins.coverage.metrics.steps.CoverageViewModel.*;
Expand Down Expand Up @@ -59,6 +60,13 @@ void shouldReportOverview() {
assertThatJson(overview).node("metrics").isArray().containsExactly(expectedMetrics);
assertThatJson(overview).node("covered").isArray().containsExactlyElementsOf(expectedCovered);
assertThatJson(overview).node("missed").isArray().containsExactlyElementsOf(expectedMissed);

assertThat(model.getTableModel(ABSOLUTE_COVERAGE_TABLE_ID).getRows()).anySatisfy(
row -> assertThat(row).isInstanceOfSatisfying(CoverageRow.class,
coverageRow -> assertThat(coverageRow.getFileName().getDisplay())
.contains("title=\"edu/hm/hafner/util/",
"data-bs-toggle=\"tooltip\" data-bs-placement=\"top\""))
);
}

private static void ensureValidPercentages(final List<Double> percentages) {
Expand Down Expand Up @@ -92,7 +100,8 @@ private Node createIndirectCoverageChangesNode() {
@Test
void shouldProvideRightTableModelById() {
CoverageViewModel model = createModelFromCodingStyleReport();
assertThat(model.getTableModel(MODIFIED_LINES_COVERAGE_TABLE_ID)).isInstanceOf(ModifiedLinesCoverageTableModel.class);
assertThat(model.getTableModel(MODIFIED_LINES_COVERAGE_TABLE_ID)).isInstanceOf(
ModifiedLinesCoverageTableModel.class);
assertThat(model.getTableModel(INDIRECT_COVERAGE_TABLE_ID)).isInstanceOf(IndirectCoverageChangesTable.class);
assertThat(model.getTableModel(ABSOLUTE_COVERAGE_TABLE_ID)).isInstanceOf(CoverageTableModel.class);

Expand Down
Loading