Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANDROID-13796 Roborazzi screenshot tests #296

Merged
merged 83 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
303b648
POC roborazzi screenshot tests
jeprubio Aug 28, 2023
260a6ed
POC roborazzi set screenshot folder
jeprubio Sep 1, 2023
849960c
POC roborazzi using getScreenshotName() to get the screenshot file name
jeprubio Sep 4, 2023
595750e
POC roborazzi add compare_screenshots.yml
jeprubio Sep 4, 2023
53865e1
POC roborazzi updating failure report
jeprubio Sep 8, 2023
f97a966
Merge branch 'main' into poc/roborazzi
jeprubio Sep 8, 2023
9745034
POC roborazzi buttons test
jeprubio Sep 8, 2023
c050235
POC roborazzi update screenshots baseline
jeprubio Sep 8, 2023
4155351
POC roborazzi execute update_screenshot_baseline.yml on push
jeprubio Sep 8, 2023
db7ff60
Updated screenshots baseline
jeprubio Sep 8, 2023
8db018d
POC roborazzi update record screenshots baseline
jeprubio Sep 8, 2023
9734388
POC roborazzi runs on ubuntu-latest
jeprubio Sep 8, 2023
a84e7c4
Updated screenshots baseline
jeprubio Sep 8, 2023
0e92faa
POC roborazzi remove on push
jeprubio Sep 8, 2023
e1520b2
Merge remote-tracking branch 'origin/poc/roborazzi' into poc/roborazzi
jeprubio Sep 8, 2023
c0e890c
POC roborazzi upload to azure
jeprubio Sep 8, 2023
07ecb8f
POC roborazzi upload to azure if failure
jeprubio Sep 8, 2023
3e586c1
POC roborazzi updated upload to azure
jeprubio Sep 8, 2023
693f71c
POC roborazzi updated upload to azure
jeprubio Sep 8, 2023
434bb80
POC roborazzi force screenshots error
jeprubio Sep 8, 2023
99f2239
POC roborazzi add pngs of other directories
jeprubio Sep 8, 2023
f5114d3
POC roborazzi add pngs of other directories
jeprubio Sep 8, 2023
027f5bb
POC roborazzi revert brand names
jeprubio Sep 8, 2023
a13ee3a
POC roborazzi update baseline
jeprubio Sep 8, 2023
64ead38
POC roborazzi update baseline
jeprubio Sep 8, 2023
adffa31
POC roborazzi update baseline
jeprubio Sep 8, 2023
f04c8d3
POC roborazzi using Enclosed to run parametrized and not parametrized…
jeprubio Sep 11, 2023
026d865
POC roborazzi update screenshots
jeprubio Sep 11, 2023
3ad5a71
POC roborazzi update screenshots
jeprubio Sep 11, 2023
d6ed913
POC roborazzi update globs
jeprubio Sep 15, 2023
9573d41
POC roborazzi also upload artifact
jeprubio Sep 15, 2023
bc19b0c
POC roborazzi update job name
jeprubio Sep 15, 2023
b42a4af
POC roborazzi fix uppercase
jeprubio Sep 15, 2023
bc2df7b
POC roborazzi upload names
jeprubio Sep 15, 2023
5b73d35
POC roborazzi use pixel 5
jeprubio Sep 15, 2023
a363339
POC roborazzi update baseline on push
jeprubio Sep 15, 2023
84a264f
Updated screenshots baseline
jeprubio Sep 15, 2023
e1ab44c
POC roborazzi update device
jeprubio Sep 15, 2023
61bc591
POC roborazzi force error
jeprubio Sep 15, 2023
11ee4d8
POC roborazzi update device
jeprubio Sep 15, 2023
7e730f0
POC roborazzi force error
jeprubio Sep 15, 2023
07e60ae
POC roborazzi pixel 5 + 33% image size
jeprubio Sep 15, 2023
4d3342c
POC roborazzi add error on PasswordInput
jeprubio Sep 15, 2023
4d385b4
POC roborazzi change report image dimensions
jeprubio Sep 15, 2023
79b3ca2
POC roborazzi add image click
jeprubio Sep 15, 2023
349fcbc
POC roborazzi update compare_screenshots.yml AZURE_ACCOUNT_NAME
jeprubio Sep 18, 2023
e39ae82
POC roborazzi update setting GraphicsMode from build.gradle file
jeprubio Sep 18, 2023
af575ee
POC roborazzi classic views test
jeprubio Sep 22, 2023
f31a83e
POC roborazzi classic views in xmls
jeprubio Sep 22, 2023
92ce41f
POC roborazzi remove clicked from screenshot tests
jeprubio Sep 22, 2023
6da54d3
POC roborazzi update to 1.5.0
jeprubio Sep 22, 2023
b9cc05a
POC roborazzi add screenshots.md file
jeprubio Sep 25, 2023
fbbd271
POC roborazzi fix url
jeprubio Sep 25, 2023
ca6efc5
Merge branch 'poc/roborazzi-1.5.0' into poc/roborazzi
jeprubio Sep 25, 2023
d0488c6
Merge branch 'main' into poc/roborazzi
jeprubio Sep 26, 2023
c0daf65
POC roborazzi update screenshots.md
jeprubio Sep 26, 2023
83aeb97
Merge branch 'main' into poc/roborazzi
jeprubio Sep 28, 2023
e93c2da
POC roborazzi update test_dummy_activity.xml to the test package
jeprubio Sep 28, 2023
5528abd
POC roborazzi remove upload to github
jeprubio Sep 28, 2023
9d5c5fb
POC roborazzi update screenshots.md
jeprubio Sep 28, 2023
593539f
POC roborazzi extract roborazzi_version
jeprubio Sep 28, 2023
7599217
POC roborazzi update screenshots.md removing github artifacts from there
jeprubio Sep 28, 2023
da6d038
POC roborazzi update removing checks that are also done with the scre…
jeprubio Sep 28, 2023
8ef2191
POC roborazzi split ButtonKtTest
jeprubio Sep 28, 2023
626f9dc
POC roborazzi remove git status
jeprubio Sep 28, 2023
9fd7417
POC roborazzi add darkTheme screenshots
jeprubio Sep 28, 2023
363798d
ANDROID-13796 add ScreenshotsTest base class
jeprubio Oct 9, 2023
7a12e7c
ANDROID-13796 use ScreenshotsTest in classic view tests
jeprubio Oct 9, 2023
36b3aea
ANDROID-13796 update screenshots
jeprubio Oct 9, 2023
a19421e
ANDROID-13796 add compareScreenshot methods in ScreenshotsTest
jeprubio Oct 9, 2023
d193e19
ANDROID-13796 downgrade roborazzi to 1.4.0
jeprubio Oct 9, 2023
1f4193e
ANDROID-13796 restore checkout
jeprubio Oct 9, 2023
059380c
Merge branch 'main' into poc/roborazzi
jeprubio Oct 9, 2023
0e78b6e
ANDROID-13796 downgrade roborazzi to 1.4.0
jeprubio Oct 11, 2023
7fb6fc6
ANDROID-13796 add generate-html-report action
jeprubio Oct 11, 2023
e905f27
ANDROID-13796 add gradle/gradle-build-action
jeprubio Oct 11, 2023
7416b62
ANDROID-13796 removing the layout tests from library
jeprubio Oct 11, 2023
fdb6337
ANDROID-13796 add TextInputWithError test
jeprubio Oct 11, 2023
69e609f
ANDROID-13796 add TextInputDisabled test
jeprubio Oct 11, 2023
b217f04
ANDROID-13796 remove unneeded code
jeprubio Oct 13, 2023
af15dd0
ANDROID-13796 configure sdk version
jeprubio Oct 13, 2023
601dca0
ANDROID-13796 extract repeated code to private method
jeprubio Oct 13, 2023
c24fc2a
ANDROID-13796 add dark mode tests for classic views
jeprubio Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/generate-html-report/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: 'Generate HTML Report'
description: 'Generates HTML report from screenshots'
runs:
using: "composite"
steps:
- run: ${GITHUB_ACTION_PATH}/scripts/generate-html-report.sh
shell: bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

mkdir reports
touch reports/report.html
cp */screenshots/*_compare.png reports/
files=$(find . -type f -name "*_compare.png" | grep "reports/")
{
echo '<!doctype html>'
echo '<html>'
echo '<head>'
echo '<title>Screenshots failure report</title>'
echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" rel="stylesheet">'
echo '<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">'
echo '<meta charset="UTF-8">'
echo '</head>'
echo '<style>'
echo 'body {'
echo 'display: flex;'
echo 'min-height: 100vh;'
echo 'flex-direction: column;'
echo '}'
echo 'main {'
echo 'flex: 1 0 auto;'
echo '}'
echo '</style>'
echo '<body>'
echo '<nav>'
echo '<div class="nav-wrapper indigo darken-3">'
echo '<a href="#" class="brand-logo left">Screenshots failure report</a>'
echo '<ul id="nav-mobile" class="right hide-on-med-and-down">'
echo '<li><a href="https://github.com/takahirom/roborazzi">Roborazzi</a></li>'
echo '</ul>'
echo '</div>'
echo '</nav>'
echo '<main class="container">'
echo '<div class="section">'
echo '<table class="highlight responsive-table">'
echo '<tr><th>File name</th><th>Comparison</th></tr>'
} >> reports/report.html

for file in $files; do
# Get the file name and insert newlines every 100 characters
fileName=$(basename "$file" | sed -r 's/(.{100})/\1<br>/g')
echo "<tr><td>$(basename "$file")</td>" >> reports/report.html
echo "<td><a href=\"$(basename "$file")\"><img src=\"$(basename "$file")\" width=\"100%\" height=\"100%\" /></a></td></tr>" >> reports/report.html
done
{
echo '</table>'
echo '</div>'
echo '</main>'
echo '<footer class="page-footer indigo darken-3">'
echo '<div></div>'
echo '</footer>'
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>'
echo '</body></html>'
} >> reports/report.html

echo "Report: "
cat reports/report.html
49 changes: 49 additions & 0 deletions .github/workflows/compare_screenshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Compare Screenshots

on:
workflow_dispatch:
pull_request:

jobs:
CompareScreenshots:

runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Verify Screenshots (roborazzi)
run: 'bash ./gradlew verifyRoborazziDebug'
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done e905f27


- id: generate-html
name: Generate Html Report
if: failure()
uses: ./.github/actions/generate-html-report

- name: Generate screenshots tests reports tar.gz
if: failure()
run: |
tar cvzf mistica-screenshots-tests-report.tar.gz reports || echo "No screenshots tests reports found"
shell: bash

- name: Checkout Telefonica/github-actions repo
if: failure()
uses: actions/checkout@v3
with:
repository: Telefonica/github-actions
token: "${{ secrets.NOVUM_PRIVATE_REPOS }}"
path: .github/shared-actions

- name: Upload reports to azure
if: failure()
uses: ./.github/shared-actions/azure/upload-to-storage
with:
azure-account-name: ${{secrets.AZURE_ACCOUNT_NAME}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will obfuscate the url of the screenshots report. Could it be clear text?

Copy link
Contributor Author

@jeprubio jeprubio Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this is the cause we have urls in the reports with the *** as for example: https://***.blob.core.windows.net/ci-container-1696848766116/mistica-screenshots-tests-report.tar.gz
If this was in clear text that would not happen. However, my understanding is that we were asked from server core not to do that and use the secret in here, perhaps because this is a public repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, that's what we have secrets for

azure-account-key: ${{secrets.AZURE_ACCOUNT_KEY}}
globs: |
mistica-screenshots-tests-report.tar.gz
generate-summary: true
24 changes: 24 additions & 0 deletions .github/workflows/update_screenshot_baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Update screenshot baseline"
on:
workflow_dispatch:

jobs:
screenshots_baseline:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Run Roborazzi Record
run: 'bash ./gradlew clean recordRoborazziDebug'

- name: Check Git status
run: 'git status'
shell: bash
Comment on lines +15 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied from https://github.com/Telefonica/niji-for-home-android/blob/master/.github/workflows/run_acceptance_tests.yml as we thought this was necessary for the azure upload

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it justs prints git status info to the console, I would get rid of this here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, yup, then it makes sense, removed 626f9dc

Copy link
Contributor Author

@jeprubio jeprubio Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is removed the screenshots are not uploaded to azure and it prints:

Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/mistica-android/mistica-android/.github/shared-actions/azure/upload-to-storage'. Did you forget to run actions/checkout before running your local action?

Screenshot 2023-10-09 at 12 50 41

Copy link
Contributor Author

@jeprubio jeprubio Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once that actions/checkout is restored:

Screenshot 2023-10-09 at 12 53 05

Restored in 1f4193e


- name: Commit and push screenshots baseline
id: commitAndPushScreenshotsBaseline
uses: EndBug/add-and-commit@v7
with:
message: 'Updated screenshots baseline'
add: './**/screenshots/*'
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {
accompanist_version = "0.30.1"
coil_version = '2.2.2'
constraintComposeVersion = '1.0.1'
roborazzi_version = "1.4.0"
}
repositories {
google()
Expand All @@ -27,6 +28,7 @@ buildscript {
plugins {
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false
id "io.github.takahirom.roborazzi" version '1.4.0' apply false
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri May 19 13:07:06 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 18 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'maven-publish'
id 'io.github.takahirom.roborazzi'
}

android {
Expand Down Expand Up @@ -51,6 +52,15 @@ android {
sarifReport true
checkDependencies true
}

testOptions {
unitTests {
includeAndroidResources = true
all {
systemProperty 'robolectric.graphicsMode', 'NATIVE'
}
}
}
}

task sourceJar(type: Jar) {
Expand Down Expand Up @@ -88,7 +98,15 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
testImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
testImplementation 'androidx.compose.ui:ui-test-manifest:1.0.5'
testImplementation 'org.robolectric:robolectric:4.10.3'
testImplementation "io.github.takahirom.roborazzi:roborazzi:$roborazzi_version"
testImplementation "io.github.takahirom.roborazzi:roborazzi-compose:$roborazzi_version"
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
testImplementation "androidx.test:rules:1.5.0"
testImplementation "androidx.test:core-ktx:1.5.0"
testImplementation 'androidx.test.ext:junit-ktx:1.1.5'
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'

debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
}
Expand Down
Binary file added library/screenshots/check_TextInput.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added library/screenshots/check_TextInputDisabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added library/screenshots/check_TextInputWithError.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions library/src/test/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.telefonica.mistica"
>

<uses-permission android:name="android.permission.VIBRATE" />
pmartinbTEF marked this conversation as resolved.
Show resolved Hide resolved

<application>
<activity
android:name=".DummyActivity"
android:label="Text Input Activity"
android:exported="true"
android:theme="@style/MisticaTheme.Movistar">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
13 changes: 13 additions & 0 deletions library/src/test/java/com/telefonica/mistica/DummyActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.telefonica.mistica

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.telefonica.mistica.R

class DummyActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.test_dummy_activity)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.telefonica.mistica.compose.button

import androidx.compose.foundation.layout.padding
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.unit.dp
import com.telefonica.mistica.compose.theme.MisticaTheme
import com.telefonica.mistica.compose.theme.brand.MovistarBrand
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
internal class ButtonBehaviourTest {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun `check the button is clicked`() = test {
`given Button`()

`when the button is clicked`()

`then the onClickListener has been invoked`()
}

private fun TestScope.`given Button`() {
`when Button`()
}

private fun TestScope.`when Button`() {
composeTestRule.setContent {
MisticaTheme(brand = MovistarBrand) {
Button(
text = textValue,
onClickListener = onClickListener,
modifier = Modifier.padding(16.dp)
)
}
}
}

private fun TestScope.`when the button is clicked`() {
composeTestRule.onNodeWithText(textValue).performClick()
}

private fun TestScope.`then the onClickListener has been invoked`() {
assertTrue(clicked)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about using a mock instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work as well and it wouldn't be a big deal but I prefer not to use mock when it's not needed as in here and all the compose ui tests I've seen until now. As my understanding is that using a mock framework adds a little performance overhead. But I'm also not against using mocks in tests like this, I just prefer not using them if possible.

}

private fun test(block: TestScope.() -> Unit) {
TestScope().block()
}

private class TestScope {
val textValue = "textValue"
var clicked = false
val onClickListener: () -> Unit = { clicked = true }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.telefonica.mistica.compose.button

import androidx.compose.foundation.layout.padding
import androidx.compose.material.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.unit.dp
import com.telefonica.mistica.compose.theme.MisticaTheme
import com.telefonica.mistica.compose.theme.brand.BlauBrand
import com.telefonica.mistica.compose.theme.brand.Brand
import com.telefonica.mistica.compose.theme.brand.MovistarBrand
import com.telefonica.mistica.compose.theme.brand.O2Brand
import com.telefonica.mistica.compose.theme.brand.TelefonicaBrand
import com.telefonica.mistica.compose.theme.brand.VivoBrand
import com.telefonica.mistica.testutils.ScreenshotsTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner

@RunWith(ParameterizedRobolectricTestRunner::class)
internal class ButtonKtTest(private val brand: Brand, private val darkTheme: Boolean): ScreenshotsTest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ButtonKt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ButtonKtTest is the name android studio gives automatically to this test when done from the IDE, I can rename it to ButtonTest which is what I understand that you mean but then when navigating from the IDE with command + shift + T it won't find it anymore and will propose to create a new tests instead... so I think it's better that we can find that the class has tests and move quickly with the IDE than changing the name, wdyt?

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun `check the button screenshot`() {
`when Button`(brand, darkTheme)

`then screenshot is OK`(brand, darkTheme)
}

private fun `when Button`(brand: Brand = MovistarBrand, darkTheme: Boolean) {
composeTestRule.setContent {
MisticaTheme(brand = brand, darkTheme = darkTheme) {
Surface {
Button(
text = "textValue",
onClickListener = { },
modifier = Modifier.padding(16.dp)
)
}
}
}
}

private fun `then screenshot is OK`(brand: Brand, darkTheme: Boolean) {
compareScreenshot(composeTestRule.onRoot(), brand, darkTheme)
}

companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters(name = "Input: {0}")
fun brands() = listOf(
arrayOf(MovistarBrand, false),
arrayOf(VivoBrand, false),
arrayOf(O2Brand, false),
arrayOf(BlauBrand, false),
arrayOf(TelefonicaBrand, false),
arrayOf(MovistarBrand, true),
arrayOf(VivoBrand, true),
arrayOf(O2Brand, true),
arrayOf(BlauBrand, true),
arrayOf(TelefonicaBrand, true),
)
}
}
Loading
Loading