Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions compose/snippets/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.screenshot)
}

kotlin {
Expand All @@ -30,6 +31,7 @@ kotlin {
android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "com.example.compose.snippets"
experimentalProperties["android.experimental.enableScreenshotTest"] = true

defaultConfig {
applicationId = "com.example.compose.snippets"
Expand Down Expand Up @@ -181,4 +183,7 @@ dependencies {

androidTestImplementation(libs.androidx.glance.testing)
androidTestImplementation(libs.androidx.glance.appwidget.testing)

screenshotTestImplementation(libs.screenshot.validation.api)
screenshotTestImplementation(libs.androidx.ui.tooling)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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 com.example.compose.snippets.adaptivelayouts

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import org.junit.Rule
import org.junit.Test

class MyFeedTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need to change the github action so that the tests are run for every PR? otherwise people may not realize that a code change breaks the test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That makes sense to me. @kkuan2011 should we add a workflow file to this PR? That would allow us to check the workflow along with this test.


@get:Rule
val composeTestRule = createComposeRule()

@Test
Comment thread
kkuan2011 marked this conversation as resolved.
fun myFeed_displaysItems() {
val names = listOf("Alice", "Bob", "Charlie")

composeTestRule.setContent {
MyFeed(names = names)
}

// Verify that all names in the feed are displayed
for (name in names) {
composeTestRule.onNodeWithText(name).assertIsDisplayed()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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 com.example.compose.snippets.adaptivelayouts

import android.content.res.Configuration
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.tooling.preview.Wallpapers
import com.android.tools.screenshot.PreviewTest
import com.example.compose.snippets.adaptivelayouts.MyFeed

class SampleNamesProvider : PreviewParameterProvider<List<String>> {
override val values = sequenceOf(
listOf("User 1", "User 2", "User 3", "User 4", "User 5")
)
}

@PreviewTest
@Preview
@Composable
fun MyFeedPreview(
@PreviewParameter(SampleNamesProvider::class) names: List<String>,
) {
MyFeed(names)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026 The Android Open Source Project
*
* 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 com.example.compose.snippets.layouts.grid

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.android.tools.screenshot.PreviewTest


@Preview
@PreviewTest
@Composable
fun GridExamplePreviewTest() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to provide any input on what type of device to take the screenshots on?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That does make sense. Ideally we would take screenshots on:

  1. Phone (Pixel)
  2. Foldable (Pixel Fold)
  3. Tablet (Pixel Tablet OR Samsung Galaxy)
  4. Connected display (25" monitor)

GridExample()
}

@Preview
@PreviewTest
@Composable
fun SixCardsPreviewTest() {
SixCards()
}

@Preview
@PreviewTest
@Composable
fun DefineGridPreviewTest() {
DefineGrid()
}

@Preview
@PreviewTest
@Composable
fun DefineGridAndPlaceItemsPreviewTest() {
DefineGridAndPlaceItems()
}

@Preview
@PreviewTest
@Composable
fun DefineExplicitAndImplicitGridTracksPreviewTest() {
DefineExplicitAndImplicitGridTracks()
}
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.
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ android.enableR8.fullMode=true
# Use an AndroidX snapshot build.
# https://androidx.dev/snapshots/builds
# snapshotVersion=14793336

android.experimental.enableScreenshotTest=true
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ compose-remote = "1.0.0-alpha11"
glance-wear = "1.0.0-alpha10"
remote-material3 = "1.0.0-alpha04"
screenshotValidationApi = "0.0.1-alpha14"
screenshot = "0.0.1-alpha15"

[libraries]
accompanist-adaptive = "com.google.accompanist:accompanist-adaptive:0.37.3"
Expand Down Expand Up @@ -309,6 +310,7 @@ androidx-compose-remote-tooling-preview = { module = "androidx.compose.remote:re
glance-preview = { group = "androidx.glance", name = "glance-preview", version.ref = "androidx-glance-appwidget" }
glance-appwidget-preview = { group = "androidx.glance", name = "glance-appwidget-preview", version.ref = "androidx-glance-appwidget" }
screenshot-validation-api = { group = "com.android.tools.screenshot", name = "screenshot-validation-api", version.ref = "screenshotValidationApi" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can you put in alphabetical order?


[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
Expand All @@ -324,5 +326,6 @@ kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref =
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
screenshot = { id = "com.android.compose.screenshot", version.ref = "screenshot"}
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }
Loading