Skip to content

Commit

Permalink
Updated the RunCoverageTest cases to take unescaped Html Report text
Browse files Browse the repository at this point in the history
  • Loading branch information
Rd4dev committed Aug 27, 2024
1 parent 9fe65f4 commit cd10039
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.oppia.android.scripts.coverage.reporter

import com.google.common.html.HtmlEscapers
import org.oppia.android.scripts.proto.Coverage
import org.oppia.android.scripts.proto.CoverageReport
import org.oppia.android.scripts.proto.CoverageReportContainer
Expand Down Expand Up @@ -277,7 +278,7 @@ class CoverageReporter(
"""
<tr>
<td class="line-number-row">${lineNumber.toString().padStart(4, ' ')}</td>
<td class="$lineClass">$line</td>
<td class="$lineClass">${HtmlEscapers.htmlEscaper().escape(line)}</td>
</tr>
""".trimIndent()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(kotlinFilePath)

assertThat(readHtmlReport(kotlinFilePath)).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(kotlinFilePath)
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand All @@ -342,7 +348,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(sourceFilePath)

assertThat(readHtmlReport(sourceFilePath)).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(sourceFilePath)
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand Down Expand Up @@ -541,7 +553,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(filePath)

assertThat(readHtmlReport(filePath)).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePath)
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand Down Expand Up @@ -1880,10 +1898,20 @@ class RunCoverageTest {
).execute()

val expectedResult1 = getExpectedHtmlText(filePathList.get(0))
assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult1)
val unescapedHtmlReport1 = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")
assertThat(unescapedHtmlReport1).isEqualTo(expectedResult1)

val expectedResult2 = getExpectedHtmlText(filePathList.get(1))
assertThat(readHtmlReport(filePathList.get(1))).isEqualTo(expectedResult2)
val unescapedHtmlReport2 = readHtmlReport(filePathList.get(1))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")
assertThat(unescapedHtmlReport2).isEqualTo(expectedResult2)
}

@Test
Expand All @@ -1910,7 +1938,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(filePathList.get(0))

assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand All @@ -1937,7 +1971,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(filePathList.get(0))

assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand All @@ -1964,7 +2004,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(filePathList.get(0))

assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand Down Expand Up @@ -2009,7 +2055,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(filePathList.get(0))

assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand All @@ -2036,7 +2088,13 @@ class RunCoverageTest {

val expectedResult = getExpectedHtmlText(filePathList.get(0))

assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand Down Expand Up @@ -2262,7 +2320,13 @@ class RunCoverageTest {
</html>
""".trimIndent()

assertThat(readHtmlReport(filePathList.get(0))).isEqualTo(expectedResult)
val unescapedHtmlReport = readHtmlReport(filePathList.get(0))
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedHtmlReport).isEqualTo(expectedResult)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,13 @@ class CoverageReporterTest {
</html>
""".trimIndent()

assertThat(outputReportText).isEqualTo(expectedHtml)
val unescapedOutputReportText = outputReportText
.replace("&quot;", "\"")
.replace("&amp;", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")

assertThat(unescapedOutputReportText).isEqualTo(expectedHtml)
}

@Test
Expand Down

0 comments on commit cd10039

Please sign in to comment.