-
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.
- Loading branch information
1 parent
d4dbef6
commit fd64578
Showing
7 changed files
with
271 additions
and
25 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
127 changes: 127 additions & 0 deletions
127
library/src/test/java/com/telefonica/mistica/button/ButtonTest.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,127 @@ | ||
package com.telefonica.mistica.button | ||
|
||
import android.content.Intent | ||
import android.widget.FrameLayout | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.espresso.Espresso | ||
import androidx.test.espresso.matcher.ViewMatchers | ||
import androidx.test.ext.junit.rules.activityScenarioRule | ||
import com.telefonica.mistica.DummyActivity | ||
import com.telefonica.mistica.DummyActivity.Companion.EXTRA_THEME | ||
import com.telefonica.mistica.R | ||
import com.telefonica.mistica.compose.button.ButtonStyle | ||
import com.telefonica.mistica.compose.theme.brand.Brand | ||
import com.telefonica.mistica.compose.theme.brand.MovistarBrand | ||
import com.telefonica.mistica.compose.theme.brand.VivoBrand | ||
import com.telefonica.mistica.testutils.ScreenshotsTest | ||
import com.telefonica.mistica.testutils.TestUtils.getAllBrands | ||
import com.telefonica.mistica.testutils.TestUtils.getAllButtonStyles | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.ParameterizedRobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(ParameterizedRobolectricTestRunner::class) | ||
internal class ButtonTest( | ||
private val brand: Brand, | ||
private val style: ButtonStyle, | ||
private val icon: Boolean, | ||
): ScreenshotsTest() { | ||
|
||
private val intent = Intent(ApplicationProvider.getApplicationContext(), DummyActivity::class.java).apply { | ||
this.putExtra(EXTRA_THEME, brand.getBaseThemeForBrand()) | ||
} | ||
|
||
@get:Rule | ||
val rule = activityScenarioRule<DummyActivity>(intent) | ||
|
||
@Test | ||
fun `check Xml Button`() { | ||
checkXmlButton(brand, style, icon, false) | ||
} | ||
|
||
@Config(qualifiers = "+night") | ||
@Test | ||
fun `check Xml Button dark`() { | ||
checkXmlButton(brand, style, icon, true) | ||
} | ||
private fun checkXmlButton(brand: Brand = MovistarBrand, style: ButtonStyle, icon: Boolean, darkTheme: Boolean) { | ||
rule.scenario.onActivity { activity -> | ||
val wrapper: FrameLayout = activity.findViewById(R.id.dummy_activity_wrapper) | ||
val button = Button(activity, null, style.getButtonStyleRef()) | ||
button.text = "textValue" | ||
var iconSuffix: String? = null | ||
if(icon) { | ||
button.setIconResource(android.R.drawable.ic_lock_power_off) | ||
iconSuffix = "icon" | ||
} | ||
wrapper.removeAllViews() | ||
wrapper.addView(button) | ||
|
||
compareScreenshot( | ||
Espresso.onView(ViewMatchers.withId(R.id.dummy_activity_wrapper)), | ||
component = "XMLButton", | ||
style = style.toString(), | ||
brand = brand, | ||
darkTheme = darkTheme, | ||
extra = iconSuffix | ||
) | ||
} | ||
} | ||
|
||
fun getStyleResFromButtonStyle(style: ButtonStyle) = when(style) { | ||
ButtonStyle.PRIMARY -> R.style.AppTheme_Button_DefaultButton | ||
ButtonStyle.PRIMARY_SMALL -> R.style.AppTheme_Button_DefaultButton_Small | ||
ButtonStyle.SECONDARY -> R.style.AppTheme_Button_SecondaryButton | ||
ButtonStyle.SECONDARY_SMALL -> R.style.AppTheme_Button_SecondaryButton_Small | ||
ButtonStyle.DANGER -> R.style.AppTheme_Button_DangerButton | ||
ButtonStyle.DANGER_SMALL -> R.style.AppTheme_Button_DangerButton_Small | ||
ButtonStyle.LINK -> R.style.AppTheme_Button_LinkButton | ||
ButtonStyle.PRIMARY_INVERSE -> R.style.AppTheme_Button_PrimaryButtonInverse | ||
ButtonStyle.PRIMARY_SMALL_INVERSE -> R.style.AppTheme_Button_PrimaryButtonInverse_Small | ||
ButtonStyle.SECONDARY_INVERSE -> R.style.AppTheme_Button_SecondaryButtonInverse | ||
ButtonStyle.SECONDARY_SMALL_INVERSE -> R.style.AppTheme_Button_SecondaryButtonInverse_Small | ||
ButtonStyle.LINK_INVERSE -> R.style.AppTheme_Button_LinkButtonInverse | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
@ParameterizedRobolectricTestRunner.Parameters(name = "ButtonXML {1} {0} icon={2}") | ||
fun brands(): List<Array<Any>> { | ||
val allBrands = getAllBrands() | ||
val buttonStyles = getAllButtonStyles() | ||
val icons = listOf(false, true) | ||
return allBrands.flatMap { brand -> | ||
buttonStyles.flatMap { buttonStyle -> | ||
icons.map { hasIcon -> | ||
arrayOf(brand, buttonStyle, hasIcon) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Brand.getBaseThemeForBrand() = when(this) { | ||
MovistarBrand -> R.style.MisticaTheme_Movistar_test | ||
VivoBrand -> R.style.MisticaTheme_Vivo_test | ||
VivoBrand -> R.style.MisticaTheme_O2_test | ||
VivoBrand -> R.style.MisticaTheme_Blau_test | ||
else -> R.style.MisticaTheme_Telefonica_test | ||
|
||
} | ||
fun ButtonStyle.getButtonStyleRef() = when(this) { | ||
ButtonStyle.PRIMARY -> R.attr.defaultButtonTest_test | ||
ButtonStyle.PRIMARY_SMALL -> R.attr.defaultButton_Small_test | ||
ButtonStyle.SECONDARY -> R.attr.secondaryButton_test | ||
ButtonStyle.SECONDARY_SMALL -> R.attr.secondaryButton_Small_test | ||
ButtonStyle.DANGER -> R.attr.dangerButton_test | ||
ButtonStyle.DANGER_SMALL -> R.attr.dangerButton_Small_test | ||
ButtonStyle.LINK -> R.attr.linkButton_test | ||
ButtonStyle.PRIMARY_INVERSE -> R.attr.primaryButtonInverse_test | ||
ButtonStyle.PRIMARY_SMALL_INVERSE -> R.attr.primaryButtonInverse_Small_test | ||
ButtonStyle.SECONDARY_INVERSE -> R.attr.secondaryButtonInverse_test | ||
ButtonStyle.SECONDARY_SMALL_INVERSE -> R.attr.secondaryButtonInverse_Small_test | ||
ButtonStyle.LINK_INVERSE -> R.attr.linkButtonInverse_test | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<attr name="defaultButtonTest_test" format="reference"/> | ||
<attr name="defaultButton_Small_test" format="reference"/> | ||
<attr name="secondaryButton_test" format="reference"/> | ||
<attr name="secondaryButton_Small_test" format="reference"/> | ||
<attr name="dangerButton_test" format="reference"/> | ||
<attr name="dangerButton_Small_test" format="reference"/> | ||
<attr name="linkButton_test" format="reference"/> | ||
<attr name="primaryButtonInverse_test" format="reference"/> | ||
<attr name="primaryButtonInverse_Small_test" format="reference"/> | ||
<attr name="secondaryButtonInverse_test" format="reference"/> | ||
<attr name="secondaryButtonInverse_Small_test" format="reference"/> | ||
<attr name="linkButtonInverse_test" format="reference"/> | ||
|
||
<style name="MisticaTheme.Blau.test" parent="MisticaTheme.Blau"> | ||
<item name="defaultButtonTest_test">@style/AppTheme.Button.DefaultButton</item> | ||
<item name="defaultButton_Small_test">@style/AppTheme.Button.DefaultButton.Small</item> | ||
<item name="secondaryButton_test">@style/AppTheme.Button.SecondaryButton</item> | ||
<item name="secondaryButton_Small_test">@style/AppTheme.Button.SecondaryButton.Small</item> | ||
<item name="dangerButton_test">@style/AppTheme.Button.DangerButton</item> | ||
<item name="dangerButton_Small_test">@style/AppTheme.Button.DangerButton.Small</item> | ||
<item name="linkButton_test">@style/AppTheme.Button.LinkButton</item> | ||
<item name="primaryButtonInverse_test">@style/AppTheme.Button.PrimaryButtonInverse</item> | ||
<item name="primaryButtonInverse_Small_test">@style/AppTheme.Button.PrimaryButtonInverse.Small</item> | ||
<item name="secondaryButtonInverse_test">@style/AppTheme.Button.SecondaryButtonInverse</item> | ||
<item name="secondaryButtonInverse_Small_test">@style/AppTheme.Button.SecondaryButtonInverse.Small</item> | ||
<item name="linkButtonInverse_test">@style/AppTheme.Button.LinkButtonInverse</item> | ||
</style> | ||
|
||
<style name="MisticaTheme.Movistar.test" parent="MisticaTheme.Movistar"> | ||
<item name="defaultButtonTest_test">@style/AppTheme.Button.DefaultButton</item> | ||
<item name="defaultButton_Small_test">@style/AppTheme.Button.DefaultButton.Small</item> | ||
<item name="secondaryButton_test">@style/AppTheme.Button.SecondaryButton</item> | ||
<item name="secondaryButton_Small_test">@style/AppTheme.Button.SecondaryButton.Small</item> | ||
<item name="dangerButton_test">@style/AppTheme.Button.DangerButton</item> | ||
<item name="dangerButton_Small_test">@style/AppTheme.Button.DangerButton.Small</item> | ||
<item name="linkButton_test">@style/AppTheme.Button.LinkButton</item> | ||
<item name="primaryButtonInverse_test">@style/AppTheme.Button.PrimaryButtonInverse</item> | ||
<item name="primaryButtonInverse_Small_test">@style/AppTheme.Button.PrimaryButtonInverse.Small</item> | ||
<item name="secondaryButtonInverse_test">@style/AppTheme.Button.SecondaryButtonInverse</item> | ||
<item name="secondaryButtonInverse_Small_test">@style/AppTheme.Button.SecondaryButtonInverse.Small</item> | ||
<item name="linkButtonInverse_test">@style/AppTheme.Button.LinkButtonInverse</item> | ||
</style> | ||
|
||
<style name="MisticaTheme.O2.test" parent="MisticaTheme.O2"> | ||
<item name="defaultButtonTest_test">@style/AppTheme.Button.DefaultButton</item> | ||
<item name="defaultButton_Small_test">@style/AppTheme.Button.DefaultButton.Small</item> | ||
<item name="secondaryButton_test">@style/AppTheme.Button.SecondaryButton</item> | ||
<item name="secondaryButton_Small_test">@style/AppTheme.Button.SecondaryButton.Small</item> | ||
<item name="dangerButton_test">@style/AppTheme.Button.DangerButton</item> | ||
<item name="dangerButton_Small_test">@style/AppTheme.Button.DangerButton.Small</item> | ||
<item name="linkButton_test">@style/AppTheme.Button.LinkButton</item> | ||
<item name="primaryButtonInverse_test">@style/AppTheme.Button.PrimaryButtonInverse</item> | ||
<item name="primaryButtonInverse_Small_test">@style/AppTheme.Button.PrimaryButtonInverse.Small</item> | ||
<item name="secondaryButtonInverse_test">@style/AppTheme.Button.SecondaryButtonInverse</item> | ||
<item name="secondaryButtonInverse_Small_test">@style/AppTheme.Button.SecondaryButtonInverse.Small</item> | ||
<item name="linkButtonInverse_test">@style/AppTheme.Button.LinkButtonInverse</item> | ||
</style> | ||
|
||
<style name="MisticaTheme.Telefonica.test" parent="MisticaTheme.Telefonica"> | ||
<item name="defaultButtonTest_test">@style/AppTheme.Button.DefaultButton</item> | ||
<item name="defaultButton_Small_test">@style/AppTheme.Button.DefaultButton.Small</item> | ||
<item name="secondaryButton_test">@style/AppTheme.Button.SecondaryButton</item> | ||
<item name="secondaryButton_Small_test">@style/AppTheme.Button.SecondaryButton.Small</item> | ||
<item name="dangerButton_test">@style/AppTheme.Button.DangerButton</item> | ||
<item name="dangerButton_Small_test">@style/AppTheme.Button.DangerButton.Small</item> | ||
<item name="linkButton_test">@style/AppTheme.Button.LinkButton</item> | ||
<item name="primaryButtonInverse_test">@style/AppTheme.Button.PrimaryButtonInverse</item> | ||
<item name="primaryButtonInverse_Small_test">@style/AppTheme.Button.PrimaryButtonInverse.Small</item> | ||
<item name="secondaryButtonInverse_test">@style/AppTheme.Button.SecondaryButtonInverse</item> | ||
<item name="secondaryButtonInverse_Small_test">@style/AppTheme.Button.SecondaryButtonInverse.Small</item> | ||
<item name="linkButtonInverse_test">@style/AppTheme.Button.LinkButtonInverse</item> | ||
</style> | ||
|
||
<style name="MisticaTheme.Vivo.test" parent="MisticaTheme.Vivo"> | ||
<item name="defaultButtonTest_test">@style/AppTheme.Button.DefaultButton</item> | ||
<item name="defaultButton_Small_test">@style/AppTheme.Button.DefaultButton.Small</item> | ||
<item name="secondaryButton_test">@style/AppTheme.Button.SecondaryButton</item> | ||
<item name="secondaryButton_Small_test">@style/AppTheme.Button.SecondaryButton.Small</item> | ||
<item name="dangerButton_test">@style/AppTheme.Button.DangerButton</item> | ||
<item name="dangerButton_Small_test">@style/AppTheme.Button.DangerButton.Small</item> | ||
<item name="linkButton_test">@style/AppTheme.Button.LinkButton</item> | ||
<item name="primaryButtonInverse_test">@style/AppTheme.Button.PrimaryButtonInverse</item> | ||
<item name="primaryButtonInverse_Small_test">@style/AppTheme.Button.PrimaryButtonInverse.Small</item> | ||
<item name="secondaryButtonInverse_test">@style/AppTheme.Button.SecondaryButtonInverse</item> | ||
<item name="secondaryButtonInverse_Small_test">@style/AppTheme.Button.SecondaryButtonInverse.Small</item> | ||
<item name="linkButtonInverse_test">@style/AppTheme.Button.LinkButtonInverse</item> | ||
</style> | ||
|
||
<style name="MisticaTheme.VivoNew.test" parent="MisticaTheme.VivoNew"> | ||
<item name="defaultButtonTest_test">@style/AppTheme.Button.DefaultButton</item> | ||
<item name="defaultButton_Small_test">@style/AppTheme.Button.DefaultButton.Small</item> | ||
<item name="secondaryButton_test">@style/AppTheme.Button.SecondaryButton</item> | ||
<item name="secondaryButton_Small_test">@style/AppTheme.Button.SecondaryButton.Small</item> | ||
<item name="dangerButton_test">@style/AppTheme.Button.DangerButton</item> | ||
<item name="dangerButton_Small_test">@style/AppTheme.Button.DangerButton.Small</item> | ||
<item name="linkButton_test">@style/AppTheme.Button.LinkButton</item> | ||
<item name="primaryButtonInverse_test">@style/AppTheme.Button.PrimaryButtonInverse</item> | ||
<item name="primaryButtonInverse_Small_test">@style/AppTheme.Button.PrimaryButtonInverse.Small</item> | ||
<item name="secondaryButtonInverse_test">@style/AppTheme.Button.SecondaryButtonInverse</item> | ||
<item name="secondaryButtonInverse_Small_test">@style/AppTheme.Button.SecondaryButtonInverse.Small</item> | ||
<item name="linkButtonInverse_test">@style/AppTheme.Button.LinkButtonInverse</item> | ||
</style> | ||
|
||
|
||
</resources> |