Skip to content

Commit

Permalink
feat: screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas committed Oct 18, 2024
1 parent 3e6140b commit 2198fdb
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app/src/internalDebug/screenshotTests/** filter=lfs diff=lfs merge=lfs -text
99 changes: 99 additions & 0 deletions .github/workflows/generate-screenshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: "Generate and Verify Screenshot Tests"

on:
workflow_dispatch:
push:
branches:
- feat/screenshot-tests

permissions:
contents: write
pull-requests: write

env:
GITHUB_TOKEN: ${{ secrets.ANDROID_BOB_GH_TOKEN }}

jobs:
generate-screenshots:
runs-on: buildjet-8vcpu-ubuntu-2204

if: github.ref == 'refs/heads/feat/screenshot-tests'

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Set up JDK 17
uses: buildjet/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4

- name: Fetch All Branches
run: git fetch --all

- name: Merge Develop into screenshot-tests
run: |
git checkout screenshot-tests
git merge origin/develop --no-edit
git push origin screenshot-tests
- name: Verify Screenshot Tests
run: ./gradlew validateInternalDebugScreenshotTest

- name: Update Screenshot Reference Images
run: ./gradlew updateInternalDebugScreenshotTest

- name: Zip Screenshot Test Reports
run: |
zip -r screenshot-test-report.zip build/reports/screenshotTest/preview/debug/internal/*
- name: Upload Screenshot Test Report
uses: actions/upload-artifact@v4
with:
name: screenshot-test-report
path: screenshot-test-report.zip

- name: Create New Branch
run: |
BRANCH_NAME="test/screenshots-update-$(date +%Y%m%d%H%M%S)"
git checkout -b $BRANCH_NAME
git add .
git commit -m "test: update screenshot tests"
git push origin $BRANCH_NAME
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ env.GITHUB_TOKEN }}
branch: $BRANCH_NAME
base: screenshot-tests
title: "Update Screenshot Tests"
body: "Automated PR to update screenshot tests."

- name: Add Comment with Test Report Link
uses: actions/github-script@v6
with:
github-token: ${{ env.GITHUB_TOKEN }}
script: |
const prNumber = ${{ steps.create_pr.outputs.pull_request_number }};
const artifactUrl = `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts`;
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Screenshot test results have been generated. [Download the report](artifactUrl).`
});
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
11 changes: 11 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ plugins {
id(ScriptPlugins.testing)
id(libs.plugins.wire.kover.get().pluginId)
id(libs.plugins.wire.versionizer.get().pluginId)
alias(libs.plugins.screenshot)
}

repositories {
Expand Down Expand Up @@ -82,6 +83,13 @@ android {
jniLibs.pickFirsts.add("**/libsodium.so")
}
android.buildFeatures.buildConfig = true
experimentalProperties["android.experimental.enableScreenshotTest"] = true

testOptions {
screenshotTests {
imageDifferenceThreshold = 0.0001f // 0.01%
}
}

sourceSets {
allFlavors.forEach { flavor ->
Expand Down Expand Up @@ -240,6 +248,9 @@ dependencies {
implementation(libs.aboutLibraries.ui)
implementation(libs.compose.qr.code)

// screenshot testing
screenshotTestImplementation(libs.compose.ui.tooling)

// Unit/Android tests dependencies
testImplementation(libs.androidx.test.archCore)
testImplementation(libs.junit4) // Maybe migrate completely to Junit 5?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

@file:Suppress("TooManyFunctions")

package com.wire.android.ui.home.conversations.messages.item
package com.wire.android.kotlin.ui.home.conversations.messages.item

import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
Expand All @@ -27,6 +25,9 @@ import com.wire.android.media.audiomessage.AudioMediaPlayingState
import com.wire.android.media.audiomessage.AudioState
import com.wire.android.model.Clickable
import com.wire.android.ui.home.conversations.info.ConversationDetailsData
import com.wire.android.ui.home.conversations.messages.item.MessageClickActions
import com.wire.android.ui.home.conversations.messages.item.RegularMessageItem
import com.wire.android.ui.home.conversations.messages.item.SystemMessageItem
import com.wire.android.ui.home.conversations.mock.mockAssetAudioMessage
import com.wire.android.ui.home.conversations.mock.mockAssetMessage
import com.wire.android.ui.home.conversations.mock.mockFooter
Expand Down Expand Up @@ -336,15 +337,15 @@ fun PreviewMessageWithSystemMessage() {
SystemMessageItem(
mockMessageWithKnock.copy(
messageContent = UIMessageContent.SystemMessage.MissedCall.YouCalled(
UIText.DynamicString("You")
UIText.DynamicString("ME")
)
)
)
SystemMessageItem(
mockMessageWithKnock.copy(
messageContent = UIMessageContent.SystemMessage.MemberAdded(
UIText.DynamicString("You"),
listOf(UIText.DynamicString("Adam Smith"))
UIText.DynamicString("ME"),
listOf(UIText.DynamicString("John Smith"))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
*/
@file:Suppress("TooManyFunctions")

package com.wire.android.ui.home.conversations.messages.item
package com.wire.android.kotlin.ui.home.conversations.messages.item

import androidx.compose.runtime.Composable
import com.wire.android.ui.home.conversations.messages.item.SystemMessageItem
import com.wire.android.ui.home.conversations.mock.mockMessageWithKnock
import com.wire.android.ui.home.conversations.mock.mockUsersUITexts
import com.wire.android.ui.home.conversations.model.UIMessageContent
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ kotlin.code.style=official
# Support KMP Gradle Composite Builds - See https://youtrack.jetbrains.com/issue/KT-52172/
kotlin.mpp.import.enableKgpDependencyResolution=true
org.gradle.logging.level=QUIET
android.experimental.enableScreenshotTest=true
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ compose-compiler = "1.5.13"
compose-constraint = "1.0.1"
compose-navigation = "2.7.7" # adjusted to work with compose-destinations "1.9.54"
compose-destinations = "1.10.2"
screenshot = "0.0.1-alpha07"

# Hilt
hilt = "2.51.1"
Expand Down Expand Up @@ -115,6 +116,7 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
aboutLibraries = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "aboutLibraries" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
screenshot = { id = "com.android.compose.screenshot", version.ref = "screenshot"}

# Home-made convention plugins defined in build-logic
wire-android-application = { id = "com.wire.android.application" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pluginManagement {
includeBuild("build-logic")
repositories {
mavenCentral()
google()
}
}

Expand Down

0 comments on commit 2198fdb

Please sign in to comment.