-
Notifications
You must be signed in to change notification settings - Fork 4
WIP: UI prototype using React hooks to render live data #1857
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
Draft
0x6675636b796f75676974687562
wants to merge
6
commits into
master
Choose a base branch
from
feature/test-suite-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a0342cf
Add more type aliases
0x6675636b796f75676974687562 5817a99
Add the initial implementation on the preprocessor side
0x6675636b796f75676974687562 4b074a5
Get rid of type aliases
0x6675636b796f75676974687562 52a46e2
Back-end (experimental)
0x6675636b796f75676974687562 c03ee1a
Front-end (experimental)
0x6675636b796f75676974687562 0ed3ea6
WIP
0x6675636b796f75676974687562 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
108 changes: 108 additions & 0 deletions
108
...src/main/kotlin/com/saveourtool/save/backend/controllers/TestSuiteValidationController.kt
This file contains hidden or 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,108 @@ | ||
package com.saveourtool.save.backend.controllers | ||
|
||
import com.saveourtool.save.backend.ParallelFluxResponse | ||
import com.saveourtool.save.backend.utils.withHttpHeaders | ||
import com.saveourtool.save.configs.ApiSwaggerSupport | ||
import com.saveourtool.save.test.TestSuiteValidationProgress | ||
import com.saveourtool.save.v1 | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import org.springframework.http.HttpHeaders.ACCEPT | ||
import org.springframework.http.MediaType.APPLICATION_NDJSON_VALUE | ||
import org.springframework.http.MediaType.TEXT_EVENT_STREAM_VALUE | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.ParallelFlux | ||
import reactor.core.scheduler.Schedulers | ||
import kotlin.streams.asStream | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
/** | ||
* Demonstrates _Server-Sent Events_ (SSE). | ||
*/ | ||
@ApiSwaggerSupport | ||
@RestController | ||
@RequestMapping(path = ["/api/$v1/a"]) | ||
class TestSuiteValidationController { | ||
/** | ||
* @return a stream of events. | ||
*/ | ||
@GetMapping( | ||
path = ["/validate"], | ||
headers = [ | ||
"$ACCEPT=$TEXT_EVENT_STREAM_VALUE", | ||
"$ACCEPT=$APPLICATION_NDJSON_VALUE", | ||
], | ||
produces = [ | ||
TEXT_EVENT_STREAM_VALUE, | ||
APPLICATION_NDJSON_VALUE, | ||
], | ||
) | ||
@ApiResponse(responseCode = "406", description = "Could not find acceptable representation.") | ||
fun sequential(): ParallelFluxResponse<TestSuiteValidationProgress> = | ||
withHttpHeaders { | ||
overallProgress() | ||
} | ||
|
||
@Suppress("MAGIC_NUMBER") | ||
private fun singleCheck( | ||
checkId: String, | ||
checkName: String, | ||
duration: Duration, | ||
): Flux<TestSuiteValidationProgress> { | ||
@Suppress("MagicNumber") | ||
val ticks = 0..100 | ||
|
||
val delayMillis = duration.inWholeMilliseconds / (ticks.count() - 1) | ||
|
||
return Flux.fromStream(ticks.asSequence().asStream()) | ||
.map { percentage -> | ||
TestSuiteValidationProgress( | ||
checkId = checkId, | ||
checkName = checkName, | ||
percentage = percentage, | ||
) | ||
} | ||
.map { item -> | ||
Thread.sleep(delayMillis) | ||
item | ||
} | ||
.subscribeOn(Schedulers.boundedElastic()) | ||
} | ||
|
||
@Suppress("MAGIC_NUMBER") | ||
private fun overallProgress(): ParallelFlux<TestSuiteValidationProgress> { | ||
@Suppress("ReactiveStreamsUnusedPublisher") | ||
val checks = arrayOf( | ||
singleCheck( | ||
"check A", | ||
"Searching for plug-ins with zero tests", | ||
10.seconds, | ||
|
||
), | ||
|
||
singleCheck( | ||
"check B", | ||
"Searching for test suites with wildcard mode", | ||
20.seconds, | ||
|
||
), | ||
|
||
singleCheck( | ||
"check C", | ||
"Ordering pizza from the nearest restaurant", | ||
30.seconds, | ||
|
||
), | ||
) | ||
|
||
return when { | ||
checks.isEmpty() -> Flux.empty<TestSuiteValidationProgress>().parallel() | ||
|
||
else -> checks.reduce { left, right -> | ||
left.mergeWith(right) | ||
} | ||
.parallel(Runtime.getRuntime().availableProcessors()) | ||
.runOn(Schedulers.parallel()) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...-cloud-common/src/commonMain/kotlin/com/saveourtool/save/test/TestSuiteValidationError.kt
This file contains hidden or 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,18 @@ | ||
package com.saveourtool.save.test | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* @property checkId the unique check id. | ||
* @property checkName the human-readable check name. | ||
* @property message the error message (w/o the trailing dot). | ||
*/ | ||
@Serializable | ||
data class TestSuiteValidationError( | ||
override val checkId: String, | ||
override val checkName: String, | ||
val message: String, | ||
) : TestSuiteValidationResult() { | ||
override fun toString(): String = | ||
"$checkName: $message." | ||
} |
28 changes: 28 additions & 0 deletions
28
...oud-common/src/commonMain/kotlin/com/saveourtool/save/test/TestSuiteValidationProgress.kt
This file contains hidden or 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,28 @@ | ||
package com.saveourtool.save.test | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* @property checkId the unique check id. | ||
* @property checkName the human-readable check name. | ||
* @property percentage the completion percentage (`0..100`). | ||
*/ | ||
@Serializable | ||
data class TestSuiteValidationProgress( | ||
override val checkId: String, | ||
override val checkName: String, | ||
val percentage: Int | ||
) : TestSuiteValidationResult() { | ||
init { | ||
@Suppress("MAGIC_NUMBER") | ||
require(percentage in 0..100) { | ||
percentage.toString() | ||
} | ||
} | ||
|
||
override fun toString(): String = | ||
when (percentage) { | ||
100 -> "Check $checkName is complete." | ||
else -> "Check $checkName is running, $percentage% complete\u2026" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...cloud-common/src/commonMain/kotlin/com/saveourtool/save/test/TestSuiteValidationResult.kt
This file contains hidden or 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,17 @@ | ||
package com.saveourtool.save.test | ||
|
||
/** | ||
* The validation result — either a progress message (intermediate or | ||
* terminal) or an error message (terminal). | ||
*/ | ||
sealed class TestSuiteValidationResult { | ||
/** | ||
* The unique check id. | ||
*/ | ||
abstract val checkId: String | ||
|
||
/** | ||
* The human-readable check name. | ||
*/ | ||
abstract val checkName: String | ||
} |
This file contains hidden or 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
59 changes: 59 additions & 0 deletions
59
...in/kotlin/com/saveourtool/save/frontend/components/views/TestSuiteValidationResultView.kt
This file contains hidden or 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,59 @@ | ||
@file:Suppress("FILE_NAME_MATCH_CLASS") | ||
|
||
package com.saveourtool.save.frontend.components.views | ||
|
||
import com.saveourtool.save.test.TestSuiteValidationProgress | ||
import csstype.ClassName | ||
import csstype.WhiteSpace | ||
import csstype.Width | ||
import js.core.jso | ||
import react.FC | ||
import react.Props | ||
import react.dom.aria.AriaRole | ||
import react.dom.aria.ariaValueMax | ||
import react.dom.aria.ariaValueMin | ||
import react.dom.aria.ariaValueNow | ||
import react.dom.html.ReactHTML.div | ||
|
||
@Suppress( | ||
"MagicNumber", | ||
"MAGIC_NUMBER", | ||
) | ||
val testSuiteValidationResultView: FC<TestSuiteValidationResultProps> = FC { props -> | ||
props.validationResults.forEach { item -> | ||
div { | ||
div { | ||
className = ClassName("progress progress-sm mr-2") | ||
div { | ||
className = ClassName("progress-bar bg-info") | ||
role = "progressbar".unsafeCast<AriaRole>() | ||
style = jso { | ||
width = "${item.percentage}%".unsafeCast<Width>() | ||
} | ||
ariaValueMin = 0.0 | ||
|
||
ariaValueNow = item.percentage.toDouble() | ||
ariaValueMax = 100.0 | ||
|
||
} | ||
} | ||
div { | ||
style = jso { | ||
whiteSpace = "pre".unsafeCast<WhiteSpace>() | ||
} | ||
|
||
+item.toString() | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Properties for [testSuiteValidationResultView]. | ||
* | ||
* @see testSuiteValidationResultView | ||
*/ | ||
external interface TestSuiteValidationResultProps : Props { | ||
/** | ||
* Test suite validation results. | ||
*/ | ||
var validationResults: Collection<TestSuiteValidationProgress> | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.