Skip to content

Commit

Permalink
buzz window tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoung786 committed May 19, 2024
1 parent aa84276 commit c693561
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
9 changes: 4 additions & 5 deletions assets/js/hooks/buzz_timestamp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export default {
mounted() {
window.addEventListener("jeopardy:buzz", (event) => {
this.pushEventTo("#awaiting-buzz", "buzz", {
timestamp: Date.now()
});
});

this.el.addEventListener("jeopardy:buzz", e => {
this.pushEventTo("#awaiting-buzz", "buzz", {timestamp: Date.now()});
})
}
};
2 changes: 1 addition & 1 deletion lib/jeopardy_web/components/contestant/awaiting_buzz.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule JeopardyWeb.Components.Contestant.AwaitingBuzz do
<.button
:if={@name not in @game.clue.incorrect_contestants}
class="btn-primary rounded-none w-full h-full"
phx-click={JS.dispatch("jeopardy:buzz")}
phx-click={JS.dispatch("jeopardy:buzz", to: "#awaiting-buzz")}
phx-target={@myself}
>
Buzz
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Jeopardy.MixProject do
{:phoenix_html, "~> 3.3"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.20.1"},
{:floki, "~> 0.34.3"},
{:floki, "~> 0.36"},
{:phoenix_live_dashboard, "~> 0.8.0"},
{:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
{:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"exqlite": {:hex, :exqlite, "0.22.0", "8bc24a2b807f34ae1af15203f16668bf6abd171b35e4097d7ad56a717f9bafa8", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "3ea23b9fab54d68815281cac15ca4c7c4cbd0e8832dffe4bd395742f938e87c0"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"finch": {:hex, :finch, "0.18.0", "944ac7d34d0bd2ac8998f79f7a811b21d87d911e77a786bc5810adb75632ada4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69f5045b042e531e53edc2574f15e25e735b522c37e2ddb766e15b979e03aa65"},
"floki": {:hex, :floki, "0.34.3", "5e2dcaec5d7c228ce5b1d3501502e308b2d79eb655e4191751a1fe491c37feac", [:mix], [], "hexpm", "9577440eea5b97924b4bf3c7ea55f7b8b6dce589f9b28b096cc294a8dc342341"},
"floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"},
"gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
Expand Down
14 changes: 9 additions & 5 deletions test/jeopardy/end_to_end_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ defmodule Jeopardy.EndToEndTest do
GameServer.action(code, :finished_reading)

assert fsm_state(code) == FSM.AwaitingBuzz
GameServer.action(code, :buzz, "a")
GameServer.action(code, :buzz, {"a", 0})
GameServer.action(code, :buzz_window_expired)

assert fsm_state(code) == FSM.AwaitingAnswer
{:ok, game} = GameServer.action(code, :answered, :incorrect)
assert game.contestants["a"].score == -100
assert fsm_state(code) == FSM.AwaitingBuzz
{:error, :already_answered_incorrectly} = GameServer.action(code, :buzz, "a")
{:error, :already_answered_incorrectly} = GameServer.action(code, :buzz, {"a", 2})
GameServer.action(code, :time_expired)

assert fsm_state(code) == FSM.ReadingAnswer
Expand All @@ -54,7 +55,8 @@ defmodule Jeopardy.EndToEndTest do
GameServer.action(code, :finished_reading)

assert fsm_state(code) == FSM.AwaitingBuzz
GameServer.action(code, :buzz, "b")
GameServer.action(code, :buzz, {"b", 0})
GameServer.action(code, :buzz_window_expired)

assert fsm_state(code) == FSM.AwaitingAnswer
{:ok, game} = GameServer.action(code, :answered, :correct)
Expand All @@ -76,13 +78,15 @@ defmodule Jeopardy.EndToEndTest do
GameServer.action(code, :finished_reading)

assert fsm_state(code) == FSM.AwaitingBuzz
GameServer.action(code, :buzz, "a")
GameServer.action(code, :buzz, {"a", 0})
GameServer.action(code, :buzz_window_expired)

assert fsm_state(code) == FSM.AwaitingAnswer
GameServer.action(code, :answered, :incorrect)

assert fsm_state(code) == FSM.AwaitingBuzz
GameServer.action(code, :buzz, "b")
GameServer.action(code, :buzz, {"b", 0})
GameServer.action(code, :buzz_window_expired)

assert fsm_state(code) == FSM.AwaitingAnswer
{:ok, game} = GameServer.action(code, :answered, :incorrect)
Expand Down

0 comments on commit c693561

Please sign in to comment.