|
|
|
@ -2,9 +2,7 @@ package org.jetbrains.compose.resources
|
|
|
|
|
|
|
|
|
|
import androidx.compose.foundation.Image |
|
|
|
|
import androidx.compose.material3.Text |
|
|
|
|
import androidx.compose.runtime.CompositionLocalProvider |
|
|
|
|
import androidx.compose.runtime.collectAsState |
|
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
|
import androidx.compose.runtime.* |
|
|
|
|
import androidx.compose.ui.test.ExperimentalTestApi |
|
|
|
|
import androidx.compose.ui.test.runComposeUiTest |
|
|
|
|
import kotlinx.coroutines.flow.MutableStateFlow |
|
|
|
@ -29,12 +27,14 @@ class ComposeResourceTest {
|
|
|
|
|
val imagePathFlow = MutableStateFlow(DrawableResource("1.png")) |
|
|
|
|
val recompositionsCounter = RecompositionsCounter() |
|
|
|
|
setContent { |
|
|
|
|
CompositionLocalProvider(LocalComposeEnvironment provides TestComposeEnvironment) { |
|
|
|
|
val res by imagePathFlow.collectAsState() |
|
|
|
|
val imgRes = imageResource(res) |
|
|
|
|
recompositionsCounter.content { |
|
|
|
|
Image(bitmap = imgRes, contentDescription = null) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
awaitIdle() |
|
|
|
|
imagePathFlow.emit(DrawableResource("2.png")) |
|
|
|
|
awaitIdle() |
|
|
|
@ -48,7 +48,10 @@ class ComposeResourceTest {
|
|
|
|
|
val testResourceReader = TestResourceReader() |
|
|
|
|
val imagePathFlow = MutableStateFlow(DrawableResource("1.png")) |
|
|
|
|
setContent { |
|
|
|
|
CompositionLocalProvider(LocalResourceReader provides testResourceReader) { |
|
|
|
|
CompositionLocalProvider( |
|
|
|
|
LocalResourceReader provides testResourceReader, |
|
|
|
|
LocalComposeEnvironment provides TestComposeEnvironment |
|
|
|
|
) { |
|
|
|
|
val res by imagePathFlow.collectAsState() |
|
|
|
|
Image(painterResource(res), null) |
|
|
|
|
} |
|
|
|
@ -72,7 +75,10 @@ class ComposeResourceTest {
|
|
|
|
|
val testResourceReader = TestResourceReader() |
|
|
|
|
val stringIdFlow = MutableStateFlow(TestStringResource("app_name")) |
|
|
|
|
setContent { |
|
|
|
|
CompositionLocalProvider(LocalResourceReader provides testResourceReader) { |
|
|
|
|
CompositionLocalProvider( |
|
|
|
|
LocalResourceReader provides testResourceReader, |
|
|
|
|
LocalComposeEnvironment provides TestComposeEnvironment |
|
|
|
|
) { |
|
|
|
|
val res by stringIdFlow.collectAsState() |
|
|
|
|
Text(stringResource(res)) |
|
|
|
|
Text(stringArrayResource(TestStringResource("str_arr")).joinToString()) |
|
|
|
@ -95,12 +101,20 @@ class ComposeResourceTest {
|
|
|
|
|
fun testReadStringResource() = runComposeUiTest { |
|
|
|
|
runBlockingTest { |
|
|
|
|
setContent { |
|
|
|
|
assertEquals("Compose Resources App", stringResource(TestStringResource("app_name"))) |
|
|
|
|
CompositionLocalProvider(LocalComposeEnvironment provides TestComposeEnvironment) { |
|
|
|
|
assertEquals( |
|
|
|
|
"Compose Resources App", |
|
|
|
|
stringResource(TestStringResource("app_name")) |
|
|
|
|
) |
|
|
|
|
assertEquals( |
|
|
|
|
"Hello, test-name! You have 42 new messages.", |
|
|
|
|
stringResource(TestStringResource("str_template"), "test-name", 42) |
|
|
|
|
) |
|
|
|
|
assertEquals(listOf("item 1", "item 2", "item 3"), stringArrayResource(TestStringResource("str_arr"))) |
|
|
|
|
assertEquals( |
|
|
|
|
listOf("item 1", "item 2", "item 3"), |
|
|
|
|
stringArrayResource(TestStringResource("str_arr")) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
awaitIdle() |
|
|
|
|
} |
|
|
|
|