Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 25, 2025
1 parent 30ad154 commit 5d663d0
Show file tree
Hide file tree
Showing 33 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.piepmeyer.gauguin.ui.newgame

import kotlinx.coroutines.CoroutineScope
import org.piepmeyer.gauguin.calculation.GridPreviewCalculationService
import org.piepmeyer.gauguin.grid.Grid
import org.piepmeyer.gauguin.options.GameVariant

class GridPreviewCalculationServiceMock(
private val grid: Grid,
) : GridPreviewCalculationService() {
override fun calculateGrid(
variant: GameVariant,
scope: CoroutineScope,
) {
listeners.forEach {
it.previewGridCalculated(grid)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package org.piepmeyer.gauguin.ui.newgame
import com.github.takahirom.roborazzi.captureRoboImage
import com.google.android.material.tabs.TabLayout
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand All @@ -19,6 +21,8 @@ import org.piepmeyer.gauguin.R
import org.piepmeyer.gauguin.ScreenshotTest
import org.piepmeyer.gauguin.ScreenshotTestUtils
import org.piepmeyer.gauguin.Theme
import org.piepmeyer.gauguin.calculation.GridCalculationService
import org.piepmeyer.gauguin.calculation.GridPreviewCalculationService
import org.piepmeyer.gauguin.creation.GridCreator
import org.piepmeyer.gauguin.creation.RandomPossibleDigitsShuffler
import org.piepmeyer.gauguin.creation.SeedRandomizerMock
Expand All @@ -32,7 +36,6 @@ import org.piepmeyer.gauguin.options.GridCageOperation
import org.piepmeyer.gauguin.options.NumeralSystem
import org.piepmeyer.gauguin.options.SingleCageUsage
import org.piepmeyer.gauguin.preferences.ApplicationPreferences
import org.piepmeyer.gauguin.ui.grid.GridUI
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.GraphicsMode
Expand Down Expand Up @@ -101,11 +104,27 @@ class NewGameActivityScreenshotTest(
every { numeralSystem } returns NumeralSystem.Decimal
every { operations } returns GridCageOperation.OPERATIONS_ALL
every { singleCageUsage } returns SingleCageUsage.FIXED_NUMBER
every { gridWidth } returns 9
every { gridHeigth } returns 9
every { gameVariant } returns GameOptionsVariant.createClassic()
every { gridWidth } returns 6
every { gridHeigth } returns 6
every { squareOnlyGrid } returns true
every { gameOptionsVariant } returns GameOptionsVariant.createClassic()
}
} withOptions { binds(listOf(ApplicationPreferences::class)) }
/*single {
GridPreviewCalculationServiceMock(createDefaultGrid())
} withOptions { binds(listOf(GridPreviewCalculationService::class)) }*/
single {
mockk<GridPreviewCalculationService>(relaxed = true) {
every { takeCalculatedGrid(any()) } just runs
every { calculateGrid(any(), any()) } just runs
}
} withOptions { binds(listOf(GridPreviewCalculationService::class)) }
single {
mockk<GridCalculationService>(relaxed = true) {
every { hasCalculatedNextGrid(any()) } returns true
every { consumeNextGrid() } returns createDefaultGrid()
}
} withOptions { binds(listOf(GridCalculationService::class)) }
}
}

Expand All @@ -118,15 +137,15 @@ class NewGameActivityScreenshotTest(
@Test
fun screenshotTest() {
robolectricScreenshotRule.activityScenario.onActivity {
it.findViewById<GridUI>(R.id.newGridPreview).grid = createDefaultGrid()

val tabs = it.findViewById<TabLayout>(R.id.new_game_options_tablayout)

when (testItem.uiState) {
UiStateEnum.TabBasic -> tabs.selectTab(tabs.getTabAt(0))
UiStateEnum.TabNumbers -> tabs.selectTab(tabs.getTabAt(1))
UiStateEnum.TabAdvanced -> tabs.selectTab(tabs.getTabAt(2))
}

it.recreate()
}

robolectricScreenshotRule
Expand Down
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import java.util.WeakHashMap

private val logger = KotlinLogging.logger {}

class GridPreviewCalculationService(
open class GridPreviewCalculationService(
private val dispatcher: CoroutineDispatcher = Dispatchers.Default,
) {
private val grids: MutableMap<GameVariant, Grid> = WeakHashMap()
private var listeners = mutableListOf<GridPreviewListener>()
var listeners = mutableListOf<GridPreviewListener>()
private var lastVariant: GameVariant? = null
private var lastGridCalculation: Deferred<Grid>? = null

Expand All @@ -35,7 +35,7 @@ class GridPreviewCalculationService(
listeners.forEach { it.previewGridCreated(grid, false) }
}

fun calculateGrid(
open fun calculateGrid(
variant: GameVariant,
scope: CoroutineScope,
) {
Expand Down

0 comments on commit 5d663d0

Please sign in to comment.