Skip to content

Commit

Permalink
Add stringResource test for testharness
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Nov 22, 2022
1 parent 40ea604 commit 5adcbc5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
Expand All @@ -33,14 +34,17 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.core.os.LocaleListCompat
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import com.google.accompanist.testharness.test.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Rule
Expand Down Expand Up @@ -142,6 +146,26 @@ class TestHarnessTest {
assertEquals(expectedLocales, locales)
}

@Test
fun usLocale_usesCorrectResource() {
composeTestRule.setContent {
TestHarness(locales = LocaleListCompat.forLanguageTags("us")) {
BasicText(text = stringResource(R.string.this_is_content, "abc"))
}
}
composeTestRule.onNodeWithText("This is content\nabc").assertExists()
}

@Test
fun arLocale_usesCorrectResource() {
composeTestRule.setContent {
TestHarness(locales = LocaleListCompat.forLanguageTags("ar")) {
BasicText(text = stringResource(R.string.this_is_content, "abc"))
}
}
composeTestRule.onNodeWithText("هذا مضمون \nabc").assertExists()
}

@Test
fun layoutDirection_RtlLocale_usesOverride() {
lateinit var direction: LayoutDirection
Expand Down
19 changes: 19 additions & 0 deletions testharness/src/sharedTest/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2022 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>
<string name="this_is_content">هذا مضمون \n%s</string>
</resources>
19 changes: 19 additions & 0 deletions testharness/src/sharedTest/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
~ Copyright 2022 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>
<string name="this_is_content">This is content\n%s</string>
</resources>

0 comments on commit 5adcbc5

Please sign in to comment.