Skip to content

Commit

Permalink
fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Apr 21, 2024
1 parent b2d50c3 commit 9ab702f
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class SimplePlayerSelectionScreen : EmbeddedScreen() {

val textPane =
makeTransparentTextPane().apply {
// editorKit = HTMLEditorKit()
alignCentrally()
setFontSize(18)
border = EmptyBorder(0, 0, 25, 0)
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/dartzee/screen/game/DartsGameScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class DartsGameScreen(game: GameEntity, private val participants: List<IWrappedP
if (!InjectedThings.partyMode) {
gamePanel.startNewGame(participants)
} else {
contentPane.remove(gamePanel)
contentPane.removeAll()
contentPane.add(tutorialPanel)
repaint()
}
}

fun tutorialFinished() {
contentPane.remove(tutorialPanel)
contentPane.removeAll()
contentPane.add(gamePanel)
repaint()

Expand Down
18 changes: 18 additions & 0 deletions src/test/kotlin/dartzee/bean/TestScrollTablePlayers.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package dartzee.bean

import com.github.alyssaburlton.swingtest.shouldMatchImage
import dartzee.core.bean.ScrollTable
import dartzee.db.PlayerEntity
import dartzee.helper.AbstractTest
import dartzee.helper.insertPlayer
import dartzee.toLabel
import dartzee.utils.InjectedThings
import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.shouldBe
import javax.swing.ImageIcon
import javax.swing.ListSelectionModel
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

class TestScrollTablePlayers : AbstractTest() {
Expand All @@ -30,6 +35,19 @@ class TestScrollTablePlayers : AbstractTest() {
table.getValueAt(1, 1) shouldBe robot
}

@Test
@Tag("screenshot")
fun `Should render with player avatars in party mode`() {
InjectedThings.partyMode = true

val table = ScrollTable()
val bob = insertPlayer(name = "Bob")
table.initPlayerTableModel(listOf(bob))

val icon = table.getValueAt(0, 0) as ImageIcon
icon.toLabel().shouldMatchImage("tableAvatar")
}

@Test
fun `Should return all players correctly`() {
val table = ScrollTable()
Expand Down
7 changes: 2 additions & 5 deletions src/test/kotlin/dartzee/e2e/TestPartyModeE2E.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.github.alyssaburlton.swingtest.shouldBeVisible
import dartzee.bean.GameSetupPlayerSelector
import dartzee.bean.ScrollTableDartsGame
import dartzee.clickButton
import dartzee.db.PlayerEntity.Companion.ICON_HUMAN
import dartzee.drtDoubleTwenty
import dartzee.drtInnerFourteen
import dartzee.drtInnerOne
Expand Down Expand Up @@ -88,10 +87,8 @@ class TestPartyModeE2E : AbstractE2ETest() {
val leaderboardTable = app.getChild<ScrollTableDartsGame>()
leaderboardTable
.getRows()
.shouldContainExactly(
arrayOf(1, ICON_HUMAN, "Alice", 1L, 12),
arrayOf(2, ICON_HUMAN, "Bob", 1L, 14)
)
.map { it.filterIndexed { index: Int, _ -> index != 1 } }
.shouldContainExactly(arrayOf(1, "Alice", 1L, 12), arrayOf(2, "Bob", 1L, 14))
}

private fun launchApp(): DartsApp {
Expand Down
5 changes: 3 additions & 2 deletions src/test/kotlin/dartzee/screen/game/TestDartsGameScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class TestDartsGameScreen : AbstractTest() {
val game = insertGame()
val scrn = DartsGameScreen(game, listOf(makeSingleParticipant()))
scrn.gamePanel = mockk(relaxed = true)
scrn.startNewGame()

scrn.findChild<DartsGamePanel<*, *>>() shouldBe null
scrn.findChild<TutorialPanel>() shouldNotBe null

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

Expand All @@ -69,6 +69,7 @@ class TestDartsGameScreen : AbstractTest() {
val game = insertGame()
val scrn = DartsGameScreen(game, participants)
scrn.gamePanel = mockk(relaxed = true)
scrn.startNewGame()

scrn.getChild<TutorialPanel>().clickButton(text = "I'm ready - let's play!")
verify { scrn.gamePanel.startNewGame(participants) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package dartzee.screen.stats.overall
import com.github.alyssaburlton.swingtest.clickChild
import com.github.alyssaburlton.swingtest.findChild
import com.github.alyssaburlton.swingtest.getChild
import com.github.alyssaburlton.swingtest.shouldMatchImage
import dartzee.bean.GameParamFilterPanel
import dartzee.bean.GameParamFilterPanelRoundTheClock
import dartzee.bean.GameParamFilterPanelX01
import dartzee.bean.PlayerTypeFilterPanel
import dartzee.bean.SpinnerX01
import dartzee.core.bean.ScrollTable
import dartzee.db.PlayerEntity
import dartzee.game.ClockType
import dartzee.game.FinishType
import dartzee.game.GameType
Expand All @@ -17,30 +19,36 @@ import dartzee.game.X01Config
import dartzee.helper.AbstractTest
import dartzee.helper.insertFinishedParticipant
import dartzee.helper.insertFinishedTeam
import dartzee.helper.insertPlayerImage
import dartzee.preferences.Preferences
import dartzee.toLabel
import dartzee.utils.InjectedThings
import dartzee.utils.InjectedThings.preferenceService
import io.kotest.matchers.shouldBe
import javax.swing.ImageIcon
import javax.swing.JCheckBox
import javax.swing.JRadioButton
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

class TestLeaderboardTotalScore : AbstractTest() {
@Test
fun `should extract the right data into rows`() {
val gAlice = insertFinishedParticipant("Alice", GameType.X01, 50)
val gBob = insertFinishedParticipant("Bob", GameType.X01, 35)
val gAlice = insertFinishedParticipant("Alice", GameType.X01, 50, ai = true)
val gBob = insertFinishedParticipant("Bob", GameType.X01, 35, ai = false)
val gTeam = insertFinishedTeam("Clive", "Daisy", GameType.X01, 52)

val leaderboard = LeaderboardTotalScore(GameType.X01)
leaderboard.buildTable()
leaderboard.rowCount() shouldBe 3

leaderboard.getNameAt(0) shouldBe "Bob"
leaderboard.getIconAt(0) shouldBe PlayerEntity.ICON_HUMAN
leaderboard.getScoreAt(0) shouldBe 35
leaderboard.getGameIdAt(0) shouldBe gBob.localId

leaderboard.getNameAt(1) shouldBe "Alice"
leaderboard.getIconAt(1) shouldBe PlayerEntity.ICON_AI
leaderboard.getScoreAt(1) shouldBe 50
leaderboard.getGameIdAt(1) shouldBe gAlice.localId

Expand All @@ -49,6 +57,35 @@ class TestLeaderboardTotalScore : AbstractTest() {
leaderboard.getGameIdAt(2) shouldBe gTeam.localId
}

@Test
@Tag("screenshot")
fun `Should display avatars in party mode`() {
InjectedThings.partyMode = true

insertFinishedParticipant("Alice", GameType.X01, 29)
insertFinishedTeam("Yoshi", "Wage", GameType.X01, 35)

PlayerEntity.retrieveForName("Yoshi")!!.run {
playerImageId = insertPlayerImage("yoshi").rowId
saveToDatabase()
}

PlayerEntity.retrieveForName("Wage")!!.run {
playerImageId = insertPlayerImage("wage").rowId
saveToDatabase()
}

val leaderboard = LeaderboardTotalScore(GameType.X01)
leaderboard.buildTable()
leaderboard.rowCount() shouldBe 2

val aliceImg = leaderboard.getIconAt(0)
aliceImg.toLabel().shouldMatchImage("individualAvatar")

val teamImg = leaderboard.getIconAt(1)
teamImg.toLabel().shouldMatchImage("teamAvatar")
}

@Test
fun `should ignore unfinished participants`() {
insertFinishedParticipant("Alice", GameType.X01, -1)
Expand Down Expand Up @@ -191,6 +228,8 @@ class TestLeaderboardTotalScore : AbstractTest() {

private fun LeaderboardTotalScore.rowCount() = table().rowCount

private fun LeaderboardTotalScore.getIconAt(row: Int) = table().getValueAt(row, 1) as ImageIcon

private fun LeaderboardTotalScore.getNameAt(row: Int) = table().getValueAt(row, 2)

private fun LeaderboardTotalScore.getGameIdAt(row: Int) = table().getValueAt(row, 3)
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.

0 comments on commit 9ab702f

Please sign in to comment.