Skip to content

Commit

Permalink
add first simple end-to-end UX request response test
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-chung committed Apr 29, 2024
1 parent 62be829 commit 7400da9
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 4 deletions.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ rootProject.name = "hello-http"

include("test-server")
include("test-common")
include("ux-and-transport-test")
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -107,7 +108,7 @@ fun AppView() {
val dialogViewModel = AppContext.DialogViewModel
val dialogState = dialogViewModel.state.collectAsState().value // needed for updating UI by flow
log.d { "Dialog State = $dialogState" }
Box(modifier = Modifier.background(colors.background).fillMaxSize()) {
Box(modifier = Modifier.background(colors.background).fillMaxSize().testTag(TestTag.ContainerView.name)) {
AppContentView()

dialogState?.let { dialog ->
Expand Down Expand Up @@ -148,6 +149,7 @@ fun AppView() {
.align(
Alignment.Center
)
.testTag(TestTag.DialogContainerView.name)
) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextRange
Expand Down Expand Up @@ -90,6 +91,7 @@ fun CodeEditorView(
transformations: List<VisualTransformation> = emptyList(),
isEnableVariables: Boolean = false,
knownVariables: Set<String> = setOf(),
testTag: String? = null,
) {
val colors: TextFieldColors = TextFieldDefaults.textFieldColors(
textColor = textColor,
Expand Down Expand Up @@ -477,6 +479,13 @@ fun CodeEditorView(
this
}
}
.run {
if (testTag != null) {
testTag(testTag)
} else {
this
}
}
)
}
VerticalScrollbar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.sunnychung.application.multiplatform.hellohttp.model.Environment
import com.sunnychung.application.multiplatform.hellohttp.model.Project
Expand Down Expand Up @@ -144,12 +145,14 @@ fun ProjectAndEnvironmentViewV2(
false
}
}
.defaultMinSize(minWidth = 200.dp),
.defaultMinSize(minWidth = 200.dp)
.testTag(TestTag.ProjectNameAndSubprojectNameDialogTextField.name),
)
AppTextButton(
text = "Done",
onClick = { onDone() },
modifier = Modifier.padding(top = 4.dp),
modifier = Modifier.padding(top = 4.dp)
.testTag(TestTag.ProjectNameAndSubprojectNameDialogDoneButton.name),
)
}

Expand Down Expand Up @@ -205,6 +208,7 @@ fun ProjectAndEnvironmentViewV2(
dialogTextFieldValue = ""
dialogIsCreate = true
}
.testTag(TestTag.FirstTimeCreateProjectButton.name)
)
} else {
LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
Expand Down Expand Up @@ -287,6 +291,7 @@ fun ProjectAndEnvironmentViewV2(
dialogTextFieldValue = ""
dialogIsCreate = true
}
.testTag(TestTag.FirstTimeCreateSubprojectButton.name)
)
} else {
LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
Expand Down Expand Up @@ -286,6 +287,7 @@ fun RequestEditorView(
),
singleLine = true,
modifier = Modifier.weight(1f).padding(vertical = 4.dp)
.testTag(TestTag.RequestUrlTextField.name)
)

val isOneOffRequest = when (request.application) {
Expand Down Expand Up @@ -327,6 +329,7 @@ fun RequestEditorView(
}
}
.padding(start = 10.dp, end = if (dropdownItems.isNotEmpty()) 4.dp else 10.dp)
.testTag(TestTag.RequestFireOrDisconnectButton.name)
) {
AppText(
text = label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.sunnychung.application.multiplatform.hellohttp.model.MoveDirection
Expand Down Expand Up @@ -469,6 +470,7 @@ fun RequestTreeView(
true
},
modifier = Modifier.padding(4.dp)
.testTag(TestTag.CreateRequestOrFolderButton.name)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerEventType
import androidx.compose.ui.input.pointer.onPointerEvent
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -340,7 +341,12 @@ fun StatusLabel(modifier: Modifier = Modifier, response: UserResponse, connectio
Pair("", colors.errorResponseBackground)
}
if (text.isNotEmpty()) {
DataLabel(modifier = modifier, text = text, backgroundColor = backgroundColor, textColor = colors.bright)
DataLabel(
modifier = modifier.testTag(TestTag.ResponseStatus.name),
text = text,
backgroundColor = backgroundColor,
textColor = colors.bright,
)
}
}

Expand Down Expand Up @@ -539,6 +545,7 @@ fun BodyViewerView(
} else {
emptyList()
},
testTag = TestTag.ResponseBody.name,
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sunnychung.application.multiplatform.hellohttp.ux

enum class TestTag {
ContainerView,
DialogContainerView,
ProjectNameAndSubprojectNameDialogTextField,
ProjectNameAndSubprojectNameDialogDoneButton,
FirstTimeCreateProjectButton,
FirstTimeCreateSubprojectButton,
CreateRequestOrFolderButton,
RequestMethodDropdownButton,
RequestUrlTextField,
RequestFireOrDisconnectButton,
ResponseStatus,
ResponseBody,
}
39 changes: 39 additions & 0 deletions ux-and-transport-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
kotlin("jvm")
id("org.jetbrains.compose")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
}

repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")

testImplementation(project(":test-common"))
testImplementation(rootProject)
testImplementation("io.github.sunny-chung:kdatetime-multiplatform:1.0.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")

@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
testImplementation(compose.uiTest)
testImplementation(compose.desktop.currentOs)
}

tasks.withType<Test> {
useJUnitPlatform()

testLogging {
events = setOf(TestLogEvent.STARTED, TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED)
}
}
Loading

0 comments on commit 7400da9

Please sign in to comment.