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

Roborazzi Test for Markdown Playground #1064

Merged
merged 46 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4bc6b9e
Initial commit, add roborazzi dependencies
kateliu20 Oct 24, 2024
8f49433
First attempt at adding SlackRoborazziTest
kateliu20 Oct 24, 2024
9d10d3d
Add compose desktop roborazzi dependency
kateliu20 Oct 25, 2024
45ac073
Change roborazzi module and version
kateliu20 Oct 25, 2024
7217eeb
Change main function structure and write basic (but failing) roborazz…
kateliu20 Oct 25, 2024
b75371f
Add dependencies to jvmTest
kateliu20 Oct 28, 2024
0f9a04a
Modify MarkdownPlayground to have a composable app content for testing.
kateliu20 Oct 28, 2024
0a4b6e9
Add roborazzi test
kateliu20 Oct 28, 2024
376c598
Merge branch 'main' into kl/roborazzi_markdown_test
kateliu20 Oct 28, 2024
c3c167d
Add modifier to AppContent
kateliu20 Oct 28, 2024
d54a281
Merge branch 'kl/roborazzi_markdown_test' of github.com:slackhq/slack…
kateliu20 Oct 28, 2024
09db2b7
Run spotless
kateliu20 Oct 28, 2024
8f9b8ea
Rename test file
kateliu20 Oct 28, 2024
60903cf
Remove junit from libs.versions.toml and default changeThreshold opti…
kateliu20 Oct 28, 2024
3099434
Rename to MarkdownPlayground
kateliu20 Oct 28, 2024
3a0b3a7
Add robolectric and testing dependencies
kateliu20 Oct 29, 2024
eabadf3
specify roborazzi screenshots in folder
kateliu20 Oct 29, 2024
77a9e74
Add path to build
kateliu20 Oct 29, 2024
2869a46
Add comment
kateliu20 Oct 29, 2024
3b9057b
Add to git attributes and rename to snapshots
kateliu20 Oct 30, 2024
50c1b3e
Add yml and pre-receive check
kateliu20 Oct 30, 2024
fff72b9
Limit to compiling test jvm sources
kateliu20 Oct 30, 2024
e1ebfee
Add compileTestKotlinJVM
kateliu20 Oct 30, 2024
f32861a
Run spotless
kateliu20 Oct 30, 2024
7ded42a
Merge branch 'main' into kl/roborazzi_markdown_test
kateliu20 Oct 30, 2024
282ff2d
Clean up dependencies and remove rule comment
kateliu20 Oct 30, 2024
bda0d2e
Remove runTest and clean up build file
kateliu20 Oct 31, 2024
2194c68
Merge remote-tracking branch 'origin/kl/roborazzi_markdown_test' into…
kateliu20 Oct 31, 2024
a9f4566
Test workflow run
kateliu20 Oct 31, 2024
5699146
Modify record images folder
kateliu20 Oct 31, 2024
7a13dfd
Remove robolectric dependency
kateliu20 Oct 31, 2024
b7b18ff
Add validation task and rearrange tasks
kateliu20 Oct 31, 2024
4bcd716
Modify outputdir
kateliu20 Oct 31, 2024
0e4bb3b
Add snapshot image path
kateliu20 Oct 31, 2024
ab6ec98
Add kotlin test dependency
kateliu20 Oct 31, 2024
2e046f4
Try verifyRoborazziJvm
kateliu20 Oct 31, 2024
3974141
Try running compare
kateliu20 Oct 31, 2024
6eba561
remove specific directory and see if verify works.
kateliu20 Oct 31, 2024
48d5397
run without gradlew check
kateliu20 Oct 31, 2024
815e184
Add output
kateliu20 Nov 1, 2024
79d4622
Upgrade roborazzi for output dirs
kateliu20 Nov 7, 2024
b0a3161
upgrade roborazzi version
kateliu20 Nov 7, 2024
da67e7b
Merge branch 'main' into kl/roborazzi_markdown_test
kateliu20 Nov 7, 2024
a1895aa
Remove verifyRoborazzi check
kateliu20 Nov 7, 2024
992b80d
Clean up code and remove files
kateliu20 Nov 11, 2024
5bc98ea
Merge branch 'main' into kl/roborazzi_markdown_test
kateliu20 Nov 11, 2024
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
gradlew linguist-generated=true
gradlew.bat linguist-generated=true
config/bin/* filter=lfs diff=lfs merge=lfs -text
**/snapshots/**/*.png filter=lfs diff=lfs merge=lfs -text
kateliu20 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
kateliu20 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
ZacSweers marked this conversation as resolved.
Show resolved Hide resolved
with:
lfs: 'true'

- name: Check LFS files
uses: actionsdesk/[email protected]

- name: Export JDK version
shell: bash
Expand Down Expand Up @@ -54,6 +59,7 @@ jobs:
name: reports
path: |
**/build/reports/**
**/src/jvmTest/snapshots/**/*_compare.png
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

publish-snapshot:
name: 'Publish snapshot (main only)'
Expand Down
8 changes: 8 additions & 0 deletions config/git/hooks/pre-receive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# compares files that match .gitattributes filter to those actually tracked by git-lfs
diff <(git ls-files ':(attr:filter=lfs)' | sort) <(git lfs ls-files -n | sort) >/dev/null
kateliu20 marked this conversation as resolved.
Show resolved Hide resolved

ret=$?
if [[ $ret -ne 0 ]]; then
echo >&2 "This remote has detected files committed without using Git LFS. Run 'brew install git-lfs && git lfs install' to install it and re-commit your files.";
exit 1;
fi
9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jdk = "21"
jvmTarget = "17"
jewel = "0.26.2"
jna = "5.15.0"
junit = "4.13.1"
kaml = "0.62.2"
kotlin = "2.0.21"
kotlinx-serialization = "1.7.3"
Expand All @@ -38,6 +39,7 @@ nullawayGradle = "2.1.0"
okhttp = "5.0.0-alpha.12"
okio = "3.9.1"
retrofit = "2.11.0"
roborazzi = "1.30.1"
slack-lint = "0.8.2"
sortDependencies = "0.12"
spotless = "7.0.0.BETA4"
Expand Down Expand Up @@ -69,6 +71,7 @@ moshiGradlePlugin = { id = "dev.zacsweers.moshix", version.ref = "moshix" }
moshix = { id = "dev.zacsweers.moshix", version.ref = "moshix" }
pluginUploader = { id = "dev.bmac.intellij.plugin-uploader", version = "1.3.5" }
retry = { id = "org.gradle.test-retry", version.ref = "gradle-retry" }
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
sortDependencies = { id = "com.squareup.sort-dependencies", version.ref = "sortDependencies" }
versionsPlugin = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }
Expand Down Expand Up @@ -122,6 +125,7 @@ kotlin-gradlePlugins-bom = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin
kotlin-poet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoet" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinShell = "eu.jrie.jetbrains:kotlin-shell-core:0.2.1"
ktfmt = { module = "com.facebook:ktfmt", version.ref = "ktfmt" }
jewel-bridge = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge-242", version.ref = "jewel" }
Expand All @@ -143,11 +147,16 @@ okio-fakefilesystem = { module = "com.squareup.okio:okio-fakefilesystem", versio
oshi = "com.github.oshi:oshi-core:6.6.5"
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converters-wire = { module = "com.squareup.retrofit2:converter-wire", version.ref = "retrofit" }
roborazzi = { module = "io.github.takahirom.roborazzi:roborazzi-compose-desktop", version.ref = "roborazzi" }
rxjava = "io.reactivex.rxjava3:rxjava:3.1.9"
sarif4k = "io.github.detekt.sarif4k:sarif4k:0.6.0"
slackLints-checks = { module = "com.slack.lint:slack-lint-checks", version.ref = "slack-lint" }
slackLints-annotations = { module = "com.slack.lint:slack-lint-annotations", version.ref = "slack-lint" }
slf4jNop = "org.slf4j:slf4j-nop:2.0.16"
testing-roborazzi = { module = "io.github.takahirom.roborazzi:roborazzi", version.ref = "roborazzi" }
testing-roborazzi-rules = { module = "io.github.takahirom.roborazzi:roborazzi-junit-rule", version.ref = "roborazzi" }
testing-roborazzi-compose = { module = "io.github.takahirom.roborazzi:roborazzi-compose", version.ref = "roborazzi" }
testing-roborazzi-core = { module = "io.github.takahirom.roborazzi:roborazzi-core", version.ref = "roborazzi" }
tikxml-htmlEscape = { module = "com.tickaroo.tikxml:converter-htmlescape", version = "0.8.15" }
truth = "com.google.truth:truth:1.4.4"
xmlutil-core = { module = "io.github.pdvrieze.xmlutil:core", version.ref = "xmlutil" }
Expand Down
2 changes: 2 additions & 0 deletions platforms/intellij/compose/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ POM_ARTIFACT_ID=skate-compose
POM_NAME=Skate (Compose)
POM_DESCRIPTION=Skate (Compose)
INTELLIJ_PLUGIN=true
# Set the default path for Roborazzi record images
roborazzi.record.filePathStrategy=relativePathFromRoborazziContextOutputDirectory
ZacSweers marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions platforms/intellij/compose/playground/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ plugins {
alias(libs.plugins.compose)
alias(libs.plugins.kotlin.plugin.compose)
alias(libs.plugins.lint)
alias(libs.plugins.roborazzi)
}

roborazzi {
outputDir.set(
layout.projectDirectory.dir(
"src/jvmTest/kotlin/foundry/intellij/compose/playground/snapshots/images"
)
)
}

kotlin {
Expand Down Expand Up @@ -47,6 +56,19 @@ kotlin {
implementation(projects.platforms.intellij.compose)
}
}
jvmTest {
dependencies {
api(libs.testing.roborazzi.rules)

implementation(libs.kotlin.test)
implementation(libs.roborazzi)
implementation(libs.testing.roborazzi)
implementation(libs.testing.roborazzi.core)
implementation(libs.testing.roborazzi.compose)
implementation(compose.desktop.common)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added compose dependencies to the jvmTest. Before I added these dependencies, I had a java.lang.NoClassDefFoundError.

implementation(compose.desktop.uiTestJUnit4)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would this also be the correct compose desktop test dependency to add?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What does the sample in roborazzi use? Probably easiest to just match that to start

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems here they don't have dependencies in jvmTest, but they have these in the commonMain dependencies:

implementation(compose.runtime)
implementation(compose.desktop.currentOs)
implementation(project(":roborazzi-painter"))
implementation(libs.kotlin.stdlib.jdk8)
api libs.compose.ui.test.junit4.desktop
implementation libs.compose.ui.graphics.desktop

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's the library itself, we should look at one of their samples. I was eyeing this: https://github.com/takahirom/roborazzi/blob/main/sample-compose-desktop-jvm/build.gradle.kts

}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package foundry.intellij.compose.playground
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication
import foundry.intellij.compose.markdown.ui.MarkdownContent
Expand All @@ -31,18 +33,30 @@ import org.jetbrains.jewel.intui.standalone.theme.IntUiTheme
import org.jetbrains.jewel.ui.component.DefaultButton
import org.jetbrains.jewel.ui.component.Text

fun main() = singleWindowApplication {
fun main() {
singleWindowApplication { MarkdownPlayground() }
}
kateliu20 marked this conversation as resolved.
Show resolved Hide resolved

@Composable
fun MarkdownPlayground(modifier: Modifier = Modifier) {
var isDark by remember { mutableStateOf(false) }
IntUiTheme(isDark) {
Column(Modifier.background(JewelTheme.globalColors.panelBackground)) {
DefaultButton(modifier = Modifier.padding(16.dp), onClick = { isDark = !isDark }) {
Column(modifier.background(JewelTheme.globalColors.panelBackground)) {
DefaultButton(
modifier = Modifier.padding(16.dp).testTag(TestTags.DARK_MODE_TOGGLE),
onClick = { isDark = !isDark },
) {
Text("Toggle dark mode")
}
MarkdownContent { MARKDOWN }
}
}
}

object TestTags {
const val DARK_MODE_TOGGLE = "dark-mode-toggle"
}

private const val MARKDOWN =
"""
# Markdown Playground
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package foundry.intellij.compose.playground

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runDesktopComposeUiTest
import com.github.takahirom.roborazzi.DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH
import com.github.takahirom.roborazzi.ExperimentalRoborazziApi
import com.github.takahirom.roborazzi.RoborazziOptions
import io.github.takahirom.roborazzi.captureRoboImage
import kotlin.test.Test

class MarkdownPlaygroundTest {
@OptIn(ExperimentalTestApi::class, ExperimentalRoborazziApi::class)
@Test
fun snapshot() = runDesktopComposeUiTest {
setContent { MarkdownPlayground() }

val roborazziOptions =
RoborazziOptions(
recordOptions = RoborazziOptions.RecordOptions(resizeScale = 0.5),
compareOptions =
RoborazziOptions.CompareOptions(outputDirectoryPath = DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH),
)

onRoot().captureRoboImage(roborazziOptions = roborazziOptions)

onNodeWithTag(TestTags.DARK_MODE_TOGGLE).performClick()

onRoot().captureRoboImage(roborazziOptions = roborazziOptions)
}
}
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