Skip to content

Commit

Permalink
重複しているテストコードをメソッド化
Browse files Browse the repository at this point in the history
  • Loading branch information
naokinaokiboo committed May 28, 2024
1 parent 0f7c857 commit a895a56
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/system/admin/invitation_url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase
assert_equal '管理ページ | FBC', title
end

def wait_for_invitation_url_with_timeout(expected)
Timeout.timeout(Capybara.default_max_wait_time, StandardError) do
loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected
end
end

test 'show invitation-url page' do
visit_with_auth '/admin/invitation_url', 'komagata'
company = Company.order(created_at: :desc).first
role = User::INVITATION_ROLES.first[1]
course = Course.order(:created_at).first
expected = "#{@new_user_url}?company_id=#{company.id}&course_id=#{course.id}&role=#{role}&token=token"

Timeout.timeout(Capybara.default_max_wait_time, StandardError) do
loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected
end
wait_for_invitation_url_with_timeout(expected)
end

test 'change selected company' do
Expand All @@ -38,9 +42,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase

find('.js-invitation-company').click
select(company.name)
Timeout.timeout(Capybara.default_max_wait_time, StandardError) do
loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected
end
wait_for_invitation_url_with_timeout(expected)
end

test 'change selected role' do
Expand All @@ -53,9 +55,7 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase

find('.js-invitation-role').click
select(role_text)
Timeout.timeout(Capybara.default_max_wait_time, StandardError) do
loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected
end
wait_for_invitation_url_with_timeout(expected)
end

test 'change selected course' do
Expand All @@ -67,8 +67,6 @@ class Admin::InvitationUrlTest < ApplicationSystemTestCase

find('.js-invitation-course')
select(course.title)
Timeout.timeout(Capybara.default_max_wait_time, StandardError) do
loop until find('.js-invitation-url-text').value == expected && find('.js-invitation-url')[:href] == expected
end
wait_for_invitation_url_with_timeout(expected)
end
end

0 comments on commit a895a56

Please sign in to comment.