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 9 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
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ nullawayGradle = "2.1.0"
okhttp = "5.0.0-alpha.12"
okio = "3.9.1"
retrofit = "2.11.0"
roborazzi = "1.6.0"
slack-lint = "0.8.2"
sortDependencies = "0.7"
spotless = "7.0.0.BETA4"
sqldelight = "2.0.2"
versionsPlugin = "0.51.0"
wire = "5.1.0"
xmlutil = "0.90.2"
junit = "4.13.1"

[plugins]
bestPracticesPlugin = { id = "com.autonomousapps.plugin-best-practices-plugin", version = "0.10" }
Expand All @@ -68,6 +70,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 @@ -139,6 +142,7 @@ 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" }
Expand All @@ -147,4 +151,5 @@ slf4jNop = "org.slf4j:slf4j-nop:2.0.16"
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" }
xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" }
xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" }
kateliu20 marked this conversation as resolved.
Show resolved Hide resolved
junit-junit = { group = "junit", name = "junit", version.ref = "junit" }
14 changes: 14 additions & 0 deletions platforms/intellij/compose/playground/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* limitations under the License.
*/
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.kotlin.plugin.compose)
alias(libs.plugins.lint)
alias(libs.plugins.roborazzi)
}

kotlin {
Expand Down Expand Up @@ -47,6 +49,14 @@ kotlin {
implementation(projects.platforms.intellij.compose)
}
}
jvmTest {
dependencies {
implementation(libs.junit)
implementation(libs.roborazzi)
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 All @@ -56,3 +66,7 @@ configurations
.configureEach { attributes { attribute(KotlinPlatformType.attribute, KotlinPlatformType.jvm) } }

dependencies { lintChecks(libs.composeLints) }

tasks.withType<KotlinCompile>().configureEach {
compilerOptions { freeCompilerArgs.add("-Xcontext-receivers") }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a comment explaining why this is needed, and let's limit it to test JVM compilations.

tasks.named { it.name == "compileJvmTestKotlin" }...

Should be soooomething like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I need to register compileJvmTestKotlin task? It's not in the list of gradlew tasks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

the name might be slightly different, you'll want to find the task name for the task that compiles test jvm sources

Copy link
Collaborator

Choose a reason for hiding this comment

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

jvmTestClasses is not a type of KotlinCompile as far as I know. Do you see this actually being configured there? I looked and I'm think what you want is compileTestKotlinJvm, but if it works without adding this opt-in at all then we can omit it?

Copy link
Contributor Author

@kateliu20 kateliu20 Oct 30, 2024

Choose a reason for hiding this comment

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

I found the task compileTestKotlinJvm while running ./gradlew tasks --all , so I committed it here: e1ebfee. Is this the task we are looking for? I think it didn't show up when just running ./gradlew tasks

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, in general you are gonna be better off not relying on ./gradlew tasks vs just running a task you know will run it and adding --dry-run to the end, which will just print all the tasks it's gonna run. You can also look at a build scan to see task types.

}
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,11 +33,20 @@ 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 { AppContent() }
}

// created function for testing
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 a comment here for now since testing on the function wrapped in a singleWindowApplication seemed to result in an infinite loop (where the test wouldn't end). I made a composable AppContent() function with the same content and added a test tag too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need the comment, feels obvious in source why it's there :)

@Composable
fun AppContent() {
var isDark by remember { mutableStateOf(false) }
IntUiTheme(isDark) {
Column(Modifier.background(JewelTheme.globalColors.panelBackground)) {
DefaultButton(modifier = Modifier.padding(16.dp), onClick = { isDark = !isDark }) {
DefaultButton(
modifier = Modifier.padding(16.dp).testTag("dark-mode-toggle"),
ZacSweers marked this conversation as resolved.
Show resolved Hide resolved
onClick = { isDark = !isDark },
) {
Text("Toggle dark mode")
}
MarkdownContent { MARKDOWN }
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.RoborazziOptions
import io.github.takahirom.roborazzi.captureRoboImage
import kotlinx.coroutines.test.runTest
import org.junit.Test

class MarkdownPlaygroundKtTest {
kateliu20 marked this conversation as resolved.
Show resolved Hide resolved
@OptIn(ExperimentalTestApi::class)
@Test
fun test() = runTest {
runDesktopComposeUiTest {
setContent { AppContent() }

val roborazziOptions =
RoborazziOptions(
recordOptions = RoborazziOptions.RecordOptions(resizeScale = 0.5),
compareOptions = RoborazziOptions.CompareOptions(changeThreshold = 0F),
)

onRoot().captureRoboImage(roborazziOptions = roborazziOptions)

onNodeWithTag("dark-mode-toggle").performClick()

onRoot().captureRoboImage(roborazziOptions = roborazziOptions)
}
}
}
Loading