Skip to content

Commit

Permalink
DartsGameScreen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Apr 10, 2024
1 parent b09f707 commit c23f354
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/test/kotlin/dartzee/screen/game/TestDartsGameScreen.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package dartzee.screen.game

import com.github.alyssaburlton.swingtest.findChild
import com.github.alyssaburlton.swingtest.getChild
import dartzee.achievements.x01.AchievementX01BestGame
import dartzee.clickButton
import dartzee.core.helper.verifyNotCalled
import dartzee.helper.AbstractTest
import dartzee.helper.insertGame
import dartzee.screen.ScreenCache
import dartzee.utils.InjectedThings
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
import java.awt.Frame

class TestDartsGameScreen : AbstractTest() {
@Test
Expand Down Expand Up @@ -37,4 +46,36 @@ class TestDartsGameScreen : AbstractTest() {
scrn.achievementUnlocked("foo", "bar", achievement)
verify { scrn.gamePanel.achievementUnlocked("bar", achievement) }
}

@Test
fun `Should maximise and show the tutorial if in party mode, and not start a new game`() {
InjectedThings.partyMode = true

val game = insertGame()
val scrn = DartsGameScreen(game, listOf(makeSingleParticipant()))
scrn.gamePanel = mockk(relaxed = true)
scrn.findChild<DartsGamePanel<*, *>>() shouldBe null
scrn.findChild<TutorialPanel>() shouldNotBe null
scrn.extendedState shouldBe Frame.MAXIMIZED_BOTH

scrn.startNewGame()
verifyNotCalled { scrn.gamePanel.startNewGame(any()) }
}

@Test
fun `Should start the game when tutorial ready button is pressed`() {
InjectedThings.partyMode = true

val participants = listOf(makeSingleParticipant())

val game = insertGame()
val scrn = DartsGameScreen(game, participants)
scrn.gamePanel = mockk(relaxed = true)

scrn.getChild<TutorialPanel>().clickButton(text = "I'm ready - let's play!")
verify { scrn.gamePanel.startNewGame(participants) }

scrn.findChild<TutorialPanel>().shouldBeNull()
scrn.findChild<DartsGamePanel<*, *>>().shouldNotBeNull()
}
}

0 comments on commit c23f354

Please sign in to comment.