Skip to content

Commit

Permalink
Fixes for TestSuiteSelector and TestSuiteSourceCreationComponent (#…
Browse files Browse the repository at this point in the history
…1091)

Fixes for TestSuiteSelector and TestSuiteSourceCreationComponent

### What's done:
 * Added (returned back) testSuiteSelector for general tests - all the avaliable ones
 * Fixed an issue with TestSuiteSelector in browser mode - now input form is cleared when an entity from avaliable list is chosen
 * Fixed an issue with unclosing modal - now when TestSuiteSource is successfully created, a new request for a fetch is sent

 (#1079)
  • Loading branch information
sanyavertolet authored Aug 23, 2022
1 parent 3147930 commit 528314e
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 25 deletions.
51 changes: 51 additions & 0 deletions save-backend/backend-api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,57 @@
]
}
},
"/api/v1/test-suites-sources/avaliable": {
"get": {
"tags": [
"test-suites-source"
],
"summary": "Get organizations with public test suite sources.",
"description": "Get list of organizations with public test suite sources",
"operationId": "getOrganizationNamesWithPublicTestSuiteSources",
"parameters": [
{
"name": "X-Authorization-Source",
"in": "header",
"required": true,
"example": "basic"
}
],
"responses": {
"200": {
"description": "Successfully fetched organizations with public test suite sources.",
"content": {
"*/*": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TestSuitesSourceDto"
}
}
}
}
},
"401": {
"description": "Unauthorized",
"content": {
"*/*": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TestSuitesSourceDto"
}
}
}
}
}
},
"security": [
{
"basic": []
}
]
}
},
"/api/v1/projects/": {
"get": {
"tags": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ class TestSuitesSourceController(
when (testSuitesSourceService.createSourceIfNotPresent(testSuitesSource)) {
SourceSaveStatus.EXIST -> Mono.just(ResponseEntity.status(HttpStatus.CONFLICT).body(SourceSaveStatus.EXIST))
SourceSaveStatus.CONFLICT -> Mono.just(ResponseEntity.status(HttpStatus.CONFLICT).body(SourceSaveStatus.CONFLICT))
SourceSaveStatus.NEW -> testSuitesSourceService.fetch(testSuitesSource.toDto())
.map { ResponseEntity.ok(SourceSaveStatus.NEW) }
SourceSaveStatus.NEW -> Mono.just(ResponseEntity.ok(SourceSaveStatus.NEW))
}
}

Expand Down Expand Up @@ -513,6 +512,22 @@ class TestSuitesSourceController(
}
}

@GetMapping("/api/$v1/test-suites-sources/avaliable")
@RequiresAuthorizationSourceHeader
@PreAuthorize("permitAll()")
@Operation(
method = "GET",
summary = "Get organizations with public test suite sources.",
description = "Get list of organizations with public test suite sources",
)
@ApiResponse(responseCode = "200", description = "Successfully fetched organizations with public test suite sources.")
fun getOrganizationNamesWithPublicTestSuiteSources(
authentication: Authentication,
): Mono<TestSuitesSourceDtoList> = testSuitesSourceService.getAvaliableTestSuiteSources().toMono()
.map {testSuitesSourceList ->
testSuitesSourceList.map { it.toDto() }
}

private fun TestSuitesSourceDto.downloadSnapshot(
version: String
): Mono<ByteBufferFluxResponse> = testSuitesSourceSnapshotStorage.findKey(organizationName, name, version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class TestSuitesSourceService(
}
}

/**
* @return list of organizations that have open public test suite sources
*/
fun getAvaliableTestSuiteSources(): List<TestSuitesSource> = testSuitesSourceRepository.findAll()

/**
* @param testSuitesSource test suites source which requested to be fetched
* @return empty response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ fun ChildrenBuilder.showTestSuiteSourceCreationModal(
private fun testSuiteSourceCreationComponent() = FC<TestSuiteSourceCreationProps> { props ->
val (testSuiteSource, setTestSuiteSource) = useState(TestSuitesSourceDto.empty.copy(organizationName = props.organizationName))
val (saveStatus, setSaveStatus) = useState<SourceSaveStatus?>(null)
val fetchTestSuiteSource = useRequest {
post(
url = "$apiUrl/test-suites-sources/${testSuiteSource.organizationName}/${testSuiteSource.name}/fetch",
headers = jsonHeaders,
body = undefined,
loadingHandler = ::noopLoadingHandler,
responseHandler = ::noopResponseHandler,
)
}
val onSubmitButtonPressed = useRequest {
val response = post(
url = "/api/$v1/test-suites-sources/create",
Expand All @@ -112,6 +121,7 @@ private fun testSuiteSourceCreationComponent() = FC<TestSuiteSourceCreationProps
responseHandler = ::responseHandlerWithValidation,
)
if (response.ok) {
fetchTestSuiteSource()
props.onSuccess()
} else if (response.isConflict()) {
setSaveStatus(response.decodeFromJsonString<SourceSaveStatus>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.saveourtool.save.frontend.components.basic.contests

import com.saveourtool.save.entities.ContestDto
import com.saveourtool.save.frontend.components.basic.*
import com.saveourtool.save.frontend.components.basic.testsuiteselector.showPublicTestSuitesSelectorModal
import com.saveourtool.save.frontend.components.basic.testsuiteselector.showGeneralTestSuitesSelectorModal
import com.saveourtool.save.frontend.externals.modal.CssProperties
import com.saveourtool.save.frontend.externals.modal.Styles
import com.saveourtool.save.frontend.externals.modal.modal
Expand Down Expand Up @@ -150,10 +150,10 @@ private fun contestCreationComponent() = FC<ContestCreationComponentProps> { pro
div {
className = ClassName("card")
contestCreationCard {
showPublicTestSuitesSelectorModal(
showGeneralTestSuitesSelectorModal(
contestDto.testSuiteIds,
testSuitesSelectorWindowOpenness,
useState(emptyList())
useState(emptyList()),
) {
setContestDto(contestDto.copy(testSuiteIds = it))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ external interface TestSuiteSelectorProps : Props {

/**
* Specific organization name which reduces list of test suites source.
* If it's null we show public tests
* If null, all the test suites are shown
*/
var specificOrganizationName: String?

/**
* If this flag is true public tests will be shown
*/
var isStandardMode: Boolean
}

/**
Expand All @@ -52,6 +57,8 @@ enum class TestSuiteSelectorMode {
}

/**
* Browse standard test suites
*
* @param initTestSuiteIds initial value
* @param windowOpenness state to control openness of window
* @param testSuiteIdsInSelectorState state for intermediate result in selector
Expand All @@ -63,10 +70,29 @@ fun ChildrenBuilder.showPublicTestSuitesSelectorModal(
testSuiteIdsInSelectorState: StateInstance<List<Long>>,
setSelectedTestSuiteIds: (List<Long>) -> Unit,
) {
showTestSuitesSelectorModal(null, initTestSuiteIds, windowOpenness, testSuiteIdsInSelectorState, setSelectedTestSuiteIds)
showTestSuitesSelectorModal(null, true, initTestSuiteIds, windowOpenness, testSuiteIdsInSelectorState, setSelectedTestSuiteIds)
}

/**
* Browse all the avaliable test suites.
*
* @param initTestSuiteIds initial value
* @param windowOpenness state to control openness of window
* @param testSuiteIdsInSelectorState state for intermediate result in selector
* @param setSelectedTestSuiteIds consumer for result
*/
fun ChildrenBuilder.showGeneralTestSuitesSelectorModal(
initTestSuiteIds: List<Long>,
windowOpenness: WindowOpenness,
testSuiteIdsInSelectorState: StateInstance<List<Long>>,
setSelectedTestSuiteIds: (List<Long>) -> Unit,
) {
showTestSuitesSelectorModal(null, false, initTestSuiteIds, windowOpenness, testSuiteIdsInSelectorState, setSelectedTestSuiteIds)
}

/**
* Browse test suites of a given organization
*
* @param organizationName
* @param initTestSuiteIds initial value
* @param windowOpenness state to control openness of window
Expand All @@ -80,11 +106,13 @@ fun ChildrenBuilder.showPrivateTestSuitesSelectorModal(
testSuiteIdsInSelectorState: StateInstance<List<Long>>,
setSelectedTestSuiteIds: (List<Long>) -> Unit,
) {
showTestSuitesSelectorModal(organizationName, initTestSuiteIds, windowOpenness, testSuiteIdsInSelectorState, setSelectedTestSuiteIds)
showTestSuitesSelectorModal(organizationName, false, initTestSuiteIds, windowOpenness, testSuiteIdsInSelectorState, setSelectedTestSuiteIds)
}

@Suppress("TOO_MANY_PARAMETERS", "LongParameterList")
private fun ChildrenBuilder.showTestSuitesSelectorModal(
specificOrganizationName: String?,
isStandardMode: Boolean,
initTestSuiteIds: List<Long>,
windowOpenness: WindowOpenness,
testSuiteIdsInSelectorState: StateInstance<List<Long>>,
Expand All @@ -102,7 +130,7 @@ private fun ChildrenBuilder.showTestSuitesSelectorModal(
currentlySelectedTestSuiteIds = initTestSuiteIds
windowOpenness.closeWindow()
}
showTestSuitesSelectorModal(windowOpenness.isOpen(), specificOrganizationName, initTestSuiteIds, onSubmit, onTestSuiteIdUpdate, onCancel)
showTestSuitesSelectorModal(windowOpenness.isOpen(), specificOrganizationName, isStandardMode, initTestSuiteIds, onSubmit, onTestSuiteIdUpdate, onCancel)
}

@Suppress(
Expand All @@ -114,6 +142,7 @@ private fun ChildrenBuilder.showTestSuitesSelectorModal(
private fun ChildrenBuilder.showTestSuitesSelectorModal(
isOpen: Boolean,
specificOrganizationName: String?,
isStandardMode: Boolean,
preselectedTestSuiteIds: List<Long>,
onSubmit: () -> Unit,
onTestSuiteIdUpdate: (List<Long>) -> Unit,
Expand Down Expand Up @@ -150,6 +179,7 @@ private fun ChildrenBuilder.showTestSuitesSelectorModal(
this.onTestSuiteIdUpdate = onTestSuiteIdUpdate
this.preselectedTestSuiteIds = preselectedTestSuiteIds
this.specificOrganizationName = specificOrganizationName
this.isStandardMode = isStandardMode
}
}

Expand Down Expand Up @@ -233,6 +263,7 @@ private fun testSuiteSelector() = FC<TestSuiteSelectorProps> { props ->
this.onTestSuiteIdsUpdate = props.onTestSuiteIdUpdate
this.preselectedTestSuiteIds = props.preselectedTestSuiteIds
this.specificOrganizationName = props.specificOrganizationName
this.isStandardMode = props.isStandardMode
}
TestSuiteSelectorMode.SEARCH -> testSuiteSelectorSearchMode {
this.onTestSuiteIdsUpdate = props.onTestSuiteIdUpdate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ external interface TestSuiteSelectorBrowserModeProps : Props {

/**
* Specific organization name which reduces list of test suites source.
* If it's null we show public tests
* If null, all the test suites are shown
*/
var specificOrganizationName: String?

/**
* If this flag is true public tests will be shown
*/
var isStandardMode: Boolean
}

@Suppress(
Expand Down Expand Up @@ -158,22 +163,20 @@ private fun testSuiteSelectorBrowserMode() = FC<TestSuiteSelectorBrowserModeProp

val (availableOrganizations, setAvailableOrganizations) = useState<List<String>>(emptyList())
val (availableTestSuiteSources, setAvailableTestSuiteSources) = useState<List<String>>(emptyList())

useRequest {
val response = props.specificOrganizationName?.let { organizationName ->
get(
url = "$apiUrl/test-suites-sources/$organizationName/list",
headers = jsonHeaders,
loadingHandler = ::noopLoadingHandler,
responseHandler = ::noopResponseHandler,
)
} ?: run {
get(
url = "$apiUrl/test-suites-sources/public-list",
headers = jsonHeaders,
loadingHandler = ::noopLoadingHandler,
responseHandler = ::noopResponseHandler,
)
val url = when {
props.isStandardMode -> "$apiUrl/test-suites-sources/public-list"
props.specificOrganizationName != null -> "$apiUrl/test-suites-sources/avaliable"
else -> "$apiUrl/test-suites-sources/${props.specificOrganizationName}/list"
}
val response = get(
url = url,
headers = jsonHeaders,
loadingHandler = ::noopLoadingHandler,
responseHandler = ::noopResponseHandler,
)

val testSuitesSources: TestSuitesSourceDtoList = response.decodeFromJsonString()
setAvailableOrganizations(testSuitesSources.map { it.organizationName }.distinct())
setAvailableTestSuiteSources(testSuitesSources.map { it.name })
Expand Down Expand Up @@ -291,7 +294,6 @@ private fun testSuiteSelectorBrowserMode() = FC<TestSuiteSelectorBrowserModeProp
}
}
}

// ==================== SELECTOR ====================
div {
className = ClassName("")
Expand All @@ -300,16 +302,19 @@ private fun testSuiteSelectorBrowserMode() = FC<TestSuiteSelectorBrowserModeProp
availableOrganizations.filter { it.contains(namePrefix, true) }
) { organization ->
setSelectedOrganization(organization)
setNamePrefix("")
}
selectedTestSuiteSource == null -> showAvaliableOptions(
availableTestSuiteSources.filter { it.contains(namePrefix, true) }
) { testSuiteSource ->
setSelectedTestSuiteSource(testSuiteSource)
setNamePrefix("")
}
selectedTestSuiteVersion == null -> showAvaliableOptions(
availableTestSuitesVersions.filter { it.contains(namePrefix, true) }
) { testSuiteVersion ->
setSelectedTestSuiteVersion(testSuiteVersion)
setNamePrefix("")
}
else -> showAvaliableTestSuites(
availableTestSuites.filter { it.name.contains(namePrefix, true) },
Expand Down

0 comments on commit 528314e

Please sign in to comment.