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