mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-31 19:45:45 +00:00
Use turbo streams for the bout board instead of auto refreshing every 30 seconds.
This commit is contained in:
@@ -559,6 +559,36 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
get_up_matches
|
||||
success
|
||||
end
|
||||
|
||||
test "up matches uses turbo stream updates instead of timer refresh script" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
get_up_matches
|
||||
success
|
||||
assert_includes response.body, "turbo-cable-stream-source"
|
||||
assert_includes response.body, "data-controller=\"up-matches-connection\""
|
||||
assert_includes response.body, "up-matches-cable-status-indicator"
|
||||
assert_not_includes response.body, "This page reloads every 30s"
|
||||
end
|
||||
|
||||
test "up matches shows full screen button when print param is not true" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
get :up_matches, params: { id: @tournament.id }
|
||||
assert_response :success
|
||||
|
||||
assert_includes response.body, "Show Bout Board in Full Screen"
|
||||
assert_includes response.body, "print=true"
|
||||
end
|
||||
|
||||
test "up matches hides full screen button when print param is true" do
|
||||
@tournament.is_public = true
|
||||
@tournament.save
|
||||
get :up_matches, params: { id: @tournament.id, print: "true" }
|
||||
assert_response :success
|
||||
|
||||
assert_not_includes response.body, "Show Bout Board in Full Screen"
|
||||
end
|
||||
# END UP MATCHES PAGE PERMISSIONS
|
||||
|
||||
# ALL_RESULTS PAGE PERMISSIONS WHEN TOURNAMENT IS NOT PUBLIC
|
||||
@@ -643,11 +673,11 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
# END ALL_RESULTS PAGE PERMISSIONS
|
||||
|
||||
#TESTS THAT NEED MATCHES PUT ABOVE THIS
|
||||
test "redirect up_matches if no matches" do
|
||||
test "up_matches renders when no matches exist" do
|
||||
sign_in_owner
|
||||
wipe
|
||||
get :up_matches, params: { id: 1 }
|
||||
no_matches
|
||||
success
|
||||
end
|
||||
|
||||
test "redirect bracket if no matches" do
|
||||
|
||||
@@ -40,9 +40,9 @@ class UpMatchesCacheTest < ActionController::TestCase
|
||||
mat.reload
|
||||
movable_match = mat.queue2_match || mat.queue1_match
|
||||
assert movable_match, "Expected at least one queued match to move"
|
||||
mat.assign_match_to_queue!(movable_match, 4)
|
||||
|
||||
third_events = cache_events_for_up_matches do
|
||||
mat.assign_match_to_queue!(movable_match, 4)
|
||||
get :up_matches, params: { id: @tournament.id }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -25,6 +25,7 @@ class RandomSeedingTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "There are the same number of matches in the top half and bottom half of a double elimination tournament in round 1" do
|
||||
# This has to be an even number otherwise there will obviously be a discrepency
|
||||
create_double_elim_tournament_single_weight(18, "Regular Double Elimination 1-8")
|
||||
clean_up_original_seeds(@tournament)
|
||||
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
|
||||
@@ -35,6 +36,7 @@ class RandomSeedingTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "There are the same number of matches in the top half and bottom half of a double elimination tournament in round 1 in a 6 man bracket" do
|
||||
# This has to be an even number otherwise there will obviously be a discrepency
|
||||
create_double_elim_tournament_single_weight(6, "Regular Double Elimination 1-8")
|
||||
clean_up_original_seeds(@tournament)
|
||||
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
|
||||
@@ -52,4 +54,22 @@ class RandomSeedingTest < ActionDispatch::IntegrationTest
|
||||
assert round_one_matches.select{|m| m.w1.nil? and m.w2.nil? }.size == 0
|
||||
assert conso_round_one_matches.select{|m| m.loser1_name == "BYE" and m.loser2_name == "BYE" }.size == 0
|
||||
end
|
||||
|
||||
test "There are no double byes in a 64 person double elimination tournament in round 1" do
|
||||
create_double_elim_tournament_single_weight(33, "Regular Double Elimination 1-8")
|
||||
clean_up_original_seeds(@tournament)
|
||||
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
|
||||
assert round_one_matches.select{|m| m.w1.nil? and m.w2.nil? }.size == 0
|
||||
end
|
||||
|
||||
test "There are the same number of matches in the top half and bottom half of a 64 person double elimination tournament in round 1" do
|
||||
# This has to be an even number otherwise there will obviously be a discrepency
|
||||
create_double_elim_tournament_single_weight(34, "Regular Double Elimination 1-8")
|
||||
clean_up_original_seeds(@tournament)
|
||||
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
|
||||
# 64 man bracket there are 32 matches so top half is bracket_position_number 1-16 and bottom is 17-32
|
||||
round_one_top_half = round_one_matches.select{|m| !m.w1.nil? and !m.w2.nil? and m.bracket_position_number < 17}
|
||||
round_one_bottom_half = round_one_matches.select{|m| !m.w1.nil? and !m.w2.nil? and m.bracket_position_number > 16}
|
||||
assert round_one_top_half.size == round_one_bottom_half.size
|
||||
end
|
||||
end
|
||||
87
test/models/up_matches_broadcast_test.rb
Normal file
87
test/models/up_matches_broadcast_test.rb
Normal file
@@ -0,0 +1,87 @@
|
||||
require "test_helper"
|
||||
|
||||
class UpMatchesBroadcastTest < ActiveSupport::TestCase
|
||||
test "tournament broadcaster emits replace action for up matches board" do
|
||||
tournament = tournaments(:one)
|
||||
stream = stream_name_for(tournament)
|
||||
clear_streams(stream)
|
||||
|
||||
Tournament.broadcast_up_matches_board(tournament.id)
|
||||
|
||||
assert_operator broadcasts_for(stream).size, :>, 0
|
||||
payload = broadcasts_for(stream).last
|
||||
assert_up_matches_replace_payload(payload)
|
||||
end
|
||||
|
||||
test "mat queue change broadcasts up matches board update" do
|
||||
tournament = tournaments(:one)
|
||||
mat = mats(:one)
|
||||
match = matches(:tournament_1_bout_2000)
|
||||
stream = stream_name_for(tournament)
|
||||
clear_streams(stream)
|
||||
|
||||
mat.update!(queue1: match.id)
|
||||
|
||||
assert_operator broadcasts_for(stream).size, :>, 0
|
||||
assert_up_matches_replace_payload(broadcasts_for(stream).last)
|
||||
end
|
||||
|
||||
test "match mat assignment change broadcasts up matches board update" do
|
||||
tournament = tournaments(:one)
|
||||
mat = mats(:one)
|
||||
match = matches(:tournament_1_bout_2001)
|
||||
stream = stream_name_for(tournament)
|
||||
clear_streams(stream)
|
||||
|
||||
match.update!(mat_id: mat.id)
|
||||
|
||||
assert_operator broadcasts_for(stream).size, :>, 0
|
||||
assert_up_matches_replace_payload(broadcasts_for(stream).last)
|
||||
end
|
||||
|
||||
test "mat update without queue slot changes does not broadcast up matches board update" do
|
||||
tournament = tournaments(:one)
|
||||
mat = mats(:one)
|
||||
stream = stream_name_for(tournament)
|
||||
clear_streams(stream)
|
||||
|
||||
mat.update!(name: "Mat One Renamed")
|
||||
|
||||
assert_equal 0, broadcasts_for(stream).size
|
||||
end
|
||||
|
||||
test "match update without mat_id change does not broadcast up matches board update" do
|
||||
tournament = tournaments(:one)
|
||||
match = matches(:tournament_1_bout_2001)
|
||||
stream = stream_name_for(tournament)
|
||||
clear_streams(stream)
|
||||
|
||||
match.update!(w1_stat: "Local stat change")
|
||||
|
||||
assert_equal 0, broadcasts_for(stream).size
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def broadcasts_for(stream)
|
||||
ActionCable.server.pubsub.broadcasts(stream)
|
||||
end
|
||||
|
||||
def clear_streams(*streams)
|
||||
ActionCable.server.pubsub.clear
|
||||
streams.each do |stream|
|
||||
broadcasts_for(stream).clear
|
||||
end
|
||||
end
|
||||
|
||||
def stream_name_for(streamable)
|
||||
Turbo::StreamsChannel.send(:stream_name_from, [streamable])
|
||||
end
|
||||
|
||||
# Broadcast payloads may be JSON-escaped in test adapters, so assert semantic markers.
|
||||
def assert_up_matches_replace_payload(payload)
|
||||
assert_includes payload, "up_matches_board"
|
||||
assert_includes payload, "replace"
|
||||
assert_includes payload, "turbo-stream"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user