Files
nairobi/spec/support/common_actions/verifications.rb
Javi Martín 8408bfdcf0 Don't use ckeditor.setData in specs
After upgrading to chromedriver 80, tests checking CKEditor's content
were causing chromedriver to hang. That's why we were configuring
webdrivers to use an older chromedriver.

Version 80 of chromedriver introduced several issues regarding frames.
Debugging shows in this case chromedriver froze when we used `setData`
and then `within_frame`. Since adding a `sleep` call made it work, we
think `within_frame` was being executed before `setData` had finished.
The fact that `setData` causes the browser to enter the frame having
CKEditor is probably the reason.

Even though the `setData` method provides a callback when it's finished,
configuring it so the rest of the Ruby code isn't executed until that
happens leads to complex code. Using Capybara's `set` to fill in the
editor is IMHO a bit easier to understand.

After this change, since we're using a method provided by Capybara
instead of executing asynchronous JavaScript code, we don't have to
check CKEditor has been filled anymore. The "Admin Active polls add"
test, which failed on my machine without that check, now passes.
2020-06-09 13:29:56 +02:00

59 lines
1.7 KiB
Ruby

module Verifications
def select_date(values, selector)
selector = selector[:from]
day, month, year = values.split("-")
select day, from: "#{selector}_3i"
select month, from: "#{selector}_2i"
select year, from: "#{selector}_1i"
end
def verify_residence
select "DNI", from: "residence_document_type"
fill_in "residence_document_number", with: "12345678Z"
select_date "31-#{I18n.l(Date.current.at_end_of_year, format: "%B")}-1980",
from: "residence_date_of_birth"
fill_in "residence_postal_code", with: "28013"
check "residence_terms_of_service"
click_button "new_residence_submit"
expect(page).to have_content I18n.t("verification.residence.create.flash.success")
end
def officing_verify_residence
select "DNI", from: "residence_document_type"
fill_in "residence_document_number", with: "12345678Z"
fill_in "residence_year_of_birth", with: "1980"
click_button "Validate document"
expect(page).to have_content "Document verified with Census"
end
def expect_badge_for(resource_name, resource)
within("##{resource_name}_#{resource.id}") do
expect(page).to have_css ".label.round"
expect(page).to have_content "Employee"
end
end
def expect_no_badge_for(resource_name, resource)
within("##{resource_name}_#{resource.id}") do
expect(page).not_to have_css ".label.round"
expect(page).not_to have_content "Employee"
end
end
def fill_in_ckeditor(label, with:)
locator = find("label", text: label)[:for]
until page.execute_script("return CKEDITOR.instances.#{locator}.status === 'ready';") do
sleep 0.01
end
within("#cke_#{locator}") do
within_frame(0) { find("body").set(with) }
end
end
end