Skip to content

Commit

Permalink
Hide coverage section on the UI if there isn't any coverage data (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigatk committed Dec 22, 2021
1 parent 35759c6 commit d8d59d9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,12 @@ class CoverageDatabaseRepository(private val dslContext: DSLContext) : CoverageR
overallStatus
}

override suspend fun coverageExists(publicId: PublicId): Boolean =
override suspend fun coverageGroupExists(publicId: PublicId): Boolean =
withContext(Dispatchers.IO) {
dslContext.fetchExists(
dslContext.selectFrom(CODE_COVERAGE_RUN)
dslContext.select(CODE_COVERAGE_RUN.ID)
.from(CODE_COVERAGE_RUN)
.innerJoin(CODE_COVERAGE_GROUP).on(CODE_COVERAGE_RUN.ID.eq(CODE_COVERAGE_GROUP.CODE_COVERAGE_RUN_ID))
.where(CODE_COVERAGE_RUN.TEST_RUN_PUBLIC_ID.eq(publicId.id))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface CoverageRepository {

suspend fun fetchCoverageList(publicId: PublicId): List<CoverageReport>

suspend fun coverageExists(publicId: PublicId): Boolean
suspend fun coverageGroupExists(publicId: PublicId): Boolean

suspend fun fetchCoverageFiles(publicId: PublicId, groupName: String): List<CoverageFile>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class CoverageService(
}

suspend fun coverageExists(publicId: PublicId): Boolean =
coverageRepository.coverageExists(publicId)
coverageRepository.coverageGroupExists(publicId)

suspend fun deleteCoverage(publicId: PublicId) =
coverageRepository.deleteCoverage(publicId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package projektor.coverage

import io.ktor.util.*
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import projektor.DatabaseRepositoryTestCase
Expand Down Expand Up @@ -224,19 +223,33 @@ class CoverageDatabaseRepositoryTest : DatabaseRepositoryTestCase() {
)
runBlocking { coverageDatabaseRepository.addCoverageReport(coverageRun, coverageReport) }

val hasCoverageData = runBlocking { coverageDatabaseRepository.coverageExists(publicId) }
val hasCoverageData = runBlocking { coverageDatabaseRepository.coverageGroupExists(publicId) }

expectThat(hasCoverageData).isTrue()
}

@Test
fun `when no coverage data should return false when checking if coverage exists`() {
fun `when no coverage run should return false when checking if coverage exists`() {
val coverageDatabaseRepository = CoverageDatabaseRepository(dslContext)

val publicId = randomPublicId()
testRunDBGenerator.createTestRun(publicId, listOf())

val hasCoverageData = runBlocking { coverageDatabaseRepository.coverageExists(publicId) }
val hasCoverageData = runBlocking { coverageDatabaseRepository.coverageGroupExists(publicId) }

expectThat(hasCoverageData).isFalse()
}

@Test
fun `when has coverage run but no coverage groups should return false when checking if coverage exists`() {
val coverageDatabaseRepository = CoverageDatabaseRepository(dslContext)

val publicId = randomPublicId()
testRunDBGenerator.createTestRun(publicId, listOf())

runBlocking { coverageDatabaseRepository.createOrGetCoverageRun(publicId) }

val hasCoverageData = runBlocking { coverageDatabaseRepository.coverageGroupExists(publicId) }

expectThat(hasCoverageData).isFalse()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fun loadSixFailingTests() {
}

fun loadPassingGroupedExample() {
val saveResultsResponse = sendGroupedResultsToServer(groupedResultsXmlLoader.passingGroupedResults(null))
val saveResultsResponse = sendGroupedResultsToServer(groupedResultsXmlLoader.resultsWithCoverage(resultsXmls = listOf(resultsXmlLoader.passing()), coverageXmls = listOf()))
println("View run with passing grouped tests at at $uiBaseUrl${saveResultsResponse.uri}")
}

Expand Down

0 comments on commit d8d59d9

Please sign in to comment.