-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37159b8
commit f3f516b
Showing
49 changed files
with
533 additions
and
153 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
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
6 changes: 3 additions & 3 deletions
6
...spezi/core/design/views/ValidationTest.kt → .../core/design/validation/ValidationTest.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
38 changes: 38 additions & 0 deletions
38
...st/kotlin/edu/stanford/spezi/core/design/validation/composables/DefaultValidationRules.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,38 @@ | ||
package edu.stanford.spezi.core.design.validation.composables | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import edu.stanford.spezi.core.design.component.StringResource | ||
import edu.stanford.spezi.core.design.validation.validation.Validate | ||
import edu.stanford.spezi.core.design.validation.validation.ValidationRule | ||
import edu.stanford.spezi.core.design.validation.validation.asciiLettersOnly | ||
import edu.stanford.spezi.core.design.validation.validation.mediumPassword | ||
import edu.stanford.spezi.core.design.validation.validation.minimalEmail | ||
import edu.stanford.spezi.core.design.validation.validation.minimalPassword | ||
import edu.stanford.spezi.core.design.validation.validation.nonEmpty | ||
import edu.stanford.spezi.core.design.validation.validation.strongPassword | ||
import edu.stanford.spezi.core.design.validation.validation.unicodeLettersOnly | ||
import edu.stanford.spezi.core.design.validation.validation.views.VerifiableTextField | ||
|
||
@Composable | ||
fun DefaultValidationRules() { | ||
val input = remember { mutableStateOf("") } | ||
val rules = remember { | ||
listOf( | ||
ValidationRule.nonEmpty, | ||
ValidationRule.unicodeLettersOnly, | ||
ValidationRule.asciiLettersOnly, | ||
ValidationRule.minimalEmail, | ||
ValidationRule.minimalPassword, | ||
ValidationRule.mediumPassword, | ||
ValidationRule.strongPassword | ||
) | ||
} | ||
Validate(input.value, rules) { | ||
VerifiableTextField( | ||
StringResource("Field"), | ||
text = input | ||
) | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...mulators/FocusValidationRulesSimulator.kt → ...mulators/FocusValidationRulesSimulator.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
42 changes: 42 additions & 0 deletions
42
core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/views/MarkdownTest.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,42 @@ | ||
package edu.stanford.spezi.core.design.views | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import edu.stanford.spezi.core.design.views.composables.MarkdownTestComposable | ||
import edu.stanford.spezi.core.design.views.simulators.MarkdownTestSimulator | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class MarkdownTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.setContent { | ||
MarkdownTestComposable() | ||
} | ||
} | ||
|
||
@Test | ||
fun testMarkdown() { | ||
markdown { | ||
waitForTextToAppear( | ||
"This is a markdown example.", | ||
timeoutMillis = 100 | ||
) | ||
assertTextExists( | ||
"This is a markdown example taking half a second to load.", | ||
exists = false | ||
) | ||
waitForTextToAppear( | ||
"This is a markdown example taking half a second to load.", | ||
) | ||
} | ||
} | ||
|
||
private fun markdown(block: MarkdownTestSimulator.() -> Unit) { | ||
MarkdownTestSimulator(composeTestRule).apply(block) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/design/src/androidTest/kotlin/edu/stanford/spezi/core/design/views/SuspendButtonTest.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,39 @@ | ||
package edu.stanford.spezi.core.design.views | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import edu.stanford.spezi.core.design.views.composables.SuspendButtonTestComposable | ||
import edu.stanford.spezi.core.design.views.simulators.SuspendButtonTestSimulator | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class SuspendButtonTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.setContent { | ||
SuspendButtonTestComposable() | ||
} | ||
} | ||
|
||
@Test | ||
fun testSuspendButton() { | ||
suspendButton { | ||
clickHelloWorldButton() | ||
waitForHelloWorldButtonAction() | ||
resetHelloWorldButtonAction() | ||
|
||
clickHelloThrowingWorldButton() | ||
assertViewStateAlertAppeared("Error was thrown!") | ||
dismissViewStateAlert() | ||
assertHelloThrowingWorldButtonIsEnabled() | ||
} | ||
} | ||
|
||
private fun suspendButton(block: SuspendButtonTestSimulator.() -> Unit) { | ||
SuspendButtonTestSimulator(composeTestRule).apply(block) | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
...oidTest/kotlin/edu/stanford/spezi/core/design/views/composables/DefaultValidationRules.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...oidTest/kotlin/edu/stanford/spezi/core/design/views/composables/MarkdownTestComposable.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,24 @@ | ||
package edu.stanford.spezi.core.design.views.composables | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.runtime.Composable | ||
import edu.stanford.spezi.core.design.validation.views.views.text.MarkdownBytes | ||
import edu.stanford.spezi.core.design.validation.views.views.text.MarkdownString | ||
import kotlinx.coroutines.delay | ||
import java.nio.charset.StandardCharsets | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
@Composable | ||
fun MarkdownTestComposable() { | ||
Column { | ||
MarkdownBytes( | ||
bytes = { | ||
delay(500.milliseconds) | ||
"This is a markdown **example** taking half a second to load." | ||
.toByteArray(StandardCharsets.UTF_8) | ||
} | ||
) | ||
|
||
MarkdownString("This is a markdown **example**.") | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...st/kotlin/edu/stanford/spezi/core/design/views/composables/SuspendButtonTestComposable.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,46 @@ | ||
package edu.stanford.spezi.core.design.views.composables | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import edu.stanford.spezi.core.design.component.StringResource | ||
import edu.stanford.spezi.core.design.validation.views.model.ViewState | ||
import edu.stanford.spezi.core.design.validation.views.viewModifier.viewState.ViewStateAlert | ||
import edu.stanford.spezi.core.design.validation.views.views.button.SuspendButton | ||
import kotlinx.coroutines.delay | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
class CustomError : Throwable() { | ||
override val message = "Error was thrown!" | ||
} | ||
|
||
@Composable | ||
fun SuspendButtonTestComposable() { | ||
var showCompleted by remember { mutableStateOf(false) } | ||
val viewState = remember { mutableStateOf<ViewState>(ViewState.Idle) } | ||
|
||
ViewStateAlert(viewState) | ||
|
||
Column { | ||
if (showCompleted) { | ||
Text("Action executed") | ||
Button(onClick = { showCompleted = false }) { | ||
Text("Reset") | ||
} | ||
} else { | ||
SuspendButton(StringResource("Hello World")) { | ||
delay(500.milliseconds) | ||
showCompleted = true | ||
} | ||
|
||
SuspendButton(StringResource("Hello Throwing World"), viewState) { | ||
throw CustomError() | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...droidTest/kotlin/edu/stanford/spezi/core/design/views/simulators/MarkdownTestSimulator.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,25 @@ | ||
package edu.stanford.spezi.core.design.views.simulators | ||
|
||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.onAllNodesWithText | ||
import androidx.compose.ui.test.onNodeWithText | ||
|
||
class MarkdownTestSimulator( | ||
private val composeTestRule: ComposeTestRule, | ||
) { | ||
fun assertTextExists(text: String, exists: Boolean = true) { | ||
val node = composeTestRule.onNodeWithText(text) | ||
if (exists) { | ||
node.assertExists() | ||
} else { | ||
node.assertDoesNotExist() | ||
} | ||
} | ||
|
||
fun waitForTextToAppear(text: String, timeoutMillis: Long = 1_000) { | ||
composeTestRule.waitUntil(timeoutMillis) { | ||
composeTestRule.onAllNodesWithText(text) | ||
.fetchSemanticsNodes().isNotEmpty() | ||
} | ||
} | ||
} |
Oops, something went wrong.