-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add Designsystem ScreenshotTests
- Loading branch information
1 parent
1706e1e
commit a5ec97b
Showing
5 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...esignsystem/src/test/java/com/wei/picquest/core/designsystem/BackgroundScreenshotTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.wei.picquest.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.wei.picquest.core.designsystem.component.PqBackground | ||
import com.wei.picquest.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 atBackground_multipleThemes() { | ||
composeTestRule.captureMultiTheme("Background") { description -> | ||
PqBackground(Modifier.size(100.dp)) { | ||
Text("$description background") | ||
} | ||
} | ||
} | ||
} |
184 changes: 184 additions & 0 deletions
184
...esignsystem/src/test/java/com/wei/picquest/core/designsystem/NavigationScreenshotTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
package com.wei.picquest.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.wei.picquest.core.designsystem.component.PqNavigationBar | ||
import com.wei.picquest.core.designsystem.component.PqNavigationBarItem | ||
import com.wei.picquest.core.designsystem.component.PqNavigationDrawer | ||
import com.wei.picquest.core.designsystem.component.PqNavigationDrawerItem | ||
import com.wei.picquest.core.designsystem.component.PqNavigationRail | ||
import com.wei.picquest.core.designsystem.component.PqNavigationRailItem | ||
import com.wei.picquest.core.designsystem.icon.PqIcons | ||
import com.wei.picquest.core.designsystem.theme.PqTheme | ||
import com.wei.picquest.core.testing.util.DefaultRoborazziOptions | ||
import com.wei.picquest.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 navigationBar_multipleThemes() { | ||
composeTestRule.captureMultiTheme("NavigationBar") { | ||
Surface { | ||
PqNavigationBarExample() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun navigationBar_hugeFont() { | ||
composeTestRule.setContent { | ||
CompositionLocalProvider( | ||
LocalInspectionMode provides true, | ||
) { | ||
TestHarness(fontScale = 2f) { | ||
PqTheme { | ||
PqNavigationBarExample("Looong item") | ||
} | ||
} | ||
} | ||
} | ||
composeTestRule.onRoot() | ||
.captureRoboImage( | ||
"src/test/screenshots/NavigationBar" + | ||
"/NavigationBar_fontScale2.png", | ||
roborazziOptions = DefaultRoborazziOptions, | ||
) | ||
} | ||
|
||
@Test | ||
fun navigationRail_multipleThemes() { | ||
composeTestRule.captureMultiTheme("NavigationRail") { | ||
Surface { | ||
PqNavigationRailExample() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun navigationDrawer_multipleThemes() { | ||
composeTestRule.captureMultiTheme("NavigationDrawer") { | ||
Surface { | ||
PqNavigationDrawerExample() | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun navigationDrawer_hugeFont() { | ||
composeTestRule.setContent { | ||
CompositionLocalProvider( | ||
LocalInspectionMode provides true, | ||
) { | ||
TestHarness(fontScale = 2f) { | ||
PqTheme { | ||
PqNavigationDrawerExample("Loooooooooooooooong item") | ||
} | ||
} | ||
} | ||
} | ||
composeTestRule.onRoot() | ||
.captureRoboImage( | ||
"src/test/screenshots/NavigationDrawer" + | ||
"/NavigationDrawer_fontScale2.png", | ||
roborazziOptions = DefaultRoborazziOptions, | ||
) | ||
} | ||
|
||
@Composable | ||
private fun PqNavigationBarExample(label: String = "Item") { | ||
PqNavigationBar { | ||
(0..2).forEach { index -> | ||
PqNavigationBarItem( | ||
selected = index == 0, | ||
onClick = { }, | ||
icon = { | ||
Icon( | ||
imageVector = PqIcons.UpcomingBorder, | ||
contentDescription = "", | ||
) | ||
}, | ||
selectedIcon = { | ||
Icon( | ||
imageVector = PqIcons.Upcoming, | ||
contentDescription = "", | ||
) | ||
}, | ||
label = { Text(label) }, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PqNavigationRailExample() { | ||
PqNavigationRail { | ||
(0..2).forEach { index -> | ||
PqNavigationRailItem( | ||
selected = index == 0, | ||
onClick = { }, | ||
icon = { | ||
Icon( | ||
imageVector = PqIcons.UpcomingBorder, | ||
contentDescription = "", | ||
) | ||
}, | ||
selectedIcon = { | ||
Icon( | ||
imageVector = PqIcons.Upcoming, | ||
contentDescription = "", | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PqNavigationDrawerExample(label: String = "Item") { | ||
PqNavigationDrawer { | ||
(0..2).forEach { index -> | ||
PqNavigationDrawerItem( | ||
selected = index == 0, | ||
onClick = { }, | ||
icon = { | ||
Icon( | ||
imageVector = PqIcons.UpcomingBorder, | ||
contentDescription = "", | ||
) | ||
}, | ||
selectedIcon = { | ||
Icon( | ||
imageVector = PqIcons.Upcoming, | ||
contentDescription = "", | ||
) | ||
}, | ||
label = { Text(label) }, | ||
) | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
core/testing/src/main/java/com/wei/picquest/core/testing/util/MainDispatcherRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.wei.picquest.core.testing.util | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.rules.TestRule | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
|
||
/** | ||
* A JUnit [TestRule] that sets the Main dispatcher to [testDispatcher] | ||
* for the duration of the test. | ||
*/ | ||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class MainDispatcherRule( | ||
val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(), | ||
) : TestWatcher() { | ||
override fun starting(description: Description) { | ||
Dispatchers.setMain(testDispatcher) | ||
} | ||
|
||
override fun finished(description: Description) { | ||
Dispatchers.resetMain() | ||
} | ||
} |
Oops, something went wrong.