Adds screenshot tests to :core:designsystem (#931)
* WIP: Adds screenshot tests to :core:designsystem Change-Id: I0672845feba4064652dd8d60f07047b87864e121 * 🤖 Updates screenshots * Creates tests for more components and cleans up Change-Id: I61fe3ae6a4e8a41a599d520e16fc14aa6a643a22 * WIP: More cleanup and more combinations of themes Change-Id: I34312bc7d147b31f1c638cd505a9c241f8267523 * Added the rest of the screenshot tests for designsystem Change-Id: Ic427db5491910781c038882055524e3f3dbed194 * Some more cleanup Change-Id: I7384e55864719af9122ad9da8e50a09cb9a60180 * Spotless Change-Id: I22aa46e1f56b8b638c9d609ababbe49d471a26c6 * 🤖 Updates screenshots * ScreenshotHelper cleanup Change-Id: Ic94d41618e7850ab47f294d8022b405f18c843f0pull/950/head
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaBackground
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaGradientBackground
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class BackgroundScreenshotTests {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun niaBackground_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Background") { description ->
|
||||
NiaBackground(Modifier.size(100.dp)) {
|
||||
Text("$description background")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun niaGradientBackground_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Background", "GradientBackground") { description ->
|
||||
NiaGradientBackground(Modifier.size(100.dp)) {
|
||||
Text("$description background")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaButton
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaOutlinedButton
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class ButtonScreenshotTests {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun niaButton_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Button") { description ->
|
||||
Surface {
|
||||
NiaButton(onClick = {}, text = { Text("$description Button") })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun niaOutlineButton_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Button", "OutlineButton") { description ->
|
||||
Surface {
|
||||
NiaOutlinedButton(onClick = {}, text = { Text("$description OutlineButton") })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun niaButton_leadingIcon_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme(
|
||||
name = "Button",
|
||||
overrideFileName = "ButtonLeadingIcon",
|
||||
shouldCompareAndroidTheme = false,
|
||||
) { description ->
|
||||
Surface {
|
||||
NiaButton(
|
||||
onClick = {},
|
||||
text = { Text("$description Icon Button") },
|
||||
leadingIcon = { Icon(imageVector = NiaIcons.Add, contentDescription = null) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.google.accompanist.testharness.TestHarness
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaBackground
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaFilterChip
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class FilterChipScreenshotTests() {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun filterChip_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("FilterChip") { description ->
|
||||
Surface {
|
||||
NiaFilterChip(selected = false, onSelectedChange = {}) {
|
||||
Text("Unselected chip")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filterChip_multipleThemes_selected() {
|
||||
composeTestRule.captureMultiTheme("FilterChip", "FilterChipSelected") { description ->
|
||||
Surface {
|
||||
NiaFilterChip(selected = true, onSelectedChange = {}) {
|
||||
Text("Selected Chip")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filterChip_hugeFont() {
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(
|
||||
LocalInspectionMode provides true,
|
||||
) {
|
||||
TestHarness(fontScale = 2f, size = DpSize(80.dp, 40.dp)) {
|
||||
NiaTheme {
|
||||
NiaBackground {
|
||||
NiaFilterChip(selected = true, onSelectedChange = {}) {
|
||||
Text("Chip")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
composeTestRule.onRoot()
|
||||
.captureRoboImage(
|
||||
"src/test/screenshots/FilterChip/FilterChip_fontScale2.png",
|
||||
roborazziOptions = DefaultRoborazziOptions,
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaIconToggleButton
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class IconButtonScreenshotTests {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun iconButton_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("IconButton") { description ->
|
||||
NiaIconToggleExample(false)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun iconButton_unchecked_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("IconButton", "IconButtonUnchecked") { description ->
|
||||
Surface {
|
||||
NiaIconToggleExample(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NiaIconToggleExample(checked: Boolean) {
|
||||
NiaIconToggleButton(
|
||||
checked = checked,
|
||||
onCheckedChange = { },
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = NiaIcons.BookmarkBorder,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
checkedIcon = {
|
||||
Icon(
|
||||
imageVector = NiaIcons.Bookmark,
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaLoadingWheel
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaOverlayLoadingWheel
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class LoadingWheelScreenshotTests() {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun loadingWheel_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("LoadingWheel") {
|
||||
Surface {
|
||||
NiaLoadingWheel(contentDesc = "test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun overlayLoadingWheel_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("LoadingWheel", "OverlayLoadingWheel") {
|
||||
Surface {
|
||||
NiaOverlayLoadingWheel(contentDesc = "test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadingWheelAnimation() {
|
||||
composeTestRule.mainClock.autoAdvance = false
|
||||
composeTestRule.setContent {
|
||||
NiaTheme() {
|
||||
NiaLoadingWheel(contentDesc = "")
|
||||
}
|
||||
}
|
||||
// Try multiple frames of the animation; some arbitrary, some synchronized with duration.
|
||||
listOf(20L, 115L, 724L, 1000L).forEach { deltaTime ->
|
||||
composeTestRule.mainClock.advanceTimeBy(deltaTime)
|
||||
composeTestRule.onRoot()
|
||||
.captureRoboImage(
|
||||
"src/test/screenshots/LoadingWheel/LoadingWheel_animation_$deltaTime.png",
|
||||
roborazziOptions = DefaultRoborazziOptions,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.google.accompanist.testharness.TestHarness
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationBar
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaNavigationBarItem
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class NavigationScreenshotTests() {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun navigation_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Navigation") {
|
||||
Surface {
|
||||
NiaNavigationBarExample()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun navigation_hugeFont() {
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(
|
||||
LocalInspectionMode provides true,
|
||||
) {
|
||||
TestHarness(fontScale = 2f) {
|
||||
NiaTheme {
|
||||
NiaNavigationBarExample("Looong item")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
composeTestRule.onRoot()
|
||||
.captureRoboImage(
|
||||
"src/test/screenshots/Navigation" +
|
||||
"/Navigation_fontScale2.png",
|
||||
roborazziOptions = DefaultRoborazziOptions,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NiaNavigationBarExample(label: String = "Item") {
|
||||
NiaNavigationBar {
|
||||
(0..2).forEach { index ->
|
||||
NiaNavigationBarItem(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector = NiaIcons.UpcomingBorder,
|
||||
contentDescription = "",
|
||||
)
|
||||
},
|
||||
selectedIcon = {
|
||||
Icon(
|
||||
imageVector = NiaIcons.Upcoming,
|
||||
contentDescription = "",
|
||||
)
|
||||
},
|
||||
label = { Text(label) },
|
||||
selected = index == 0,
|
||||
onClick = { },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.google.accompanist.testharness.TestHarness
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTab
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTabRow
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class TabsScreenshotTests() {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun tabs_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Tabs") {
|
||||
NiaTabsExample()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tabs_hugeFont() {
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(
|
||||
LocalInspectionMode provides true,
|
||||
) {
|
||||
TestHarness(fontScale = 2f) {
|
||||
NiaTheme {
|
||||
NiaTabsExample("Looooong item")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
composeTestRule.onRoot()
|
||||
.captureRoboImage(
|
||||
"src/test/screenshots/Tabs/Tabs_fontScale2.png",
|
||||
roborazziOptions = DefaultRoborazziOptions,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NiaTabsExample(label: String = "Topics") {
|
||||
Surface {
|
||||
val titles = listOf(label, "People")
|
||||
NiaTabRow(selectedTabIndex = 0) {
|
||||
titles.forEachIndexed { index, title ->
|
||||
NiaTab(
|
||||
selected = index == 0,
|
||||
onClick = { },
|
||||
text = { Text(text = title) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.google.accompanist.testharness.TestHarness
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTopicTag
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class TagScreenshotTests() {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun Tag_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("Tag") {
|
||||
NiaTopicTag(followed = true, onClick = {}) {
|
||||
Text("TOPIC")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tag_hugeFont() {
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(
|
||||
LocalInspectionMode provides true,
|
||||
) {
|
||||
TestHarness(fontScale = 2f) {
|
||||
NiaTheme {
|
||||
NiaTopicTag(followed = true, onClick = {}) {
|
||||
Text("LOOOOONG TOPIC")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
composeTestRule.onRoot()
|
||||
.captureRoboImage(
|
||||
"src/test/screenshots/Tag/Tag_fontScale2.png",
|
||||
roborazziOptions = DefaultRoborazziOptions,
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2023 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.google.samples.apps.nowinandroid.core.designsystem
|
||||
|
||||
import android.R.string
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import com.google.accompanist.testharness.TestHarness
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.component.NiaTopAppBar
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.icon.NiaIcons
|
||||
import com.google.samples.apps.nowinandroid.core.designsystem.theme.NiaTheme
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.DefaultRoborazziOptions
|
||||
import com.google.samples.apps.nowinandroid.core.testing.util.captureMultiTheme
|
||||
import dagger.hilt.android.testing.HiltTestApplication
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
import org.robolectric.annotation.LooperMode
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(application = HiltTestApplication::class, sdk = [33], qualifiers = "480dpi")
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class TopAppBarScreenshotTests() {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||
|
||||
@Test
|
||||
fun topAppBar_multipleThemes() {
|
||||
composeTestRule.captureMultiTheme("TopAppBar") {
|
||||
NiaTopAppBarExample()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topAppBar_hugeFont() {
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(
|
||||
LocalInspectionMode provides true,
|
||||
) {
|
||||
TestHarness(fontScale = 2f) {
|
||||
NiaTheme {
|
||||
NiaTopAppBarExample()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
composeTestRule.onRoot()
|
||||
.captureRoboImage(
|
||||
"src/test/screenshots/TopAppBar/TopAppBar_fontScale2.png",
|
||||
roborazziOptions = DefaultRoborazziOptions,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NiaTopAppBarExample() {
|
||||
NiaTopAppBar(
|
||||
titleRes = android.R.string.untitled,
|
||||
navigationIcon = NiaIcons.Search,
|
||||
navigationIconContentDescription = "Navigation icon",
|
||||
actionIcon = NiaIcons.MoreVert,
|
||||
actionIconContentDescription = "Action icon",
|
||||
)
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 442 B |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 442 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 5.4 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 527 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 811 B |
After Width: | Height: | Size: 290 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.7 KiB |