-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from ooni/testing
Add UI and ViewModel tests
- Loading branch information
Showing
5 changed files
with
106 additions
and
5 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
42 changes: 42 additions & 0 deletions
42
composeApp/src/commonTest/kotlin/org/ooni/probe/ui/result/ResultScreenTest.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 org.ooni.probe.ui.result | ||
|
||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.runComposeUiTest | ||
import org.ooni.probe.data.models.TestResult | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ResultScreenTest { | ||
@Test | ||
fun showResult() = | ||
runComposeUiTest { | ||
val result = TestResult(TestResult.Id("ABCDEF")) | ||
setContent { | ||
ResultScreen( | ||
state = ResultViewModel.State(result), | ||
onEvent = {}, | ||
) | ||
} | ||
|
||
onNodeWithText(result.id.value).assertExists() | ||
} | ||
|
||
@Test | ||
fun pressBack() = | ||
runComposeUiTest { | ||
val events = mutableListOf<ResultViewModel.Event>() | ||
val result = TestResult(TestResult.Id("ABCDEF")) | ||
setContent { | ||
ResultScreen( | ||
state = ResultViewModel.State(result), | ||
onEvent = events::add, | ||
) | ||
} | ||
|
||
onNodeWithContentDescription("Back").performClick() | ||
assertEquals(1, events.size) | ||
assertEquals(ResultViewModel.Event.BackClicked, events.first()) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
composeApp/src/commonTest/kotlin/org/ooni/probe/ui/result/ResultViewModelTest.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,21 @@ | ||
package org.ooni.probe.ui.result | ||
|
||
import org.ooni.probe.data.models.TestResult | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
class ResultViewModelTest { | ||
@Test | ||
fun backClicked() { | ||
var backPressed = false | ||
|
||
val viewModel = | ||
ResultViewModel( | ||
resultId = TestResult.Id("1234"), | ||
onBack = { backPressed = true }, | ||
) | ||
|
||
viewModel.onEvent(ResultViewModel.Event.BackClicked) | ||
assertTrue(backPressed) | ||
} | ||
} |