-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding test run badge to main page (#1219)
- Loading branch information
Showing
10 changed files
with
176 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
server/server-app/src/test/kotlin/projektor/badge/TestRunTestsBadgeApplicationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package projektor.badge | ||
|
||
import io.ktor.http.* | ||
import io.ktor.server.testing.* | ||
import org.junit.jupiter.api.Test | ||
import projektor.ApplicationTestCase | ||
import projektor.incomingresults.randomPublicId | ||
import projektor.util.randomOrgAndRepo | ||
import strikt.api.expectThat | ||
import strikt.assertions.contains | ||
import strikt.assertions.isEqualTo | ||
import strikt.assertions.isNotNull | ||
|
||
class TestRunTestsBadgeApplicationTest : ApplicationTestCase() { | ||
@Test | ||
fun `when test run passed should tests create badge`() { | ||
val repoName = randomOrgAndRepo() | ||
|
||
val publicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/run/$publicId/badge/tests") { | ||
testRunDBGenerator.createSimpleTestRunInRepo(publicId, repoName, true, null) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
expectThat(response.contentType().toString()).contains(ContentType.Image.SVG.toString()) | ||
|
||
expectThat(response.content).isNotNull().contains("passing") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when test run failed should tests create badge`() { | ||
val repoName = randomOrgAndRepo() | ||
|
||
val publicId = randomPublicId() | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Get, "/run/$publicId/badge/tests") { | ||
testRunDBGenerator.createSimpleFailingTestRunInRepo(publicId, repoName, true, null) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
expectThat(response.contentType().toString()).contains(ContentType.Image.SVG.toString()) | ||
|
||
expectThat(response.content).isNotNull().contains("failing") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from "react"; | ||
import TestsBadge from "./TestsBadge"; | ||
import { fetchTestsBadge } from "../../service/TestRunService"; | ||
|
||
interface TestRunTestsBadgeProps { | ||
publicId: string; | ||
repoName: string; | ||
projectName?: string; | ||
} | ||
|
||
const TestRunTestsBadge = ({ | ||
publicId, | ||
repoName, | ||
projectName, | ||
}: TestRunTestsBadgeProps) => { | ||
const [badgeSvg, setBadgeSvg] = React.useState<string>(null); | ||
|
||
React.useEffect(() => { | ||
fetchTestsBadge(publicId) | ||
.then((response) => { | ||
setBadgeSvg(response.data); | ||
}) | ||
.catch((_) => {}); | ||
}, [setBadgeSvg]); | ||
|
||
if (badgeSvg) { | ||
return ( | ||
<TestsBadge | ||
badgeSvg={badgeSvg} | ||
repoName={repoName} | ||
projectName={projectName} | ||
/> | ||
); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
export default TestRunTestsBadge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters