how to change the locale in the middle of an compose ui test. I tried with the below approach. But it doesn't work
fun setLocale(locale: Locale) {
val resources = InstrumentationRegistry.getInstrumentation().targetContext.resources
val config = resources.configuration config.setLocale(locale)
resources.updateConfiguration(config, resources.displayMetrics)
}
and the test is
@Test
fun testChangeLocaleInMiddle() {
composeTestRule.onNodeWithText("Hello").assertExists()
// Change the locale to Tamil
setLocale(Locale("ta"))
// Recompose the UI
composeTestRule.activityRule.scenario.onActivity { activity ->
activity.recreate()
}
// Allow time for the activity to recreate
Thread.sleep(1000)
// Perform actions in the new locale
composeTestRule.onNodeWithText("வணக்கம்").assertExists()
}