-
-
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.
fix questionnaire composable integration test
- Loading branch information
Showing
3 changed files
with
34 additions
and
42 deletions.
There are no files selected for viewing
34 changes: 13 additions & 21 deletions
34
app/src/androidTest/kotlin/edu/stanford/bdh/engagehf/questionnaire/QuestionnaireTest.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 |
---|---|---|
@@ -1,40 +1,32 @@ | ||
package edu.stanford.bdh.engagehf.questionnaire | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import edu.stanford.bdh.engagehf.questionnaire.composables.QuestionnaireTestComposable | ||
import edu.stanford.bdh.engagehf.questionnaire.simulators.QuestionnaireTestSimulator | ||
import org.junit.Before | ||
import edu.stanford.spezi.core.design.component.ComposeContentActivity | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
@HiltAndroidTest | ||
class QuestionnaireTest { | ||
|
||
@get: Rule | ||
private val composeRule = createComposeRule() | ||
@get:Rule | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@Before | ||
fun init() { | ||
try { | ||
composeRule.setContent { | ||
QuestionnaireTestComposable() | ||
} | ||
} catch (error: Throwable) { | ||
// TODO: I currently do not know how to fix this | ||
// and how to set the view up to work in a test environment | ||
// - help much appreciated! | ||
println("Error occurred: $error") | ||
} | ||
} | ||
@get:Rule | ||
val composeTestRule = createAndroidComposeRule<ComposeContentActivity>() | ||
|
||
@Test | ||
fun testQuestionnaireComposable() { | ||
// TODO: This should actually contain logic, but is skipped for now | ||
fun testQuestionnaireComposableDisplay() { | ||
composeTestRule.activity.setScreen { QuestionnaireTestComposable() } | ||
questionnaireComposable { | ||
println("Empty test") | ||
assertIsDisplayed() | ||
} | ||
} | ||
|
||
private fun questionnaireComposable(block: QuestionnaireTestSimulator.() -> Unit) { | ||
QuestionnaireTestSimulator(composeRule).apply { block() } | ||
QuestionnaireTestSimulator(composeTestRule).apply { block() } | ||
} | ||
} |
16 changes: 13 additions & 3 deletions
16
...t/kotlin/edu/stanford/bdh/engagehf/questionnaire/simulators/QuestionnaireTestSimulator.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 |
---|---|---|
@@ -1,7 +1,17 @@ | ||
package edu.stanford.bdh.engagehf.questionnaire.simulators | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import edu.stanford.bdh.engagehf.questionnaire.spezi.QuestionnaireComposableTestIdentifiers | ||
import edu.stanford.spezi.core.testing.onNodeWithIdentifier | ||
|
||
data class QuestionnaireTestSimulator( | ||
val composeTestRule: ComposeTestRule, | ||
) | ||
class QuestionnaireTestSimulator( | ||
composeTestRule: ComposeTestRule, | ||
) { | ||
private val root = | ||
composeTestRule.onNodeWithIdentifier(QuestionnaireComposableTestIdentifiers.ROOT) | ||
|
||
fun assertIsDisplayed() { | ||
root.assertIsDisplayed() | ||
} | ||
} |
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