From 4b366374beaee825151937e99faac9db3367f86b Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Fri, 7 Jun 2024 09:29:38 +0100 Subject: [PATCH] Improve RTL Tests (#2258) --- compose-material/build.gradle.kts | 6 ++ .../src/debug/res/values/strings.xml | 21 +++++ .../horologist/compose/material/ButtonTest.kt | 59 +++++++------- .../horologist/compose/material/ChipTest.kt | 65 ++++++++-------- .../compose/material/CompactChipTest.kt | 56 +++++++------- .../horologist/compose/material/IconTest.kt | 62 +++++++-------- .../compose/material/OutlinedChipTest.kt | 65 ++++++++-------- .../material/OutlinedCompactChipTest.kt | 56 +++++++------- .../compose/material/SplitToggleChipTest.kt | 36 ++++----- .../horologist/compose/material/TitleTest.kt | 45 +++++------ .../compose/material/ToggleButtonTest.kt | 33 ++++---- .../compose/material/ToggleChipTest.kt | 77 +++++++++---------- ..._ChipTest_withSecondaryLabelAndIconRtl.png | 4 +- ...e.material_CompactChipTest_mirroredRtl.png | 4 +- ...Test_usingDrawableResAsIconMirroredRtl.png | 4 +- ...e.material_CompactChipTest_withIconRtl.png | 4 +- ...dChipTest_withSecondaryLabelAndIconRtl.png | 4 +- ...al_OutlinedCompactChipTest_mirroredRtl.png | 4 +- ...Test_usingDrawableResAsIconMirroredRtl.png | 4 +- ...al_OutlinedCompactChipTest_withIconRtl.png | 4 +- ...mpose.material_SplitToggleChipTest_rtl.png | 4 +- ...e.material_TitleTest_defaultPrimaryRtl.png | 4 +- ...material_TitleTest_defaultSecondaryRtl.png | 4 +- ...aterial_TitleTest_mirroredRtlSecondary.png | 4 +- ...ose.material_ToggleChipTest_defaultRtl.png | 4 +- ...se.material_ToggleChipTest_mirroredRtl.png | 4 +- health/composables/build.gradle.kts | 6 ++ .../src/debug/res/values/strings.xml | 22 ++++++ .../components/MetricDisplayA11yTest.kt | 28 +++---- .../screens/MetricsScreenA11yTest.kt | 34 ++++---- ...s.components_MetricDisplayA11yTest_rtl.png | 4 +- ...enA11yTest_metricsScreenTwoMetrics_rtl.png | 4 +- roboscreenshots/api/current.api | 1 + .../screenshots/rng/WearLegacyA11yTest.kt | 33 ++++---- .../rng/WearLegacyComponentTest.kt | 5 +- .../screenshots/rng/WearScreenshotTest.kt | 34 ++++++-- 36 files changed, 436 insertions(+), 372 deletions(-) create mode 100644 compose-material/src/debug/res/values/strings.xml create mode 100644 health/composables/src/debug/res/values/strings.xml diff --git a/compose-material/build.gradle.kts b/compose-material/build.gradle.kts index f0409e00d0..c799175e44 100644 --- a/compose-material/build.gradle.kts +++ b/compose-material/build.gradle.kts @@ -32,6 +32,12 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { + debug { + isPseudoLocalesEnabled = true + } + } + compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 diff --git a/compose-material/src/debug/res/values/strings.xml b/compose-material/src/debug/res/values/strings.xml new file mode 100644 index 0000000000..93cd5ff684 --- /dev/null +++ b/compose-material/src/debug/res/values/strings.xml @@ -0,0 +1,21 @@ + + + + Primary label + Secondary label + Title + \ No newline at end of file diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/ButtonTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/ButtonTest.kt index c56684832c..625183783e 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/ButtonTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/ButtonTest.kt @@ -19,11 +19,10 @@ package com.google.android.horologist.compose.material import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.DirectionsBike import androidx.compose.material.icons.filled.Check -import androidx.compose.ui.unit.LayoutDirection import androidx.wear.compose.material.ButtonDefaults -import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config internal class ButtonTest : WearLegacyComponentTest() { @@ -125,15 +124,14 @@ internal class ButtonTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun usingDrawableResAsIconRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Button( - id = android.R.drawable.ic_media_play, - contentDescription = "contentDescription", - onClick = { }, - ) - } + Button( + id = android.R.drawable.ic_media_play, + contentDescription = "contentDescription", + onClick = { }, + ) } } @@ -150,29 +148,27 @@ internal class ButtonTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun usingDrawableResAsIconMirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Button( - id = android.R.drawable.ic_media_play, - contentDescription = "contentDescription", - onClick = { }, - iconRtlMode = IconRtlMode.Mirrored, - ) - } + Button( + id = android.R.drawable.ic_media_play, + contentDescription = "contentDescription", + onClick = { }, + iconRtlMode = IconRtlMode.Mirrored, + ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun defaultRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Button( - imageVector = Icons.Default.Check, - contentDescription = "contentDescription", - onClick = { }, - ) - } + Button( + imageVector = Icons.Default.Check, + contentDescription = "contentDescription", + onClick = { }, + ) } } @@ -189,16 +185,15 @@ internal class ButtonTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun mirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Button( - imageVector = Icons.AutoMirrored.Default.DirectionsBike, - contentDescription = "contentDescription", - onClick = { }, - iconRtlMode = IconRtlMode.Mirrored, - ) - } + Button( + imageVector = Icons.AutoMirrored.Default.DirectionsBike, + contentDescription = "contentDescription", + onClick = { }, + iconRtlMode = IconRtlMode.Mirrored, + ) } } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt index d56c07e387..a47d8ad9f4 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/ChipTest.kt @@ -27,6 +27,7 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.wear.compose.material.ChipDefaults @@ -35,6 +36,7 @@ import com.google.android.horologist.images.base.paintable.DrawableResPaintable import com.google.android.horologist.images.base.paintable.ImageVectorPaintable.Companion.asPaintable import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class ChipTest : WearLegacyComponentTest() { @@ -42,7 +44,7 @@ class ChipTest : WearLegacyComponentTest() { fun default() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, ) } @@ -52,9 +54,9 @@ class ChipTest : WearLegacyComponentTest() { fun withSecondaryLabel() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), ) } } @@ -63,7 +65,7 @@ class ChipTest : WearLegacyComponentTest() { fun withIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icons.Default.Image.asPaintable(), ) @@ -74,7 +76,7 @@ class ChipTest : WearLegacyComponentTest() { fun withLargeIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon32dp.asPaintable(), largeIcon = true, @@ -86,9 +88,9 @@ class ChipTest : WearLegacyComponentTest() { fun withSecondaryLabelAndIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), ) } @@ -98,9 +100,9 @@ class ChipTest : WearLegacyComponentTest() { fun withSecondaryLabelAndLargeIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icon32dp.asPaintable(), largeIcon = true, ) @@ -111,9 +113,9 @@ class ChipTest : WearLegacyComponentTest() { fun disabled() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), enabled = false, ) @@ -212,7 +214,7 @@ class ChipTest : WearLegacyComponentTest() { fun usingSmallIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon12dp.asPaintable(), ) @@ -223,7 +225,7 @@ class ChipTest : WearLegacyComponentTest() { fun usingDrawableResAsIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = DrawableResPaintable(R.drawable.ic_delete), ) @@ -234,7 +236,7 @@ class ChipTest : WearLegacyComponentTest() { fun withLargeIconUsingSmallIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon12dp.asPaintable(), largeIcon = true, @@ -246,7 +248,7 @@ class ChipTest : WearLegacyComponentTest() { fun usingExtraLargeIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon48dp.asPaintable(), ) @@ -257,7 +259,7 @@ class ChipTest : WearLegacyComponentTest() { fun withLargeIconUsingExtraLargeIcon() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon48dp.asPaintable(), largeIcon = true, @@ -266,16 +268,15 @@ class ChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun withSecondaryLabelAndIconRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Chip( - label = "Primary label", - onClick = { }, - secondaryLabel = "Secondary label", - icon = Icons.Default.Image.asPaintable(), - ) - } + Chip( + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + onClick = { }, + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), + icon = Icons.Default.Image.asPaintable(), + ) } } @@ -283,9 +284,9 @@ class ChipTest : WearLegacyComponentTest() { fun withSecondaryChipColors() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), colors = ChipDefaults.secondaryChipColors(), ) @@ -296,9 +297,9 @@ class ChipTest : WearLegacyComponentTest() { fun withGradientBackgroundChipColors() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), colors = ChipDefaults.gradientBackgroundChipColors(), ) @@ -309,9 +310,9 @@ class ChipTest : WearLegacyComponentTest() { fun withImageBackgroundChipColors() { runComponentTest { Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), colors = ChipDefaults.imageBackgroundChipColors( backgroundImagePainter = painterResource(id = R.drawable.ic_dialog_alert), @@ -326,9 +327,9 @@ class ChipTest : WearLegacyComponentTest() { CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { @Suppress("Deprecation") Chip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Outlined.VolumeDown.asPaintable(), iconRtlMode = IconRtlMode.Mirrored, ) diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/CompactChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/CompactChipTest.kt index adbff8018c..ba3eeed704 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/CompactChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/CompactChipTest.kt @@ -20,12 +20,13 @@ import android.R import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.DirectionsBike import androidx.compose.material.icons.filled.Add -import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.res.stringResource import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.images.base.paintable.DrawableResPaintable import com.google.android.horologist.images.base.paintable.ImageVectorPaintable.Companion.asPaintable import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class CompactChipTest : WearLegacyComponentTest() { @@ -33,7 +34,7 @@ class CompactChipTest : WearLegacyComponentTest() { fun default() { runComponentTest { CompactChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, ) } @@ -43,7 +44,7 @@ class CompactChipTest : WearLegacyComponentTest() { fun withIcon() { runComponentTest { CompactChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icons.Filled.Add.asPaintable(), ) @@ -65,7 +66,7 @@ class CompactChipTest : WearLegacyComponentTest() { fun disabled() { runComponentTest { CompactChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icons.Filled.Add.asPaintable(), enabled = false, @@ -99,7 +100,7 @@ class CompactChipTest : WearLegacyComponentTest() { fun usingDrawableResAsIcon() { runComponentTest { CompactChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = DrawableResPaintable(R.drawable.ic_delete), ) @@ -107,15 +108,14 @@ class CompactChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun withIconRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - CompactChip( - label = "Primary label", - onClick = { }, - icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), - ) - } + CompactChip( + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + onClick = { }, + icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), + ) } } @@ -123,7 +123,7 @@ class CompactChipTest : WearLegacyComponentTest() { fun mirrored() { runComponentTest { CompactChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), iconRtlMode = IconRtlMode.Mirrored, @@ -132,30 +132,28 @@ class CompactChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun mirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - CompactChip( - label = "Primary label", - onClick = { }, - icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), - iconRtlMode = IconRtlMode.Mirrored, - ) - } + CompactChip( + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + onClick = { }, + icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), + iconRtlMode = IconRtlMode.Mirrored, + ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun usingDrawableResAsIconMirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - CompactChip( - label = "Primary label", - onClick = { }, - icon = DrawableResPaintable(R.drawable.ic_media_play), - iconRtlMode = IconRtlMode.Mirrored, - ) - } + CompactChip( + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + onClick = { }, + icon = DrawableResPaintable(R.drawable.ic_media_play), + iconRtlMode = IconRtlMode.Mirrored, + ) } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/IconTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/IconTest.kt index 9fc60e5f66..cb74320c8c 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/IconTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/IconTest.kt @@ -19,12 +19,11 @@ package com.google.android.horologist.compose.material import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.VolumeDown import androidx.compose.material.icons.outlined.Abc -import androidx.compose.ui.unit.LayoutDirection -import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.images.base.paintable.DrawableResPaintable import com.google.android.horologist.images.base.paintable.ImageVectorPaintable.Companion.asPaintable import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class IconTest : WearLegacyComponentTest() { @@ -39,14 +38,13 @@ class IconTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun defaultRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Icon( - paintable = Icons.Outlined.Abc.asPaintable(), - contentDescription = "contentDescription", - ) - } + Icon( + paintable = Icons.Outlined.Abc.asPaintable(), + contentDescription = "contentDescription", + ) } } @@ -62,15 +60,14 @@ class IconTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun mirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Icon( - paintable = Icons.Outlined.Abc.asPaintable(), - contentDescription = "contentDescription", - rtlMode = IconRtlMode.Mirrored, - ) - } + Icon( + paintable = Icons.Outlined.Abc.asPaintable(), + contentDescription = "contentDescription", + rtlMode = IconRtlMode.Mirrored, + ) } } @@ -85,14 +82,13 @@ class IconTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun autoMirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Icon( - paintable = Icons.AutoMirrored.Outlined.VolumeDown.asPaintable(), - contentDescription = "contentDescription", - ) - } + Icon( + paintable = Icons.AutoMirrored.Outlined.VolumeDown.asPaintable(), + contentDescription = "contentDescription", + ) } } @@ -107,14 +103,13 @@ class IconTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun usingDrawableResAsIconRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Icon( - paintable = DrawableResPaintable(android.R.drawable.ic_media_play), - contentDescription = "contentDescription", - ) - } + Icon( + paintable = DrawableResPaintable(android.R.drawable.ic_media_play), + contentDescription = "contentDescription", + ) } } @@ -130,15 +125,14 @@ class IconTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun usingDrawableResAsIconMirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Icon( - paintable = DrawableResPaintable(android.R.drawable.ic_media_play), - contentDescription = "contentDescription", - rtlMode = IconRtlMode.Mirrored, - ) - } + Icon( + paintable = DrawableResPaintable(android.R.drawable.ic_media_play), + contentDescription = "contentDescription", + rtlMode = IconRtlMode.Mirrored, + ) } } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedChipTest.kt index 1a25848d66..c4b54e06b8 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedChipTest.kt @@ -27,6 +27,7 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.wear.compose.material.ChipDefaults @@ -35,6 +36,7 @@ import com.google.android.horologist.images.base.paintable.DrawableResPaintable import com.google.android.horologist.images.base.paintable.ImageVectorPaintable.Companion.asPaintable import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class OutlinedChipTest : WearLegacyComponentTest() { @@ -42,7 +44,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun default() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, ) } @@ -52,9 +54,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withSecondaryLabel() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), ) } } @@ -63,7 +65,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icons.Default.Image.asPaintable(), ) @@ -74,7 +76,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withLargeIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon32dp.asPaintable(), largeIcon = true, @@ -86,9 +88,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withSecondaryLabelAndIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), ) } @@ -98,9 +100,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withSecondaryLabelAndLargeIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icon32dp.asPaintable(), largeIcon = true, ) @@ -111,9 +113,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun disabled() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), enabled = false, ) @@ -212,7 +214,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun usingSmallIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon12dp.asPaintable(), ) @@ -223,7 +225,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun usingDrawableResAsIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = DrawableResPaintable(R.drawable.ic_delete), ) @@ -234,7 +236,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withLargeIconUsingSmallIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon12dp.asPaintable(), largeIcon = true, @@ -246,7 +248,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun usingExtraLargeIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon48dp.asPaintable(), ) @@ -257,7 +259,7 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withLargeIconUsingExtraLargeIcon() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, icon = Icon48dp.asPaintable(), largeIcon = true, @@ -266,16 +268,15 @@ class OutlinedChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun withSecondaryLabelAndIconRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - OutlinedChip( - label = "Primary label", - onClick = { }, - secondaryLabel = "Secondary label", - icon = Icons.Default.Image.asPaintable(), - ) - } + OutlinedChip( + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + onClick = { }, + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), + icon = Icons.Default.Image.asPaintable(), + ) } } @@ -283,9 +284,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withSecondaryChipColors() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), colors = ChipDefaults.secondaryChipColors(), ) @@ -296,9 +297,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withGradientBackgroundChipColors() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), colors = ChipDefaults.gradientBackgroundChipColors(), ) @@ -309,9 +310,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { fun withImageBackgroundChipColors() { runComponentTest { OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image.asPaintable(), colors = ChipDefaults.imageBackgroundChipColors( backgroundImagePainter = painterResource(id = R.drawable.ic_dialog_alert), @@ -326,9 +327,9 @@ class OutlinedChipTest : WearLegacyComponentTest() { CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) { @Suppress("Deprecation") OutlinedChip( - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Outlined.VolumeDown.asPaintable(), iconRtlMode = IconRtlMode.Mirrored, colors = ChipDefaults.imageBackgroundChipColors( diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedCompactChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedCompactChipTest.kt index b625097903..6c881c1a40 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedCompactChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/OutlinedCompactChipTest.kt @@ -20,12 +20,13 @@ import android.R import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.DirectionsBike import androidx.compose.material.icons.filled.Add -import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.res.stringResource import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.images.base.paintable.DrawableResPaintable import com.google.android.horologist.images.base.paintable.ImageVectorPaintable.Companion.asPaintable import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class OutlinedCompactChipTest : WearLegacyComponentTest() { @@ -34,7 +35,7 @@ class OutlinedCompactChipTest : WearLegacyComponentTest() { runComponentTest { OutlinedCompactChip( onClick = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), ) } } @@ -44,7 +45,7 @@ class OutlinedCompactChipTest : WearLegacyComponentTest() { runComponentTest { OutlinedCompactChip( onClick = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), icon = Icons.Filled.Add.asPaintable(), ) } @@ -65,7 +66,7 @@ class OutlinedCompactChipTest : WearLegacyComponentTest() { runComponentTest { OutlinedCompactChip( onClick = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), icon = Icons.Filled.Add.asPaintable(), enabled = false, ) @@ -99,22 +100,21 @@ class OutlinedCompactChipTest : WearLegacyComponentTest() { runComponentTest { OutlinedCompactChip( onClick = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), icon = DrawableResPaintable(R.drawable.ic_delete), ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun withIconRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - OutlinedCompactChip( - onClick = { }, - label = "Primary label", - icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), - ) - } + OutlinedCompactChip( + onClick = { }, + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), + ) } } @@ -123,7 +123,7 @@ class OutlinedCompactChipTest : WearLegacyComponentTest() { runComponentTest { OutlinedCompactChip( onClick = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), iconRtlMode = IconRtlMode.Mirrored, ) @@ -131,30 +131,28 @@ class OutlinedCompactChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun mirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - OutlinedCompactChip( - onClick = { }, - label = "Primary label", - icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), - iconRtlMode = IconRtlMode.Mirrored, - ) - } + OutlinedCompactChip( + onClick = { }, + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + icon = Icons.AutoMirrored.Default.DirectionsBike.asPaintable(), + iconRtlMode = IconRtlMode.Mirrored, + ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun usingDrawableResAsIconMirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - OutlinedCompactChip( - onClick = { }, - label = "Primary label", - icon = DrawableResPaintable(R.drawable.ic_media_play), - iconRtlMode = IconRtlMode.Mirrored, - ) - } + OutlinedCompactChip( + onClick = { }, + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + icon = DrawableResPaintable(R.drawable.ic_media_play), + iconRtlMode = IconRtlMode.Mirrored, + ) } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/SplitToggleChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/SplitToggleChipTest.kt index 8b171f04b4..b240386363 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/SplitToggleChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/SplitToggleChipTest.kt @@ -16,10 +16,11 @@ package com.google.android.horologist.compose.material -import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.res.stringResource import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class SplitToggleChipTest : WearLegacyComponentTest() { @@ -29,7 +30,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Switch, ) @@ -42,7 +43,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Radio, ) @@ -55,7 +56,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Checkbox, ) @@ -68,7 +69,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = false, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Switch, ) @@ -81,7 +82,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Switch, secondaryLabel = "Secondary label", @@ -95,7 +96,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Switch, enabled = false, @@ -109,7 +110,7 @@ class SplitToggleChipTest : WearLegacyComponentTest() { SplitToggleChip( checked = false, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), onClick = { }, toggleControl = ToggleChipToggleControl.Switch, enabled = false, @@ -176,18 +177,17 @@ class SplitToggleChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun rtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - SplitToggleChip( - checked = true, - onCheckedChanged = { }, - label = "Primary label", - onClick = { }, - toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", - ) - } + SplitToggleChip( + checked = true, + onCheckedChanged = { }, + label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label), + onClick = { }, + toggleControl = ToggleChipToggleControl.Switch, + secondaryLabel = "Secondary label", + ) } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/TitleTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/TitleTest.kt index 7e9be1f28d..0232870780 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/TitleTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/TitleTest.kt @@ -19,10 +19,10 @@ package com.google.android.horologist.compose.material import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.MusicNote import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.LayoutDirection -import com.google.accompanist.testharness.TestHarness +import androidx.compose.ui.res.stringResource import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class TitleTest : WearLegacyComponentTest() { @@ -30,7 +30,7 @@ class TitleTest : WearLegacyComponentTest() { fun defaultPrimary() { runComponentTest { Title( - text = "Title", + text = stringResource(id = R.string.title), ) } } @@ -50,7 +50,7 @@ class TitleTest : WearLegacyComponentTest() { fun defaultSecondary() { runComponentTest { SecondaryTitle( - text = "Title", + text = stringResource(id = R.string.title), ) } } @@ -70,7 +70,7 @@ class TitleTest : WearLegacyComponentTest() { fun defaultSecondaryWithIcon() { runComponentTest { SecondaryTitle( - text = "Title", + text = stringResource(id = R.string.title), icon = Icons.Outlined.MusicNote, iconTint = Color(0xFF946EB1), ) @@ -91,24 +91,22 @@ class TitleTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun defaultPrimaryRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - Title( - text = "Title", - ) - } + Title( + text = stringResource(id = R.string.title), + ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun defaultSecondaryRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - SecondaryTitle( - text = "Title", - ) - } + SecondaryTitle( + text = stringResource(id = R.string.title), + ) } } @@ -116,7 +114,7 @@ class TitleTest : WearLegacyComponentTest() { fun mirroredSecondary() { runComponentTest { SecondaryTitle( - text = "Title", + text = stringResource(id = R.string.title), icon = Icons.Outlined.MusicNote, iconTint = Color(0xFF946EB1), iconRtlMode = IconRtlMode.Mirrored, @@ -125,16 +123,15 @@ class TitleTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun mirroredRtlSecondary() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - SecondaryTitle( - text = "Title", - icon = Icons.Outlined.MusicNote, - iconTint = Color(0xFF946EB1), - iconRtlMode = IconRtlMode.Mirrored, - ) - } + SecondaryTitle( + text = stringResource(id = R.string.title), + icon = Icons.Outlined.MusicNote, + iconTint = Color(0xFF946EB1), + iconRtlMode = IconRtlMode.Mirrored, + ) } } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleButtonTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleButtonTest.kt index 1c571169ea..e413fd26f6 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleButtonTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleButtonTest.kt @@ -21,11 +21,11 @@ import androidx.compose.material.icons.automirrored.filled.VolumeOff import androidx.compose.material.icons.automirrored.filled.VolumeUp import androidx.compose.material.icons.filled.AirplanemodeActive import androidx.compose.material.icons.filled.AirplanemodeInactive -import androidx.compose.ui.unit.LayoutDirection import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.images.base.paintable.ImageVectorPaintable.Companion.asPaintable import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class ToggleButtonTest : WearLegacyComponentTest() { @@ -237,16 +237,15 @@ class ToggleButtonTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun rtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - ToggleButton( - checkedIcon = Icons.AutoMirrored.Filled.VolumeUp.asPaintable(), - notCheckedIcon = Icons.AutoMirrored.Filled.VolumeOff.asPaintable(), - contentDescription = "contentDescription", - onCheckedChanged = {}, - ) - } + ToggleButton( + checkedIcon = Icons.AutoMirrored.Filled.VolumeUp.asPaintable(), + notCheckedIcon = Icons.AutoMirrored.Filled.VolumeOff.asPaintable(), + contentDescription = "contentDescription", + onCheckedChanged = {}, + ) } } @@ -266,15 +265,13 @@ class ToggleButtonTest : WearLegacyComponentTest() { @Test fun mirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - ToggleButton( - checkedIcon = Icons.AutoMirrored.Filled.VolumeUp.asPaintable(), - notCheckedIcon = Icons.AutoMirrored.Filled.VolumeOff.asPaintable(), - contentDescription = "contentDescription", - onCheckedChanged = {}, - iconRtlMode = IconRtlMode.Mirrored, - ) - } + ToggleButton( + checkedIcon = Icons.AutoMirrored.Filled.VolumeUp.asPaintable(), + notCheckedIcon = Icons.AutoMirrored.Filled.VolumeOff.asPaintable(), + contentDescription = "contentDescription", + onCheckedChanged = {}, + iconRtlMode = IconRtlMode.Mirrored, + ) } } diff --git a/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleChipTest.kt b/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleChipTest.kt index 700613eb19..48569b311f 100644 --- a/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleChipTest.kt +++ b/compose-material/src/test/java/com/google/android/horologist/compose/material/ToggleChipTest.kt @@ -21,11 +21,12 @@ import androidx.compose.material.icons.filled.Image import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.materialPath import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.google.accompanist.testharness.TestHarness import com.google.android.horologist.screenshots.rng.WearLegacyComponentTest import org.junit.Test +import org.robolectric.annotation.Config class ToggleChipTest : WearLegacyComponentTest() { @@ -35,7 +36,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, ) } @@ -47,7 +48,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Radio, ) } @@ -59,7 +60,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Checkbox, ) } @@ -71,7 +72,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = false, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, ) } @@ -83,9 +84,9 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), ) } } @@ -96,7 +97,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, icon = Icons.Default.Image, ) @@ -109,9 +110,9 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.Image, ) } @@ -123,7 +124,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, enabled = false, ) @@ -136,7 +137,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = false, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, enabled = false, ) @@ -261,7 +262,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, icon = Icon12dp, ) @@ -274,7 +275,7 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, icon = Icon32dp, ) @@ -289,27 +290,26 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.PlayArrow, ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun defaultRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - ToggleChip( - checked = true, - onCheckedChanged = { }, - label = "Primary label", - toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", - icon = Icons.Default.PlayArrow, - ) - } + ToggleChip( + checked = true, + onCheckedChanged = { }, + label = stringResource(R.string.primary_label), + toggleControl = ToggleChipToggleControl.Switch, + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), + icon = Icons.Default.PlayArrow, + ) } } @@ -319,9 +319,9 @@ class ToggleChipTest : WearLegacyComponentTest() { ToggleChip( checked = true, onCheckedChanged = { }, - label = "Primary label", + label = stringResource(R.string.primary_label), toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), icon = Icons.Default.PlayArrow, iconRtlMode = IconRtlMode.Mirrored, ) @@ -329,19 +329,18 @@ class ToggleChipTest : WearLegacyComponentTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun mirroredRtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - ToggleChip( - checked = true, - onCheckedChanged = { }, - label = "Primary label", - toggleControl = ToggleChipToggleControl.Switch, - secondaryLabel = "Secondary label", - icon = Icons.Default.PlayArrow, - iconRtlMode = IconRtlMode.Mirrored, - ) - } + ToggleChip( + checked = true, + onCheckedChanged = { }, + label = stringResource(R.string.primary_label), + toggleControl = ToggleChipToggleControl.Switch, + secondaryLabel = stringResource(com.google.android.horologist.compose.material.R.string.secondary_label), + icon = Icons.Default.PlayArrow, + iconRtlMode = IconRtlMode.Mirrored, + ) } } diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withSecondaryLabelAndIconRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withSecondaryLabelAndIconRtl.png index 86001313ff..ea917dd409 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withSecondaryLabelAndIconRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ChipTest_withSecondaryLabelAndIconRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:60aa1e6991a8192e82caa470f8c9de424e777906485d36ba156e781124134c17 -size 7584 +oid sha256:caef2ffc966d3aaf6636747dac80ed05c39a7a1356bad5080a1f8abe24639560 +size 7609 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_mirroredRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_mirroredRtl.png index df5c6cfca1..1c0118941c 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_mirroredRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_mirroredRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:70ea30729a321d1e37bb332bcc3702528b67e559a3278ce068a239f1af060e89 -size 4606 +oid sha256:ec486b486966917b77e8d6758b4a8187af0317e64e29e0c8e766f78a5f578649 +size 4598 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_usingDrawableResAsIconMirroredRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_usingDrawableResAsIconMirroredRtl.png index c2734393b0..c4cd5da26d 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_usingDrawableResAsIconMirroredRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_usingDrawableResAsIconMirroredRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:350db0e903d1d9c797a40013a9f2dbc114dd62ce9c75b06ec0dd9c5b0aedc509 -size 4538 +oid sha256:5a51652024cd74196964f6313d1dce712581b6f4516bc037483e9b4c1a74a216 +size 4534 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_withIconRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_withIconRtl.png index 8cce2f8415..e529c53825 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_withIconRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_CompactChipTest_withIconRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5e89d593eda1ca77747f5e60cefe433b717392c975d1ac4382aa170d40510e57 -size 4604 +oid sha256:9fa7d0fef3b469a68555c054c95797db6df4f47e257e98b496bd99c46989f0d8 +size 4596 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedChipTest_withSecondaryLabelAndIconRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedChipTest_withSecondaryLabelAndIconRtl.png index 33b9c5e395..8d1264642a 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedChipTest_withSecondaryLabelAndIconRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedChipTest_withSecondaryLabelAndIconRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ab50ed2702724b4cbd010f1940055b36116e3c1c3e6135c1b2ee8044c32ea144 -size 9541 +oid sha256:ef5e72d7d874773c1a3c4b5f3711d429becff1829dc53b14e6096c0e6404ff92 +size 9563 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_mirroredRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_mirroredRtl.png index e909383f8a..0edf76e92f 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_mirroredRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_mirroredRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b1c7b0aa97342ee7ba5d472f423c699fdddb891b0481a1a24a86c69f5479d42 -size 5669 +oid sha256:ea5a135ebb578c1974e1ccea0d55fa9a08f1c74133416ed9ea9dc063773c0de4 +size 5683 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_usingDrawableResAsIconMirroredRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_usingDrawableResAsIconMirroredRtl.png index a525248697..b9fed8b818 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_usingDrawableResAsIconMirroredRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_usingDrawableResAsIconMirroredRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d6adaaba44847ff1e4eadd6cb75ba24c6c7545fec34ca168fe03a5c6509146b2 -size 5701 +oid sha256:c9c243757d519ffeb9a723ced66e235d43e3546ba5897f041c7d941da73a8067 +size 5668 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_withIconRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_withIconRtl.png index 5e129dfa3f..fcf2e5d599 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_withIconRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_OutlinedCompactChipTest_withIconRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e7bab68ffa4c33b686912920701dc484832aee8719a84f8a9016e3ccfdbd4323 -size 5674 +oid sha256:56bd8c4e0366c35482863d93b1ed3b4c2185b9470fdfdeca8af153a6b0a4ac40 +size 5681 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_SplitToggleChipTest_rtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_SplitToggleChipTest_rtl.png index f380ccf2fc..2e8aef82f8 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_SplitToggleChipTest_rtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_SplitToggleChipTest_rtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1c6135d1c45e45d32f1fc086ad82da95226e0ee9fc06a988e0e0b397ae10c667 -size 8290 +oid sha256:7b9b121dedfb7ba0aeb7678c2b3a900ff347216f8070c20d83b55e78c0fe64b9 +size 8313 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultPrimaryRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultPrimaryRtl.png index 7757502a52..873496a1e5 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultPrimaryRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultPrimaryRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f5a27d41d344cd97aede0e3df5149c514910827432a6ba34a7c58eff184f8613 -size 1209 +oid sha256:dfe6fd9435e5336b2f14b22aec9fb776f6e285a2fcde937ebd094d1a5f4e9e6d +size 1249 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultSecondaryRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultSecondaryRtl.png index 9ca4ef9ce5..f7a49a4717 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultSecondaryRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_defaultSecondaryRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:76ce7d7ec42d5cb6b0d3e41097490d03021b3bee7df5a7348145f8d7816b79f5 -size 1112 +oid sha256:502ae493745f86c8a061a234b3dca34c4b1e21085c7835a84b5f1a3f39c482ef +size 1110 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_mirroredRtlSecondary.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_mirroredRtlSecondary.png index d9e273b3b8..f63d0b7bc2 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_mirroredRtlSecondary.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_TitleTest_mirroredRtlSecondary.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65283e528d2615a62fb196a358326bc5a46b6f05a823aa45d233fb495c2db869 -size 1550 +oid sha256:ad651e3d4bba640749a165b03056d9f0b510e750f94ee98bde9315ffd36e8720 +size 1564 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_defaultRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_defaultRtl.png index 7e477c7d88..c1d24e14a5 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_defaultRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_defaultRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1a20824f2c9dd84f365c597b28fd1acb830d0699bd7f6f3118336895f209cc6a -size 35196 +oid sha256:7b339059743da7d1281330c686b45499e3b2ca3c20dfb34016849959bf34a2a1 +size 35351 diff --git a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_mirroredRtl.png b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_mirroredRtl.png index 0c9d4db841..c965def714 100644 --- a/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_mirroredRtl.png +++ b/compose-material/src/test/snapshots/images/com.google.android.horologist.compose.material_ToggleChipTest_mirroredRtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:14fd4aaf43c75204f0093091698008133b6c4e87c94266e971f3fa5424a31ff7 -size 35198 +oid sha256:1691e9eb1977cb9df3e93c36cbd1f816ad111cf6d10bcdd1b2daeb08ceca3c36 +size 35349 diff --git a/health/composables/build.gradle.kts b/health/composables/build.gradle.kts index c1e7386df6..5d93911c25 100644 --- a/health/composables/build.gradle.kts +++ b/health/composables/build.gradle.kts @@ -31,6 +31,12 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { + debug { + isPseudoLocalesEnabled = true + } + } + compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 diff --git a/health/composables/src/debug/res/values/strings.xml b/health/composables/src/debug/res/values/strings.xml new file mode 100644 index 0000000000..a609506642 --- /dev/null +++ b/health/composables/src/debug/res/values/strings.xml @@ -0,0 +1,22 @@ + + + + Peak + mi + Vigorous + bpm + \ No newline at end of file diff --git a/health/composables/src/test/java/com/google/android/horologist/health/composables/components/MetricDisplayA11yTest.kt b/health/composables/src/test/java/com/google/android/horologist/health/composables/components/MetricDisplayA11yTest.kt index 67361c595f..5374823463 100644 --- a/health/composables/src/test/java/com/google/android/horologist/health/composables/components/MetricDisplayA11yTest.kt +++ b/health/composables/src/test/java/com/google/android/horologist/health/composables/components/MetricDisplayA11yTest.kt @@ -16,13 +16,14 @@ package com.google.android.horologist.health.composables.components -import androidx.compose.ui.unit.LayoutDirection -import com.google.accompanist.testharness.TestHarness +import androidx.compose.ui.res.stringResource +import com.google.android.horologist.health.composables.R import com.google.android.horologist.health.composables.model.MetricUiModel import com.google.android.horologist.health.composables.theme.HR_HARD import com.google.android.horologist.health.composables.theme.HR_MODERATE import com.google.android.horologist.screenshots.rng.WearLegacyA11yTest import org.junit.Test +import org.robolectric.annotation.Config class MetricDisplayA11yTest : WearLegacyA11yTest() { @@ -32,8 +33,8 @@ class MetricDisplayA11yTest : WearLegacyA11yTest() { MetricDisplay( metric = MetricUiModel( text = "139", - topRightText = "Vigorous", - bottomRightText = "bpm", + topRightText = stringResource(R.string.horologist_vigorous), + bottomRightText = stringResource(R.string.horologist_bpm), color = HR_MODERATE, ), ) @@ -41,18 +42,17 @@ class MetricDisplayA11yTest : WearLegacyA11yTest() { } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun rtl() { runComponentTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - MetricDisplay( - metric = MetricUiModel( - text = "139", - topRightText = "Vigorous", - bottomRightText = "bpm", - color = HR_HARD, - ), - ) - } + MetricDisplay( + metric = MetricUiModel( + text = "139", + topRightText = stringResource(R.string.horologist_vigorous), + bottomRightText = stringResource(R.string.horologist_bpm), + color = HR_HARD, + ), + ) } } } diff --git a/health/composables/src/test/java/com/google/android/horologist/health/composables/screens/MetricsScreenA11yTest.kt b/health/composables/src/test/java/com/google/android/horologist/health/composables/screens/MetricsScreenA11yTest.kt index bbb665aafd..70e4abf5ac 100644 --- a/health/composables/src/test/java/com/google/android/horologist/health/composables/screens/MetricsScreenA11yTest.kt +++ b/health/composables/src/test/java/com/google/android/horologist/health/composables/screens/MetricsScreenA11yTest.kt @@ -16,12 +16,13 @@ package com.google.android.horologist.health.composables.screens -import androidx.compose.ui.unit.LayoutDirection -import com.google.accompanist.testharness.TestHarness +import androidx.compose.ui.res.stringResource +import com.google.android.horologist.health.composables.R import com.google.android.horologist.health.composables.model.MetricUiModel import com.google.android.horologist.health.composables.theme.HR_MAXIMUM import com.google.android.horologist.screenshots.rng.WearLegacyA11yTest import org.junit.Test +import org.robolectric.annotation.Config class MetricsScreenA11yTest : WearLegacyA11yTest() { @@ -31,33 +32,32 @@ class MetricsScreenA11yTest : WearLegacyA11yTest() { MetricsScreen( firstMetric = MetricUiModel( text = "198", - bottomRightText = "Peak", + bottomRightText = stringResource(R.string.horologist_peak), color = HR_MAXIMUM, ), secondMetric = MetricUiModel( text = "2.7", - bottomRightText = "mi", + bottomRightText = stringResource(R.string.horologist_miles), ), ) } } @Test + @Config(qualifiers = "+ar-rXB-ldrtl") fun metricsScreenTwoMetrics_rtl() { runScreenTest { - TestHarness(layoutDirection = LayoutDirection.Rtl) { - MetricsScreen( - firstMetric = MetricUiModel( - text = "198", - bottomRightText = "Peak", - color = HR_MAXIMUM, - ), - secondMetric = MetricUiModel( - text = "2.7", - bottomRightText = "mi", - ), - ) - } + MetricsScreen( + firstMetric = MetricUiModel( + text = "198", + bottomRightText = stringResource(R.string.horologist_peak), + color = HR_MAXIMUM, + ), + secondMetric = MetricUiModel( + text = "2.7", + bottomRightText = stringResource(R.string.horologist_miles), + ), + ) } } } diff --git a/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.components_MetricDisplayA11yTest_rtl.png b/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.components_MetricDisplayA11yTest_rtl.png index d2d8179112..eb3461f6f0 100644 --- a/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.components_MetricDisplayA11yTest_rtl.png +++ b/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.components_MetricDisplayA11yTest_rtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:81616f5bdab3b1d7a953a7235dddbbf3c847aece30d82c5c271628eff7bc8894 -size 23046 +oid sha256:9fbb80125b8c1724151a53633550487e34ffe410a8f35afaea81dc9504894387 +size 23027 diff --git a/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.screens_MetricsScreenA11yTest_metricsScreenTwoMetrics_rtl.png b/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.screens_MetricsScreenA11yTest_metricsScreenTwoMetrics_rtl.png index 992a022f55..cdb904ee0f 100644 --- a/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.screens_MetricsScreenA11yTest_metricsScreenTwoMetrics_rtl.png +++ b/health/composables/src/test/snapshots/images/com.google.android.horologist.health.composables.screens_MetricsScreenA11yTest_metricsScreenTwoMetrics_rtl.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a7b315fcb40dc14fe1e8605157d338a041171c90779b6888910c003b0e6b919d -size 28562 +oid sha256:d55e13ca1ce5f17177f2840604104db720c461782a0e8d8ed8b91d3b26e88aa2 +size 28573 diff --git a/roboscreenshots/api/current.api b/roboscreenshots/api/current.api index d13c725464..0d8e9cf44a 100644 --- a/roboscreenshots/api/current.api +++ b/roboscreenshots/api/current.api @@ -137,6 +137,7 @@ package com.google.android.horologist.screenshots.rng { } public static final class WearScreenshotTest.Companion { + method @androidx.compose.runtime.Composable public void CorrectLayout(kotlin.jvm.functions.Function0 content); method public void useHardwareRenderer(); method @androidx.compose.runtime.Composable public void withImageLoader(coil.test.FakeImageLoaderEngine? imageLoaderEngine, kotlin.jvm.functions.Function0 content); } diff --git a/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyA11yTest.kt b/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyA11yTest.kt index 512b211d4e..9e58ebb098 100644 --- a/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyA11yTest.kt +++ b/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyA11yTest.kt @@ -50,6 +50,7 @@ import com.google.android.horologist.compose.layout.AppScaffold import com.google.android.horologist.compose.layout.ResponsiveTimeText import com.google.android.horologist.screenshots.FixedTimeSource import com.google.android.horologist.screenshots.a11y.A11ySnapshotTransformer +import com.google.android.horologist.screenshots.rng.WearScreenshotTest.Companion.CorrectLayout import com.google.android.horologist.screenshots.rng.WearScreenshotTest.Companion.useHardwareRenderer import com.google.android.horologist.screenshots.rng.WearScreenshotTest.Companion.withImageLoader import org.junit.Rule @@ -162,25 +163,29 @@ public abstract class WearLegacyA11yTest { @Composable public open fun TestScaffold(content: @Composable () -> Unit) { - AppScaffold( - modifier = Modifier - .fillMaxSize() - .background(MaterialTheme.colors.background), - timeText = { ResponsiveTimeText(timeSource = FixedTimeSource) }, - ) { - content() + CorrectLayout { + AppScaffold( + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colors.background), + timeText = { ResponsiveTimeText(timeSource = FixedTimeSource) }, + ) { + content() + } } } @Composable public open fun ComponentScaffold(content: @Composable () -> Unit) { - Box( - contentAlignment = Alignment.Center, - modifier = Modifier - .fillMaxSize() - .background(Color.Black), - ) { - content() + CorrectLayout { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillMaxSize() + .background(Color.Black), + ) { + content() + } } } diff --git a/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyComponentTest.kt b/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyComponentTest.kt index bf89aa7ac0..5370969ae4 100644 --- a/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyComponentTest.kt +++ b/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearLegacyComponentTest.kt @@ -31,6 +31,7 @@ import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers import com.github.takahirom.roborazzi.RoborazziOptions import com.github.takahirom.roborazzi.ThresholdValidator import com.github.takahirom.roborazzi.captureRoboImage +import com.google.android.horologist.screenshots.rng.WearScreenshotTest.Companion.CorrectLayout import com.google.android.horologist.screenshots.rng.WearScreenshotTest.Companion.useHardwareRenderer import com.google.android.horologist.screenshots.rng.WearScreenshotTest.Companion.withImageLoader import org.junit.Rule @@ -102,7 +103,9 @@ public abstract class WearLegacyComponentTest { @Composable public open fun ComponentScaffold(content: @Composable () -> Unit) { - content() + CorrectLayout { + content() + } } internal companion object { diff --git a/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearScreenshotTest.kt b/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearScreenshotTest.kt index ee7f430313..018f15de94 100644 --- a/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearScreenshotTest.kt +++ b/roboscreenshots/src/main/java/com/google/android/horologist/screenshots/rng/WearScreenshotTest.kt @@ -18,14 +18,18 @@ package com.google.android.horologist.screenshots.rng +import android.util.LayoutDirection.RTL import androidx.compose.foundation.background import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.unit.LayoutDirection import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.wear.compose.material.MaterialTheme import coil.ImageLoader @@ -110,13 +114,15 @@ public abstract class WearScreenshotTest { @Composable public open fun TestScaffold(content: @Composable () -> Unit) { - AppScaffold( - modifier = Modifier - .fillMaxSize() - .background(MaterialTheme.colors.background), - timeText = { ResponsiveTimeText(timeSource = FixedTimeSource) }, - ) { - content() + CorrectLayout { + AppScaffold( + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colors.background), + timeText = { ResponsiveTimeText(timeSource = FixedTimeSource) }, + ) { + content() + } } } @@ -151,5 +157,19 @@ public abstract class WearScreenshotTest { } } } + + @Composable + public fun CorrectLayout( + content: @Composable () -> Unit, + ) { + // TODO why needed + val layoutDirection = when (LocalConfiguration.current.layoutDirection) { + RTL -> LayoutDirection.Rtl + else -> LayoutDirection.Ltr + } + CompositionLocalProvider(value = LocalLayoutDirection provides layoutDirection) { + content() + } + } } }