Files
grecia/spec/system/ckeditor_spec.rb
Javi Martín 5b97b20f96 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.
2020-04-24 15:43:54 +02:00

55 lines
1.6 KiB
Ruby

require "rails_helper"
describe "CKEditor" do
scenario "is present before & after turbolinks update page", :js do
author = create(:user)
login_as(author)
visit new_debate_path
expect(page).to have_css ".translatable-fields[data-locale='en'] .cke_wysiwyg_frame"
click_link "Debates"
click_link "Start a debate"
expect(page).to have_css ".translatable-fields[data-locale='en'] .cke_wysiwyg_frame"
end
scenario "uploading an image through the upload tab", :js 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")
execute_script "document.getElementsByClassName('cke_dialog')[0].style.left = '0px'"
execute_script "document.getElementsByClassName('cke_dialog')[0].style.top = '0px'"
expect(find(".cke_dialog")).to match_style(left: "0px", top: "0px")
click_link "Upload"
within_frame(1) do
attach_file "Send it to the Server", Rails.root.join("spec/fixtures/files/clippy.jpg")
end
click_link "Send it to the Server"
expect(page).to have_css "img[src$='clippy.jpg']"
end
scenario "cannot upload attachments through link tab", :js 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__link").click
expect(page).to have_css(".cke_dialog")
expect(page).not_to have_link "Upload"
expect(page).not_to have_link "Browse Server"
end
end