-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tracking key toc rememberScope, tests and fix inline class bugs
- Loading branch information
1 parent
e5c09ed
commit 79cba2f
Showing
4 changed files
with
105 additions
and
26 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
57 changes: 57 additions & 0 deletions
57
sample/src/test/java/com/sebaslogen/resacaapp/ScopeKeysTest.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,57 @@ | ||
package com.sebaslogen.resacaapp | ||
|
||
import androidx.compose.material.Button | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.test.assert | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.hasTextExactly | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.performClick | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.sebaslogen.resaca.compose.rememberScoped | ||
import com.sebaslogen.resacaapp.ui.main.compose.DemoComposable | ||
import com.sebaslogen.resacaapp.ui.main.data.FakeRepo | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config(instrumentedPackages = ["androidx.loader.content"]) | ||
class ScopeKeysTest : ComposeTestUtils { | ||
|
||
@get:Rule | ||
override val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun `when the key used for rememberScoped changes, then the scoped object is different`() { | ||
|
||
// Given the starting screen with scoped object that uses a key | ||
composeTestRule.setContent { | ||
var myKey by remember { mutableStateOf(false) } | ||
val fakeRepo: FakeRepo = rememberScoped(key = myKey) { FakeRepo() } | ||
DemoComposable(inputObject = fakeRepo, objectType = "FakeRepo", scoped = true) | ||
Button(modifier = Modifier.testTag("Button"), | ||
onClick = { myKey = !myKey }) { | ||
Text("Click to change") | ||
} | ||
} | ||
printComposeUiTreeToLog() | ||
// Find the scoped text field and grab its text | ||
val initialFakeScopedRepoText = retrieveTextFromNodeWithTestTag("FakeRepo Scoped") | ||
|
||
// When I click a button to change the state and key of the rememberScoped object | ||
onNodeWithTestTag("Button").performClick() | ||
printComposeUiTreeToLog() | ||
|
||
// Then the text of the NOT scoped object is different from the original one because it's a new object | ||
onNodeWithTestTag("FakeRepo Scoped").assertIsDisplayed() | ||
.assert(hasTextExactly(initialFakeScopedRepoText).not()) | ||
} | ||
} |