From 69ba5f59a8aa58d508faa86054a7f48e6bd397d4 Mon Sep 17 00:00:00 2001 From: Jose Rubio Date: Fri, 26 Apr 2024 13:54:49 +0200 Subject: [PATCH] ANDROID-14597 title view heading (#350) * ANDROID-14597 add isTitleHeading to TitleView * ANDROID-14597 add isTitleHeading to Title * ANDROID-14597 add some title headings in catalog * ANDROID-14597 add BindingMethods for databinding * ANDROID-14597 fix typo --- .../catalog/ui/compose/components/Titles.kt | 2 + catalog/src/main/res/layout/title_catalog.xml | 2 + .../telefonica/mistica/compose/title/Title.kt | 10 ++++ .../telefonica/mistica/list/ListRowView.kt | 5 ++ .../com/telefonica/mistica/title/TitleView.kt | 21 +++++++ .../src/main/res/values/attrs_components.xml | 1 + .../mistica/compose/title/TitleKtTest.kt | 56 +++++++++++++++++++ .../telefonica/mistica/title/TitleViewTest.kt | 54 ++++++++++++++++++ 8 files changed, 151 insertions(+) create mode 100644 library/src/test/java/com/telefonica/mistica/compose/title/TitleKtTest.kt create mode 100644 library/src/test/java/com/telefonica/mistica/title/TitleViewTest.kt diff --git a/catalog/src/main/java/com/telefonica/mistica/catalog/ui/compose/components/Titles.kt b/catalog/src/main/java/com/telefonica/mistica/catalog/ui/compose/components/Titles.kt index 2e1d2cf36..1d745ed52 100644 --- a/catalog/src/main/java/com/telefonica/mistica/catalog/ui/compose/components/Titles.kt +++ b/catalog/src/main/java/com/telefonica/mistica/catalog/ui/compose/components/Titles.kt @@ -32,6 +32,7 @@ private fun DefaultTitles() { Title( modifier = Modifier.padding(bottom = 8.dp), text = "Short default title", + isTitleHeading = true, ) Title( modifier = Modifier.padding(bottom = 8.dp), @@ -59,6 +60,7 @@ private fun TitlesWithStyleOverridden( modifier = Modifier.padding(bottom = 8.dp), style = style, text = "Short title $style", + isTitleHeading = true, ) Title( modifier = Modifier.padding(bottom = 8.dp), diff --git a/catalog/src/main/res/layout/title_catalog.xml b/catalog/src/main/res/layout/title_catalog.xml index 5674a87f5..49e3b3101 100644 --- a/catalog/src/main/res/layout/title_catalog.xml +++ b/catalog/src/main/res/layout/title_catalog.xml @@ -18,6 +18,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" + app:isTitleHeading="true" app:title="Short default Title" /> + diff --git a/library/src/test/java/com/telefonica/mistica/compose/title/TitleKtTest.kt b/library/src/test/java/com/telefonica/mistica/compose/title/TitleKtTest.kt new file mode 100644 index 000000000..0b13ad5e9 --- /dev/null +++ b/library/src/test/java/com/telefonica/mistica/compose/title/TitleKtTest.kt @@ -0,0 +1,56 @@ +package com.telefonica.mistica.compose.title + +import androidx.compose.ui.test.assert +import androidx.compose.ui.test.isHeading +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import com.telefonica.mistica.compose.theme.MisticaTheme +import com.telefonica.mistica.compose.theme.brand.MovistarBrand +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +@RunWith(RobolectricTestRunner::class) +internal class TitleKtTest { + @get:Rule + val composeTestRule = createComposeRule() + + @Test + fun `check the title is not set with accessibility heading by default`() = test { + `given Title`() + + composeTestRule.onNodeWithText(textValue).assert(!isHeading()) + } + + @Test + fun `check the title is set with accessibility heading when isHeading is set`() = test { + `given Title`(isHeading = true) + + composeTestRule.onNodeWithText(textValue).assert(isHeading()) + } + + private fun TestScope.`given Title`(isHeading: Boolean = false) { + `when Title`(isHeading) + } + + private fun TestScope.`when Title`(isHeading: Boolean = false) { + composeTestRule.setContent { + MisticaTheme(brand = MovistarBrand) { + Title( + text = textValue, + isTitleHeading = isHeading + ) + } + } + } + + private fun test(block: TestScope.() -> Unit) { + TestScope().block() + } + + private class TestScope { + val textValue = "textValue" + } + +} \ No newline at end of file diff --git a/library/src/test/java/com/telefonica/mistica/title/TitleViewTest.kt b/library/src/test/java/com/telefonica/mistica/title/TitleViewTest.kt new file mode 100644 index 000000000..065df6767 --- /dev/null +++ b/library/src/test/java/com/telefonica/mistica/title/TitleViewTest.kt @@ -0,0 +1,54 @@ +package com.telefonica.mistica.title + +import android.widget.FrameLayout +import androidx.test.ext.junit.rules.activityScenarioRule +import com.telefonica.mistica.DummyActivity +import com.telefonica.mistica.R +import com.telefonica.mistica.testutils.ScreenshotsTest +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +internal class TitleViewTest: ScreenshotsTest() { + @get:Rule + val rule = activityScenarioRule() + + @Test + fun `check TitleView has accessibility heading when setTitleHeading is invoked`() { + checkTitleView { + setTitle("Title") + setTitleHeading() + + assertTrue(this.getTitleTextView().isAccessibilityHeading) + } + } + + @Test + fun `check TitleView has NOT accessibility heading when setTitleHeading is not invoked`() { + checkTitleView { + setTitle("Title") + + assertFalse(this.getTitleTextView().isAccessibilityHeading) + } + } + + @Config(qualifiers = "+night") + @Test + fun `check TextInput dark`() { + checkTitleView() + } + + private fun checkTitleView(onTitleView: TitleView.() -> Unit = {}) { + rule.scenario.onActivity { activity -> + val wrapper: FrameLayout = activity.findViewById(R.id.dummy_activity_wrapper) + val titleView = TitleView(activity) + wrapper.addView(titleView) + titleView.onTitleView() + } + } +}