-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
8 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
library/src/test/java/com/telefonica/mistica/compose/title/TitleKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
library/src/test/java/com/telefonica/mistica/title/TitleViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DummyActivity>() | ||
|
||
@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() | ||
} | ||
} | ||
} |