Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions spec/features/users/sign_in_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'rails_helper'

feature 'Sign in' do
include JavascriptDriverHelper

before(:all) do
@original_capyabara_wait = Capybara.default_max_wait_time
Capybara.default_max_wait_time = 5
Expand Down Expand Up @@ -223,9 +221,11 @@

visit new_user_session_path

with_awaited_fetch do
check t('components.password_toggle.toggle_label')
end
check t('components.password_toggle.toggle_label')

# Clicking the checkbox triggers a frontend event logging request. Wait for network requests to
# settle before continuing to avoid a race condition.
Capybara.current_session.server.wait_for_pending_requests

expect(page).to have_css('input.password[type="text"]')
expect(fake_analytics).to have_logged_event(
Expand Down
21 changes: 0 additions & 21 deletions spec/support/features/javascript_driver_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,4 @@ module JavascriptDriverHelper
def javascript_enabled?
%i[headless_chrome headless_chrome_mobile].include?(Capybara.current_driver)
end

def with_awaited_fetch
setup_js = <<~JS
window._fetch = window.fetch;
window.fetch = async (...args) => {
window.isFetching = true;
const result = await window._fetch.call(window, ...args);
window.isFetching = false;
return result;
};
JS
teardown_js = 'window.fetch = window._fetch; delete window._fetch;'

page.execute_script(setup_js)
yield
Timeout.timeout(Capybara.default_max_wait_time) do
loop if page.evaluate_script('window.isFetching')
end
ensure
page.execute_script(teardown_js)
end
end