-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add screenshot tests of the statistic screen
- Loading branch information
Showing
21 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
...p/src/test/kotlin/org/piepmeyer/gauguin/ui/statistics/StatisticsActivityScreenshotTest.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,147 @@ | ||
package org.piepmeyer.gauguin.ui.statistics | ||
|
||
import com.github.takahirom.roborazzi.captureRoboImage | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.experimental.categories.Category | ||
import org.junit.runner.RunWith | ||
import org.koin.core.KoinApplication | ||
import org.koin.core.component.inject | ||
import org.koin.core.context.stopKoin | ||
import org.koin.test.KoinTest | ||
import org.piepmeyer.gauguin.ScreenshotTest | ||
import org.piepmeyer.gauguin.ScreenshotTestUtils | ||
import org.piepmeyer.gauguin.creation.GridCreator | ||
import org.piepmeyer.gauguin.creation.RandomPossibleDigitsShuffler | ||
import org.piepmeyer.gauguin.creation.SeedRandomizerMock | ||
import org.piepmeyer.gauguin.grid.Grid | ||
import org.piepmeyer.gauguin.grid.GridSize | ||
import org.piepmeyer.gauguin.options.GameOptionsVariant | ||
import org.piepmeyer.gauguin.options.GameVariant | ||
import org.piepmeyer.gauguin.preferences.ApplicationPreferences | ||
import org.piepmeyer.gauguin.preferences.StatisticsManager | ||
import org.piepmeyer.gauguin.preferences.StatisticsManagerImpl | ||
import org.robolectric.ParameterizedRobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.annotation.GraphicsMode | ||
import sergio.sastre.uitesting.robolectric.activityscenario.robolectricActivityScenarioForActivityRule | ||
import sergio.sastre.uitesting.robolectric.config.screen.DeviceScreen | ||
import sergio.sastre.uitesting.robolectric.utils.activity.TestDataForActivity | ||
import sergio.sastre.uitesting.robolectric.utils.activity.TestDataForActivityCombinator | ||
import sergio.sastre.uitesting.utils.activityscenario.ActivityConfigItem | ||
import sergio.sastre.uitesting.utils.common.Orientation | ||
import sergio.sastre.uitesting.utils.common.UiMode | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
@Category(ScreenshotTest::class) | ||
@RunWith(ParameterizedRobolectricTestRunner::class) | ||
@GraphicsMode(GraphicsMode.Mode.NATIVE) | ||
class StatisticsActivityScreenshotTest( | ||
private val testItem: TestDataForActivity<UiStateEnum>, | ||
) : KoinTest { | ||
enum class UiStateEnum { | ||
NoStatistics, | ||
FilledStatistics, | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
@ParameterizedRobolectricTestRunner.Parameters | ||
fun testItemProvider(): Array<out TestDataForActivity<out Enum<*>>> = | ||
TestDataForActivityCombinator(uiStates = UiStateEnum.entries.toTypedArray()) | ||
.forDevices( | ||
DeviceScreen.Phone.NEXUS_ONE, | ||
DeviceScreen.Phone.SMALL_PHONE, | ||
DeviceScreen.Phone.PIXEL_4A, | ||
DeviceScreen.Tablet.MEDIUM_TABLET, | ||
DeviceScreen.Desktop.LARGE_DESKTOP, | ||
).forConfigs( | ||
ActivityConfigItem(uiMode = UiMode.DAY, orientation = Orientation.PORTRAIT), | ||
ActivityConfigItem(uiMode = UiMode.NIGHT, orientation = Orientation.LANDSCAPE), | ||
).combineAll() | ||
} | ||
|
||
@get:Rule | ||
val robolectricScreenshotRule = | ||
robolectricActivityScenarioForActivityRule<StatisticsActivity>( | ||
config = testItem.config, | ||
deviceScreen = testItem.device, | ||
) | ||
|
||
private val statisticsManager: StatisticsManager by inject() | ||
private val preferences: ApplicationPreferences by inject() | ||
|
||
@Before | ||
fun before() { | ||
KoinApplication.init() | ||
} | ||
|
||
@After | ||
fun after() { | ||
stopKoin() | ||
} | ||
|
||
@Config(sdk = [34]) // Do not use qualifiers if using `DeviceScreen` in the Rule | ||
@Test | ||
fun screenshotTest() { | ||
robolectricScreenshotRule.activityScenario.onActivity { | ||
preferences.clear() | ||
|
||
onActivityViaUiState() | ||
|
||
it.recreate() | ||
} | ||
|
||
robolectricScreenshotRule | ||
.rootView | ||
.captureRoboImage(ScreenshotTestUtils.filePath(this::class, testItem)) | ||
} | ||
|
||
private fun onActivityViaUiState() { | ||
when (testItem.uiState) { | ||
UiStateEnum.NoStatistics -> { | ||
} | ||
|
||
UiStateEnum.FilledStatistics -> { | ||
val gridOne = createGrid(0) | ||
val gridTwo = createGrid(1) | ||
val gridThree = createGrid(2) | ||
|
||
gridOne.playTime = 25.seconds | ||
gridTwo.playTime = 2.seconds | ||
gridThree.playTime = 90.seconds | ||
|
||
statisticsManager.puzzleStartedToBePlayed() | ||
statisticsManager.puzzleStartedToBePlayed() | ||
statisticsManager.puzzleStartedToBePlayed() | ||
|
||
statisticsManager.storeStreak(false) | ||
statisticsManager.storeStreak(true) | ||
statisticsManager.storeStreak(true) | ||
|
||
statisticsManager.puzzleSolved(gridOne) | ||
statisticsManager.puzzleSolved(gridTwo) | ||
statisticsManager.puzzleSolved(gridThree) | ||
|
||
statisticsManager.statistics().overall.gamesStarted = 3 | ||
|
||
val impl = statisticsManager as StatisticsManagerImpl | ||
impl.storeStreak(true) | ||
} | ||
} | ||
} | ||
|
||
private fun createGrid(seed: Int): Grid { | ||
val randomizer = SeedRandomizerMock(seed) | ||
|
||
val variant = GameVariant(GridSize(3, 3), GameOptionsVariant.createClassic()) | ||
|
||
return GridCreator( | ||
variant, | ||
randomizer, | ||
RandomPossibleDigitsShuffler(randomizer.random), | ||
).createRandomizedGridWithCages() | ||
} | ||
} |
Binary file added
BIN
+140 KB
...tatisticsActivityScreenshotTest_LARGE_DESKTOP_DAY_PORTRAIT_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.9 KB
...cs/StatisticsActivityScreenshotTest_LARGE_DESKTOP_DAY_PORTRAIT_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+121 KB
...isticsActivityScreenshotTest_LARGE_DESKTOP_NIGHT_LANDSCAPE_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.2 KB
...StatisticsActivityScreenshotTest_LARGE_DESKTOP_NIGHT_LANDSCAPE_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+217 KB
...tatisticsActivityScreenshotTest_MEDIUM_TABLET_DAY_PORTRAIT_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+81.8 KB
...cs/StatisticsActivityScreenshotTest_MEDIUM_TABLET_DAY_PORTRAIT_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+198 KB
...isticsActivityScreenshotTest_MEDIUM_TABLET_NIGHT_LANDSCAPE_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+69 KB
...StatisticsActivityScreenshotTest_MEDIUM_TABLET_NIGHT_LANDSCAPE_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.5 KB
...cs/StatisticsActivityScreenshotTest_NEXUS_ONE_DAY_PORTRAIT_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.9 KB
...istics/StatisticsActivityScreenshotTest_NEXUS_ONE_DAY_PORTRAIT_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+53.2 KB
...StatisticsActivityScreenshotTest_NEXUS_ONE_NIGHT_LANDSCAPE_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.4 KB
...ics/StatisticsActivityScreenshotTest_NEXUS_ONE_NIGHT_LANDSCAPE_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+158 KB
...ics/StatisticsActivityScreenshotTest_PIXEL_4A_DAY_PORTRAIT_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+98.9 KB
...tistics/StatisticsActivityScreenshotTest_PIXEL_4A_DAY_PORTRAIT_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+147 KB
.../StatisticsActivityScreenshotTest_PIXEL_4A_NIGHT_LANDSCAPE_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+77.7 KB
...tics/StatisticsActivityScreenshotTest_PIXEL_4A_NIGHT_LANDSCAPE_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.8 KB
.../StatisticsActivityScreenshotTest_SMALL_PHONE_DAY_PORTRAIT_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+60.6 KB
...tics/StatisticsActivityScreenshotTest_SMALL_PHONE_DAY_PORTRAIT_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+86.8 KB
...atisticsActivityScreenshotTest_SMALL_PHONE_NIGHT_LANDSCAPE_FilledStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49 KB
...s/StatisticsActivityScreenshotTest_SMALL_PHONE_NIGHT_LANDSCAPE_NoStatistics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.