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:
Javi Martín
2020-04-17 16:06:29 +02:00
parent 688aa88366
commit 5b97b20f96
2 changed files with 7 additions and 1 deletions

View File

@@ -47,6 +47,10 @@ module Verifications
def fill_in_ckeditor(text, params = {})
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
page.execute_script <<-SCRIPT
var ckeditor = CKEDITOR.instances.#{locator}

View File

@@ -19,6 +19,7 @@ describe "CKEditor" do
login_as(create(:administrator).user)
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
expect(page).to have_css(".cke_dialog")
@@ -41,8 +42,9 @@ describe "CKEditor" do
scenario "cannot upload attachments through link tab", :js do
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
expect(page).to have_css(".cke_dialog")