Skip to content

Commit 52556b7

Browse files
committed
enable Paparazzi for the renderer module
1 parent ae4aae9 commit 52556b7

13 files changed

+145
-2
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
*.properties text
1111
*.xml text
1212
*.yml text
13+
14+
**/snapshots/**/*.png filter=lfs diff=lfs merge=lfs -text

.github/workflows/build.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ jobs:
122122
steps:
123123
- name: Checkout code
124124
uses: actions/checkout@v4
125+
with:
126+
lfs: 'true'
125127
- name: Setup Java JDK
126128
uses: actions/setup-java@v4
127129
with:
@@ -142,7 +144,7 @@ jobs:
142144
key: ${{ runner.os }}-maven-${{ github.sha }}
143145
restore-keys: ${{ runner.os }}-maven-
144146
- name: Run Android Unit Tests
145-
run: ./gradlew test koverXmlReportRelease --scan --no-build-cache
147+
run: ./gradlew test verifyPaparazzi koverXmlReport --scan --no-build-cache
146148
- name: Codecov
147149
uses: codecov/codecov-action@v5
148150
with:
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "Validate Git LFS"
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
validate-lfs-pointers:
11+
name: "Validate Git LFS pointers"
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- run: git lfs fsck --pointers
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Record Snapshots
2+
3+
on:
4+
workflow_dispatch:
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref }}
8+
cancel-in-progress: true
9+
10+
jobs:
11+
record_snapshots:
12+
name: Record Snapshots
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
lfs: 'true'
20+
- name: Setup Java JDK
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: "temurin"
24+
java-version-file: ".java-version"
25+
- name: Setup Gradle
26+
uses: gradle/actions/setup-gradle@v4
27+
- name: Cache Konan
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.konan
31+
key: ${{ runner.os }}-konan-${{ github.sha }}
32+
restore-keys: ${{ runner.os }}-konan-
33+
- name: Cache Maven
34+
uses: actions/cache@v4
35+
with:
36+
path: ~/.m2/repository
37+
key: ${{ runner.os }}-maven-${{ github.sha }}
38+
restore-keys: |
39+
${{ runner.os }}-maven-
40+
- name: Record snapshots
41+
run: ./gradlew cleanRecordPaparazzi --scan
42+
- name: Commit snapshots
43+
run: |
44+
git config --global user.name '${{ github.actor }}'
45+
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
46+
git add .
47+
git commit -am "Record updated snapshots" || echo "No changed snapshots"
48+
git push

gradle/libs.versions.toml

+1
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ grgit = { id = "org.ajoberstar.grgit", version = "5.3.0" }
6161
ksp = { id = "com.google.devtools.ksp", version = "2.1.20-2.0.1" }
6262
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle" }
6363
npm-publish = { id = "dev.petuska.npm.publish", version.ref = "npmPublish" }
64+
paparazzi = { id = "app.cash.paparazzi", version = "2.0.0-alpha01" }

module/parser/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ kotlin {
2626
implementation(kotlin("stdlib"))
2727
implementation(libs.kotlin.coroutines.core)
2828

29+
api(libs.gtoSupport.fluidsonic.locale)
2930
implementation(libs.androidx.annotation)
3031
implementation(libs.colormath)
3132
implementation(libs.fluidLocale)
32-
implementation(libs.gtoSupport.fluidsonic.locale)
3333
implementation(libs.kermit)
3434
implementation(libs.kustomExport)
3535
implementation(libs.kustomExport.coroutines)

module/renderer/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id("godtools-shared.module-conventions")
33
alias(libs.plugins.compose)
44
alias(libs.plugins.compose.compiler)
5+
alias(libs.plugins.paparazzi)
56
}
67

78
android {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.cru.godtools.shared.renderer
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.ColumnScope
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.graphics.Color
9+
import app.cash.paparazzi.Paparazzi
10+
import com.android.ide.common.rendering.api.SessionParams.RenderingMode
11+
import org.junit.Rule
12+
13+
abstract class BasePaparazziTest(renderingMode: RenderingMode = RenderingMode.NORMAL) {
14+
@get:Rule
15+
val paparazzi = Paparazzi(
16+
renderingMode = renderingMode,
17+
maxPercentDifference = 0.001,
18+
)
19+
20+
protected fun contentSnapshot(content: @Composable ColumnScope.() -> Unit) {
21+
paparazzi.snapshot {
22+
Column(modifier = Modifier.background(Color.White), content = content)
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.cru.godtools.shared.renderer.content
2+
3+
import com.android.ide.common.rendering.api.SessionParams.RenderingMode
4+
import kotlin.test.Test
5+
import org.cru.godtools.shared.renderer.BasePaparazziTest
6+
import org.cru.godtools.shared.tool.parser.model.Text
7+
8+
class RenderTextPaparazziTest : BasePaparazziTest(renderingMode = RenderingMode.SHRINK) {
9+
@Test
10+
fun `RenderText() - Simple`() = contentSnapshot {
11+
RenderText(Text(text = "Simple Text"))
12+
}
13+
14+
@Test
15+
fun `RenderText() - Styles`() = contentSnapshot {
16+
RenderText(Text(text = "Italic Text", textStyles = setOf(Text.Style.ITALIC)))
17+
RenderText(Text(text = "Underline Text", textStyles = setOf(Text.Style.UNDERLINE)))
18+
RenderText(Text(text = "Italic Underline Text", textStyles = setOf(Text.Style.ITALIC, Text.Style.UNDERLINE)))
19+
}
20+
21+
@Test
22+
fun `RenderText() - Font Weight`() = contentSnapshot {
23+
RenderText(Text(text = "Font Weight 100", fontWeight = 100))
24+
RenderText(Text(text = "Font Weight 200", fontWeight = 200))
25+
RenderText(Text(text = "Font Weight 300", fontWeight = 300))
26+
RenderText(Text(text = "Font Weight 400", fontWeight = 400))
27+
RenderText(Text(text = "Font Weight 500", fontWeight = 500))
28+
RenderText(Text(text = "Font Weight 600", fontWeight = 600))
29+
RenderText(Text(text = "Font Weight 700", fontWeight = 700))
30+
RenderText(Text(text = "Font Weight 800", fontWeight = 800))
31+
RenderText(Text(text = "Font Weight 900", fontWeight = 900))
32+
RenderText(Text(text = "Font Weight 1000", fontWeight = 1000))
33+
}
34+
}

module/renderer/src/commonMain/kotlin/org/cru/godtools/shared/renderer/content/RenderText.kt

+6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ package org.cru.godtools.shared.renderer.content
33
import androidx.compose.material3.Text
44
import androidx.compose.runtime.Composable
55
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.text.font.FontStyle
7+
import androidx.compose.ui.text.font.FontWeight
8+
import androidx.compose.ui.text.style.TextDecoration
69
import org.cru.godtools.shared.tool.parser.model.Text
710

811
@Composable
912
internal fun RenderText(text: Text, modifier: Modifier = Modifier) {
1013
Text(
1114
text.text,
15+
fontWeight = text.fontWeight?.let { FontWeight(it) },
16+
fontStyle = FontStyle.Italic.takeIf { Text.Style.ITALIC in text.textStyles },
17+
textDecoration = TextDecoration.Underline.takeIf { Text.Style.UNDERLINE in text.textStyles },
1218
modifier = modifier
1319
)
1420
}

0 commit comments

Comments
 (0)