Skip to content

Commit

Permalink
Improve RTL Tests (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Jun 7, 2024
1 parent 42294b7 commit 4b36637
Show file tree
Hide file tree
Showing 36 changed files with 436 additions and 372 deletions.
6 changes: 6 additions & 0 deletions compose-material/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
debug {
isPseudoLocalesEnabled = true
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand Down
21 changes: 21 additions & 0 deletions compose-material/src/debug/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2024 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 xmlns:tools="http://schemas.android.com/tools">
<string name="primary_label" tools:ignore="MissingTranslation">Primary label</string>
<string name="secondary_label" tools:ignore="MissingTranslation">Secondary label</string>
<string name="title" tools:ignore="MissingTranslation">Title</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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 = { },
)
}
}

Expand All @@ -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 = { },
)
}
}

Expand All @@ -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,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,14 +36,15 @@ 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() {

@Test
fun default() {
runComponentTest {
Chip(
label = "Primary label",
label = stringResource(com.google.android.horologist.compose.material.R.string.primary_label),
onClick = { },
)
}
Expand All @@ -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),
)
}
}
Expand All @@ -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(),
)
Expand All @@ -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,
Expand All @@ -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(),
)
}
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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(),
)
Expand All @@ -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),
)
Expand All @@ -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,
Expand All @@ -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(),
)
Expand All @@ -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,
Expand All @@ -266,26 +268,25 @@ 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(),
)
}
}

@Test
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(),
)
Expand All @@ -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(),
)
Expand All @@ -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),
Expand All @@ -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,
)
Expand Down
Loading

0 comments on commit 4b36637

Please sign in to comment.