Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qluxzz committed Oct 27, 2024
1 parent f67bcf7 commit 411f6f9
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions tests/GameTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SimulatedEffect.Cmd
import SimulatedEffect.Process
import SimulatedEffect.Task
import Test exposing (describe, test)
import Test.Html.Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector

Expand All @@ -26,8 +27,9 @@ suite =
, Selector.exactText "$10"
, Selector.exactText "$100"
, Selector.exactText "$500"
, Selector.exactText "$1000"
]
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Validate that the user has the expected cards
|> ProgramTest.ensureView
(handHasCards 0 [ Card Card.Ace Card.Spades, Card Card.Three Card.Spades ])
Expand All @@ -48,7 +50,7 @@ suite =
|> ProgramTest.ensureView (playerHasMoney 400)
-- Continue to next round
|> ProgramTest.clickButton "Continue?"
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Validate that the user has the expected cards
|> ProgramTest.ensureView
(handHasCards 0 [ Card Card.Eight Card.Spades, Card Card.Ten Card.Spades ])
Expand Down Expand Up @@ -78,7 +80,7 @@ suite =
, Card Card.Ten Card.Diamonds -- Dealer takes and busts (6+6+10 > 21)
]
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Validate that the user has the expected hand
|> ProgramTest.ensureView
(Expect.all
Expand Down Expand Up @@ -131,7 +133,7 @@ suite =
, Card Card.Ten Card.Hearts -- Dealer takes and busts (6+6+10 > 21)
]
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Validate that the user has the expected hand
|> ProgramTest.ensureView
(Expect.all
Expand Down Expand Up @@ -186,7 +188,7 @@ suite =
, Card Card.Ten Card.Diamonds -- Dealer takes and busts (6+6+10 > 21)
]
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Validate that the user has the expected hand
|> ProgramTest.ensureView
(Expect.all
Expand Down Expand Up @@ -240,7 +242,7 @@ suite =
, Card Card.Ten Card.Diamonds -- Player gets second card on second hand
]
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
|> ProgramTest.ensureView
(handHasCards 0 [ Card Card.Eight Card.Diamonds, Card Card.Eight Card.Hearts ])
|> ProgramTest.clickButton "Split"
Expand Down Expand Up @@ -310,7 +312,7 @@ suite =
, Card Card.Ten Card.Diamonds
]
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
|> ProgramTest.ensureView
(Expect.all
[ handHasCards 0 [ Card Card.Five Card.Spades, Card Card.Five Card.Clubs ]
Expand Down Expand Up @@ -364,7 +366,7 @@ suite =
]
|> withDelay
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Deal a card per 'tick', so four means the dealer and the player has two cards each
|> ProgramTest.advanceTime 4
|> ProgramTest.clickButton "Double down"
Expand All @@ -385,7 +387,7 @@ suite =
]
|> withDelay
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Deal a card per 'tick', so four means the dealer and the player has two cards each
|> ProgramTest.advanceTime 4
|> ProgramTest.ensureView
Expand All @@ -410,7 +412,7 @@ suite =
]
|> withDelay
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Deal a card per 'tick', so three means the dealer has one card and the player has two cards
|> ProgramTest.advanceTime 3
|> ProgramTest.ensureView (toastHasMessage "Black Jack!")
Expand All @@ -437,7 +439,7 @@ suite =
]
|> withDelay
)
|> ProgramTest.clickButton "$100"
|> clickMarker 100
-- Deal a card per 'tick', so four means the dealer and the player has two cards each
|> ProgramTest.advanceTime 4
|> ProgramTest.clickButton "Stand"
Expand Down Expand Up @@ -656,3 +658,27 @@ start settings =
}
|> ProgramTest.withSimulatedEffects (simulateEffects settings.delay)
|> ProgramTest.start ()



{- Click on a marker by marker amount
Required since ProgramTest.clickButton "$100" will match both buttons "$100" and "$1000".
The following doesn't work either:
```elm
ProgramTest.simulateDomEvent
(Query.find [ Selector.tag "button", Selector.exactText ("$" ++ String.fromInt amount) ])
Test.Html.Event.click
```
Since the query returns the text node, and not the button itself, and we can't click a text node
-}


clickMarker : Int -> ProgramTest.ProgramTest model msg effect -> ProgramTest.ProgramTest model msg effect
clickMarker amount =
ProgramTest.simulateDomEvent
(Query.find [ Selector.tag "button", Selector.classes [ "marker", "_" ++ String.fromInt amount ] ])
Test.Html.Event.click

0 comments on commit 411f6f9

Please sign in to comment.