Wait for CKEditor to load in specs
Some specs involving CKEditor were failing sometimes in the Rails 5.1 branch. The reason why these specs pass with Rails 5.0 but fail with Rails 5.1 are unknown. On my machine the tests pass when precompiling the assets, which makes me think it's related to the way Rails handles them, but it might have nothing to do with it. The only (apparently) 100% reliable solution I've found is to wait for CKEditor to load before trying to fill it in. After running the tests on my machine hundreds of time, I didn't get a single failure.
This commit is contained in:
@@ -47,6 +47,10 @@ module Verifications
|
|||||||
def fill_in_ckeditor(text, params = {})
|
def fill_in_ckeditor(text, params = {})
|
||||||
locator = find("label", text: text)[:for]
|
locator = find("label", text: text)[:for]
|
||||||
|
|
||||||
|
until page.execute_script("return CKEDITOR.instances.#{locator}.status === 'ready';") do
|
||||||
|
sleep 0.01
|
||||||
|
end
|
||||||
|
|
||||||
# Fill the editor content
|
# Fill the editor content
|
||||||
page.execute_script <<-SCRIPT
|
page.execute_script <<-SCRIPT
|
||||||
var ckeditor = CKEDITOR.instances.#{locator}
|
var ckeditor = CKEDITOR.instances.#{locator}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ describe "CKEditor" do
|
|||||||
login_as(create(:administrator).user)
|
login_as(create(:administrator).user)
|
||||||
|
|
||||||
visit new_admin_site_customization_page_path
|
visit new_admin_site_customization_page_path
|
||||||
|
fill_in_ckeditor "Content", with: "Filling in to make sure CKEditor is loaded"
|
||||||
find(".cke_button__image").click
|
find(".cke_button__image").click
|
||||||
|
|
||||||
expect(page).to have_css(".cke_dialog")
|
expect(page).to have_css(".cke_dialog")
|
||||||
@@ -41,8 +42,9 @@ describe "CKEditor" do
|
|||||||
|
|
||||||
scenario "cannot upload attachments through link tab", :js do
|
scenario "cannot upload attachments through link tab", :js do
|
||||||
login_as(create(:administrator).user)
|
login_as(create(:administrator).user)
|
||||||
visit new_admin_site_customization_page_path
|
|
||||||
|
|
||||||
|
visit new_admin_site_customization_page_path
|
||||||
|
fill_in_ckeditor "Content", with: "Filling in to make sure CKEditor is loaded"
|
||||||
find(".cke_button__link").click
|
find(".cke_button__link").click
|
||||||
|
|
||||||
expect(page).to have_css(".cke_dialog")
|
expect(page).to have_css(".cke_dialog")
|
||||||
|
|||||||
Reference in New Issue
Block a user