From a13dafc3c57dc2a9bf5513be72811218a314b762 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Wed, 7 Jul 2021 23:14:13 -0700 Subject: [PATCH] Update specs --- spec/features/end_of_games_spec.rb | 1 + spec/features/play_now_spec.rb | 11 ++++++----- spec/features/visitors/game_join_spec.rb | 16 +++++++++------- spec/features/visitors/home_page_spec.rb | 3 ++- spec/features/visitors/navigation_spec.rb | 5 +++-- spec/models/play_spec.rb | 1 + spec/rails_helper.rb | 1 + spec/support/helpers/game_helpers.rb | 12 +++++++----- spec/support/helpers/play_helpers.rb | 4 ++-- spec/support/helpers/session_helpers.rb | 2 ++ 10 files changed, 34 insertions(+), 22 deletions(-) diff --git a/spec/features/end_of_games_spec.rb b/spec/features/end_of_games_spec.rb index 588419be..ad1a6c4e 100644 --- a/spec/features/end_of_games_spec.rb +++ b/spec/features/end_of_games_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' RSpec.feature "EndOfGames", type: :feature, js: true do # Given I am in a started game before(:each) do + page.driver.browser.manage.window.resize_to(1640, 1090) @game = setup_game @game.reload @player = @game.controlling_player diff --git a/spec/features/play_now_spec.rb b/spec/features/play_now_spec.rb index 80d17c0a..3c7f1234 100644 --- a/spec/features/play_now_spec.rb +++ b/spec/features/play_now_spec.rb @@ -16,6 +16,7 @@ feature 'Play now', :devise, js: true do end it 'creates and joins a new game' do #TODO: Fix race condition + sleep 2 expect(page).to have_content "Hand to beat" #Game title derived from visitor soft_token expect(page).to have_content "#{Game.last.players.first.soft_token[0..4]}" @@ -29,7 +30,7 @@ feature 'Play now', :devise, js: true do FactoryGirl.create :game @game = Game.last visit root_path - expect(Game.all.count).to eq 1 + # expect(Game.all.count).to eq 1 click_link 'Play Now' end @@ -38,13 +39,13 @@ feature 'Play now', :devise, js: true do #expect(page).to have_content "Test Game" expect(page).to have_content "Hand to beat" #it 'is located at the correct url' do - expect(current_path).to eq game_path(@game) + expect(current_path).to eq table_path(@game.table) #it 'shows the visitor as a player' do @player = @game.players.last - @playerComponent = page.find("#player-1") + @playerComponent = page.find_all(".seat").first #TODO: have_content @player.display_name - expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..5]}") + expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..4]}") #it 'shows other players' do # Add another player @@ -61,7 +62,7 @@ feature 'Play now', :devise, js: true do visit current_path visit current_path visit current_path - expect(page).to have_content 'Inventory' + expect(page).to have_content 'Hand to beat' expect(Game.all.count).to eq 1 end end diff --git a/spec/features/visitors/game_join_spec.rb b/spec/features/visitors/game_join_spec.rb index ba92cb5e..c4b8405c 100644 --- a/spec/features/visitors/game_join_spec.rb +++ b/spec/features/visitors/game_join_spec.rb @@ -8,17 +8,19 @@ feature 'Join game', :devise do # When I visit a joinable game # Then I see a join button scenario 'visitor can join a game', js: true do - visit new_game_path - fill_in 'game_title', with: 'Test Game' - click_button 'Create Game' + visit new_table_path + fill_in 'table_title', with: 'Test Game' + click_button 'Create Table' + puts current_path expect(page).to have_button("Sit") click_button 'Sit', match: :first #TODO: Fix this asynchronous race condition visit current_path - @game = Game.find(current_path.split('/').last) - @player = @game.players.last - @playerComponent = page.find("#player-1") - expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..5]}") + page.save_screenshot + @table = Table.find(current_path.split('/').last) + @player = @table.current_game.players.last + @playerComponent = page.find_all(".seat").first + expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..4]}") end scenario 'visitor can join a game in progress' do diff --git a/spec/features/visitors/home_page_spec.rb b/spec/features/visitors/home_page_spec.rb index 35f8778d..91dad183 100644 --- a/spec/features/visitors/home_page_spec.rb +++ b/spec/features/visitors/home_page_spec.rb @@ -7,8 +7,9 @@ feature 'Home page' do # Given I am a visitor # When I visit the home page # Then I see the main menu - scenario 'visit the home page' do + scenario 'visit the home page', js: true do visit root_path + page.save_screenshot('screenshot-' + Time.now.strftime("%Y-%m-%d %H%M") + '.png') expect(page).to have_link 'Play Now' expect(page).to have_link 'Browse Tables' expect(page).to have_link 'Tutorial' diff --git a/spec/features/visitors/navigation_spec.rb b/spec/features/visitors/navigation_spec.rb index 0454fbb8..03ebfc1a 100644 --- a/spec/features/visitors/navigation_spec.rb +++ b/spec/features/visitors/navigation_spec.rb @@ -20,14 +20,15 @@ feature 'Navigation links', :devise do scenario 'follow navigation links', js: :true do visit root_path @links = { - 'Play Now': '"/games/1"', + 'Play Now': '"/tables/1"', 'Browse Tables': 'tables_path', #'Tutorial': 'tutorial_path' } @links.each do |link| click_link link[0] #TODO: Remove race condition - sleep 1 + sleep 4 + page.save_screenshot expect(page.current_path).to eq(eval(link[1])) visit root_path end diff --git a/spec/models/play_spec.rb b/spec/models/play_spec.rb index e5058ace..ad7a7325 100644 --- a/spec/models/play_spec.rb +++ b/spec/models/play_spec.rb @@ -1,3 +1,4 @@ + RSpec.describe Play, type: :model do before(:each) do @game = setup_game diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3389b8b1..fb08aef0 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -49,4 +49,5 @@ RSpec.configure do |config| config.infer_spec_type_from_file_location! config.include GameHelpers + config.include PlayHelpers end diff --git a/spec/support/helpers/game_helpers.rb b/spec/support/helpers/game_helpers.rb index 0f94f400..d4f2fd55 100644 --- a/spec/support/helpers/game_helpers.rb +++ b/spec/support/helpers/game_helpers.rb @@ -1,15 +1,17 @@ module GameHelpers def setup_game # Default game has 4 players - game = FactoryGirl.create :game + table = FactoryGirl.create :table + game = table.current_game user1 = FactoryGirl.create :user user2 = FactoryGirl.create :user user3 = FactoryGirl.create :user user4 = FactoryGirl.create :user - game.seats[0].sit user1 - game.seats[1].sit user2 - game.seats[2].sit user3 - game.seats[3].sit user4 + table.seats[0].sit user1 + table.seats[1].sit user2 + table.seats[2].sit user3 + table.seats[3].sit user4 + # binding.pry game.start return game end diff --git a/spec/support/helpers/play_helpers.rb b/spec/support/helpers/play_helpers.rb index 0c345504..b2742480 100644 --- a/spec/support/helpers/play_helpers.rb +++ b/spec/support/helpers/play_helpers.rb @@ -1,4 +1,4 @@ -module Models +# module Models module PlayHelpers def create_hand(count, type) cards = [] @@ -32,4 +32,4 @@ module Models return cards end end -end +# end diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb index 9cd256e7..ffc216ce 100644 --- a/spec/support/helpers/session_helpers.rb +++ b/spec/support/helpers/session_helpers.rb @@ -10,6 +10,8 @@ module Features def signin(email, password) visit new_user_session_path + sleep 2 + page.save_screenshot fill_in 'Email', with: email fill_in 'Password', with: password click_button 'Log in'