Skip to content

Commit

Permalink
#207: Highlighting of test methods by line coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Feb 21, 2019
1 parent 61d7641 commit e64af8b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CHANGELOG

4.0.13.0

* New: Issue #207: Highlighting of test methods by line coverage
* Fix: Issue #212: Fixed name of SonarQube file

4.0.12.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void TestMethods(IEnumerable<TestMethod> testMethods, IEnumerable<FileAna
}

this.reportTextWriter.WriteLine(
"<label class=\"percentagebar{0}\" title=\"{1}{2}\"><input type=\"radio\" name=\"method\" value=\"AllTestMethods\" class=\"switchtestmethod\" checked=\"checked\" />{2}</label>",
"<label id=\"AllTestMethods\" class=\"testmethod percentagebar{0}\" title=\"{1}{2}\"><input type=\"radio\" name=\"method\" value=\"AllTestMethods\" class=\"switchtestmethod\" checked=\"checked\" />{2}</label>",
coverage.HasValue ? coverageRounded.ToString() : "undefined",
coverage.HasValue ? ReportResources.Coverage2 + " " + coverage.Value.ToString(CultureInfo.InvariantCulture) + "% - " : string.Empty,
WebUtility.HtmlEncode(ReportResources.All));
Expand All @@ -239,7 +239,7 @@ public void TestMethods(IEnumerable<TestMethod> testMethods, IEnumerable<FileAna
}

this.reportTextWriter.WriteLine(
"<br /><label class=\"percentagebar{0}\" title=\"{1}{2}\"><input type=\"radio\" name=\"method\" value=\"M{3}\" class=\"switchtestmethod\" />{4}</label>",
"<br /><label id=\"M{3}\" class=\"testmethod percentagebar{0}\" title=\"{1}{2}\"><input type=\"radio\" name=\"method\" value=\"M{3}\" class=\"switchtestmethod\" />{4}</label>",
coverage.HasValue ? coverageRounded.ToString() : "undefined",
coverage.HasValue ? ReportResources.Coverage2 + " " + coverage.Value.ToString(CultureInfo.InvariantCulture) + "% - " : string.Empty,
WebUtility.HtmlEncode(testMethod.Name),
Expand Down Expand Up @@ -731,7 +731,10 @@ public void LineAnalysis(int fileIndex, LineAnalysis analysis)

string lineVisitStatus = ConvertToCssClass(analysis.LineVisitStatus, false);

this.reportTextWriter.Write("<tr title=\"{0}\" data-coverage=\"{{", WebUtility.HtmlEncode(GetTooltip(analysis)));
this.reportTextWriter.Write(
"<tr class=\"{0}\" title=\"{1}\" data-coverage=\"{{",
analysis.LineVisitStatus > LineVisitStatus.NotCoverable ? "coverableline" : string.Empty,
WebUtility.HtmlEncode(GetTooltip(analysis)));

this.reportTextWriter.Write(
"'AllTestMethods': {{'VC': '{0}', 'LVS': '{1}'}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a:hover { color: #000; text-decoration: underline; }
.containerright { border-left: solid 1px #EAEAEA; display: table-cell; width: 340px; min-width: 340px; background-color: #fff; height: 100%; }
.containerrightfixed { position: fixed; padding: 0 20px 20px 20px; width: 300px; overflow-y: auto; height: 100%; top: 0; bottom: 0; }
.containerrightfixed h1 { background-color: rgba(248,248,248,1); }
.containerrightfixed label, .containerright a { white-space: nowrap; overflow: hidden; display: inline-block; max-width: 300px; text-overflow: ellipsis; }
.containerrightfixed label, .containerright a { white-space: nowrap; overflow: hidden; display: inline-block; width: 100%; max-width: 300px; text-overflow: ellipsis; }
.containerright a { margin-bottom: 3px; }

@media screen and (max-width:1200px){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a:hover { color: #000; text-decoration: none; }
.containerright { border-left: solid 1px #6f6f6f; display: table-cell; width: 340px; min-width: 340px; background-color: #e5e5e5; height: 100%; }
.containerrightfixed { position: fixed; padding: 0 20px 20px 20px; width: 300px; overflow-y: auto; height: 100%; top: 0; bottom: 0; }
.containerrightfixed h1 { background-color: #c00; }
.containerrightfixed label, .containerright a { white-space: nowrap; overflow: hidden; display: inline-block; max-width: 300px; text-overflow: ellipsis; }
.containerrightfixed label, .containerright a { white-space: nowrap; overflow: hidden; display: inline-block; width: 100%; max-width: 300px; text-overflow: ellipsis; }
.containerright a { margin-bottom: 3px; }

@media screen and (max-width:1200px){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var switchTestMethod = function () {
coverageData = JSON.parse(lines[i].getAttribute('data-coverage').replace(/'/g, '"'));
lineAnalysis = coverageData[method];
cells = lines[i].querySelectorAll('td');
if (lineAnalysis === null) {
if (lineAnalysis === undefined) {
lineAnalysis = coverageData.AllTestMethods;
if (lineAnalysis.LVS !== 'gray') {
cells[0].setAttribute('class', 'red');
Expand All @@ -45,6 +45,32 @@ for (i = 0, l = testMethods.length; i < l; i++) {
testMethods[i].addEventListener('change', switchTestMethod);
}

/* Highlight test method by line */
var highlightTestMethods = function () {
var lineAnalysis;
var coverageData = JSON.parse(this.getAttribute('data-coverage').replace(/'/g, '"'));
var testMethods = document.getElementsByClassName('testmethod');

for (i = 0, l = testMethods.length; i < l; i++) {
lineAnalysis = coverageData[testMethods[i].id];
if (lineAnalysis === undefined) {
testMethods[i].className = testMethods[i].className.replace(/\s*light.+/g, "");
} else {
testMethods[i].className += ' light' + lineAnalysis.LVS;
}
}
};
var unhighlightTestMethods = function () {
var testMethods = document.getElementsByClassName('testmethod');
for (i = 0, l = testMethods.length; i < l; i++) {
testMethods[i].className = testMethods[i].className.replace(/\s*light.+/g, "");
}
};
var coverableLines = document.getElementsByClassName('coverableline');
for (i = 0, l = coverableLines.length; i < l; i++) {
coverableLines[i].addEventListener('mouseenter', highlightTestMethods);
coverableLines[i].addEventListener('mouseleave', unhighlightTestMethods);
}

/* History charts */
var renderChart = function (chart) {
Expand Down

0 comments on commit e64af8b

Please sign in to comment.