-
-
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.
# SpeziViews ## ♻️ Current situation & Problem *Link any open issues or pull requests (PRs) related to this PR. Please ensure that all non-trivial PRs are first tracked and discussed in an existing GitHub issue or discussion.* ## ⚙️ Release Notes *Add a bullet point list summary of the feature and possible migration guides if this is a breaking change so this section can be added to the release notes.* *Include code snippets that provide examples of the feature implemented or links to the documentation if it appends or changes the public interface.* ## 📚 Documentation *Please ensure that you properly document any additions in conformance to [Spezi Documentation Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).* *You can use this section to describe your solution, but we encourage contributors to document your reasoning and changes using in-line documentation.* ## ✅ Testing *Please ensure that the PR meets the testing requirements set by CodeCov and that new functionality is appropriately tested.* *This section describes important information about the tests and why some elements might not be testable.* ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
1 parent
11ae70a
commit f5ee17f
Showing
58 changed files
with
2,355 additions
and
110 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
49 changes: 49 additions & 0 deletions
49
...sign/src/androidTest/kotlin/edu/stanford/spezi/core/design/personalInfo/NameFieldsTest.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,49 @@ | ||
package edu.stanford.spezi.core.design.personalInfo | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.google.common.truth.Truth.assertThat | ||
import edu.stanford.spezi.core.design.personalInfo.composables.NameFieldsTestComposable | ||
import edu.stanford.spezi.core.design.personalInfo.simulators.NameFieldsTestSimulator | ||
import edu.stanford.spezi.core.design.views.personalinfo.PersonNameComponents | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class NameFieldsTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
val nameBuilder = PersonNameComponents.Builder() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.setContent { | ||
NameFieldsTestComposable(nameBuilder) | ||
} | ||
} | ||
|
||
@Test | ||
fun testNameFields() { | ||
val givenName = "Leland" | ||
val familyName = "Stanford" | ||
|
||
nameFields { | ||
assertTextExists("First Name") | ||
assertTextExists("Last Name") | ||
|
||
enterText(PersonNameComponents.Builder::givenName, givenName) | ||
enterText(PersonNameComponents.Builder::familyName, familyName) | ||
|
||
assertTextExists("First Name") | ||
assertTextExists("Last Name") | ||
|
||
assertThat(nameBuilder.givenName).isEqualTo(givenName) | ||
assertThat(nameBuilder.familyName).isEqualTo(familyName) | ||
} | ||
} | ||
|
||
private fun nameFields(block: NameFieldsTestSimulator.() -> Unit) { | ||
NameFieldsTestSimulator(composeTestRule).apply(block) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ign/src/androidTest/kotlin/edu/stanford/spezi/core/design/personalInfo/UserProfileTest.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,35 @@ | ||
package edu.stanford.spezi.core.design.personalInfo | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import edu.stanford.spezi.core.design.personalInfo.composables.UserProfileTestComposable | ||
import edu.stanford.spezi.core.design.personalInfo.simulators.UserProfileTestSimulator | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class UserProfileTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.setContent { | ||
UserProfileTestComposable() | ||
} | ||
} | ||
|
||
@Test | ||
fun testUserProfile() { | ||
userProfile { | ||
assertUserInitialsExists(true, "PS") | ||
assertUserInitialsExists(true, "LS") | ||
waitUntilUserInitialsDisappear("LS") | ||
assertImageExists("Person") | ||
} | ||
} | ||
|
||
private fun userProfile(block: UserProfileTestSimulator.() -> Unit) { | ||
UserProfileTestSimulator(composeTestRule).apply(block) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...otlin/edu/stanford/spezi/core/design/personalInfo/composables/NameFieldsTestComposable.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,23 @@ | ||
package edu.stanford.spezi.core.design.personalInfo.composables | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import edu.stanford.spezi.core.design.views.personalinfo.PersonNameComponents | ||
import edu.stanford.spezi.core.design.views.personalinfo.fields.NameFieldRow | ||
|
||
@Composable | ||
fun NameFieldsTestComposable(nameBuilder: PersonNameComponents.Builder) { | ||
Column { | ||
NameFieldRow("First Name", nameBuilder, PersonNameComponents.Builder::givenName) { | ||
Text("enter your first name") | ||
} | ||
|
||
HorizontalDivider() | ||
|
||
NameFieldRow("Last Name", nameBuilder, PersonNameComponents.Builder::familyName) { | ||
Text("enter your last name") | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...tlin/edu/stanford/spezi/core/design/personalInfo/composables/UserProfileTestComposable.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.personalInfo.composables | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Person | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import edu.stanford.spezi.core.design.component.ImageResource | ||
import edu.stanford.spezi.core.design.component.StringResource | ||
import edu.stanford.spezi.core.design.views.personalinfo.PersonNameComponents | ||
import edu.stanford.spezi.core.design.views.personalinfo.UserProfileComposable | ||
import kotlinx.coroutines.delay | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
@Composable | ||
fun UserProfileTestComposable() { | ||
Column { | ||
UserProfileComposable( | ||
PersonNameComponents( | ||
givenName = "Paul", | ||
familyName = "Schmiedmayer" | ||
), | ||
Modifier.height(100.dp), | ||
) | ||
UserProfileComposable( | ||
PersonNameComponents( | ||
givenName = "Leland", | ||
familyName = "Stanford" | ||
), | ||
Modifier.height(200.dp), | ||
) { | ||
delay(0.5.seconds) | ||
ImageResource.Vector(Icons.Default.Person, StringResource("Person")) | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../kotlin/edu/stanford/spezi/core/design/personalInfo/simulators/NameFieldsTestSimulator.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.personalInfo.simulators | ||
|
||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performTextInput | ||
import edu.stanford.spezi.core.design.views.personalinfo.PersonNameComponents | ||
import edu.stanford.spezi.core.design.views.personalinfo.fields.NameTextFieldTestIdentifier | ||
import edu.stanford.spezi.core.testing.onNodeWithIdentifier | ||
import kotlin.reflect.KMutableProperty1 | ||
|
||
class NameFieldsTestSimulator( | ||
private val composeTestRule: ComposeTestRule, | ||
) { | ||
fun assertTextExists(text: String) { | ||
composeTestRule | ||
.onNodeWithText(text) | ||
.assertExists() | ||
} | ||
|
||
fun enterText(property: KMutableProperty1<PersonNameComponents.Builder, String?>, text: String) { | ||
composeTestRule | ||
.onNodeWithIdentifier(NameTextFieldTestIdentifier.TEXT_FIELD, property.name) | ||
.performTextInput(text) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...kotlin/edu/stanford/spezi/core/design/personalInfo/simulators/UserProfileTestSimulator.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,35 @@ | ||
package edu.stanford.spezi.core.design.personalInfo.simulators | ||
|
||
import androidx.compose.ui.test.assertCountEquals | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.onAllNodesWithContentDescription | ||
import androidx.compose.ui.test.onAllNodesWithText | ||
import androidx.compose.ui.test.onNodeWithText | ||
|
||
class UserProfileTestSimulator( | ||
private val composeTestRule: ComposeTestRule, | ||
) { | ||
|
||
fun assertUserInitialsExists(exists: Boolean, text: String) { | ||
val node = composeTestRule | ||
.onNodeWithText(text) | ||
if (exists) { | ||
node.assertExists() | ||
} else { | ||
node.assertDoesNotExist() | ||
} | ||
} | ||
|
||
fun waitUntilUserInitialsDisappear(text: String, timeoutMillis: Long = 1_000) { | ||
composeTestRule.waitUntil(timeoutMillis = timeoutMillis) { | ||
composeTestRule.onAllNodesWithText(text) | ||
.fetchSemanticsNodes().isEmpty() | ||
} | ||
} | ||
|
||
fun assertImageExists(contentDescription: String) { | ||
composeTestRule | ||
.onAllNodesWithContentDescription(contentDescription) | ||
.assertCountEquals(1) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../androidTest/kotlin/edu/stanford/spezi/core/design/validation/FocusValidationRulesTest.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,45 @@ | ||
package edu.stanford.spezi.core.design.validation | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import edu.stanford.spezi.core.design.validation.composables.FocusValidationRules | ||
import edu.stanford.spezi.core.design.validation.simulators.FocusValidationRulesSimulator | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class FocusValidationRulesTest { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun init() { | ||
composeTestRule.setContent { | ||
FocusValidationRules() | ||
} | ||
} | ||
|
||
@Test | ||
fun testFocusValidationRules() { | ||
focusValidationRules { | ||
assertHasEngines(true) | ||
assertInputValid(false) | ||
assertPasswordMessageExists(false) | ||
assertEmptyMessageExists(false) | ||
clickValidateButton() | ||
assertLastState(false) | ||
assertPasswordMessageExists(true) | ||
assertEmptyMessageExists(true) | ||
enterEmail("[email protected]") | ||
assertEmptyMessageExists(false) | ||
assertPasswordMessageExists(true) | ||
enterPassword("password") | ||
assertEmptyMessageExists(false) | ||
assertPasswordMessageExists(false) | ||
} | ||
} | ||
|
||
private fun focusValidationRules(block: FocusValidationRulesSimulator.() -> Unit) { | ||
FocusValidationRulesSimulator(composeTestRule).apply(block) | ||
} | ||
} |
Oops, something went wrong.