From a0ea1f6ecb5404d6b706b68b070f4e61cdcea5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 10 Apr 2020 15:14:15 +0200 Subject: [PATCH 1/2] Simplify CKEditor translatable fields in specs We've simplified the way CKEditor is handled in tests; probably due to that, we don't need this method anymore. --- spec/features/admin/budget_phases_spec.rb | 4 ++-- spec/support/common_actions/verifications.rb | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/spec/features/admin/budget_phases_spec.rb b/spec/features/admin/budget_phases_spec.rb index 6f3f4f7ef..f1c6d33b7 100644 --- a/spec/features/admin/budget_phases_spec.rb +++ b/spec/features/admin/budget_phases_spec.rb @@ -14,8 +14,8 @@ describe "Admin budget phases" do fill_in "start_date", with: Date.current + 1.day fill_in "end_date", with: Date.current + 12.days - fill_in_translatable_ckeditor "summary", :en, with: "New summary of the phase." - fill_in_translatable_ckeditor "description", :en, with: "New description of the phase." + fill_in_ckeditor "Summary", with: "New summary of the phase." + fill_in_ckeditor "Description", with: "New description of the phase." uncheck "budget_phase_enabled" click_button "Save changes" diff --git a/spec/support/common_actions/verifications.rb b/spec/support/common_actions/verifications.rb index 1d402522c..261a4a2d0 100644 --- a/spec/support/common_actions/verifications.rb +++ b/spec/support/common_actions/verifications.rb @@ -44,12 +44,6 @@ module Verifications end end - def fill_in_translatable_ckeditor(field, locale, params = {}) - selector = ".translatable-fields[data-locale='#{locale}'] textarea[id$='_#{field}']" - locator = find(selector, visible: false)[:id] - fill_in_ckeditor(locator, params) - end - # @param [String] locator label text for the textarea or textarea id def fill_in_ckeditor(locator, params = {}) # Find out ckeditor id at runtime using its label From 2cdc6a1b1b11212ea5ea6268f628a24386529da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 10 Apr 2020 15:18:39 +0200 Subject: [PATCH 2/2] Check CKEditor is filled properly in tests It looks like sometimes, particularly when the first thing we do after loading a page is filling the CKEditor fields and submitting the form, CKEditor doesn't have enough time to format the text, and so it's sent as plain text instead of HTML. This behaviour can be reproduced on my local machine after upgrading to Rails 5.1, with the test "Admin Active polls Add" failing 100% of the time. Checking CKEditor has been filled in correctly solves the issue. --- spec/features/admin/legislation/processes_spec.rb | 5 +---- spec/shared/features/nested_documentable.rb | 2 +- spec/support/common_actions/verifications.rb | 9 +++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 3bba51fcd..b509fc95a 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -264,10 +264,7 @@ describe "Admin collaborative legislation" do expect(page).not_to have_link "Remove language" expect(page).not_to have_field "translation_locale" - within(".translatable-fields[data-locale='en']") do - fill_in_ckeditor find("textarea", visible: false)[:id], - with: "There is still a long journey ahead of us" - end + fill_in_ckeditor "Summary", with: "There is still a long journey ahead of us" click_button "Update Process" diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 9ac59864c..01a1c8b38 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -351,7 +351,7 @@ end def documentable_fill_new_valid_dashboard_action fill_in :dashboard_action_title, with: "Dashboard title" - fill_in_ckeditor :dashboard_action_description, with: "Dashboard description" + fill_in_ckeditor "Description", with: "Dashboard description" end def documentable_fill_new_valid_budget_investment diff --git a/spec/support/common_actions/verifications.rb b/spec/support/common_actions/verifications.rb index 261a4a2d0..1023a69b4 100644 --- a/spec/support/common_actions/verifications.rb +++ b/spec/support/common_actions/verifications.rb @@ -44,10 +44,9 @@ module Verifications end end - # @param [String] locator label text for the textarea or textarea id - def fill_in_ckeditor(locator, params = {}) - # Find out ckeditor id at runtime using its label - locator = find("label", text: locator)[:for] if page.has_css?("label", text: locator) + def fill_in_ckeditor(text, params = {}) + locator = find("label", text: text)[:for] + # Fill the editor content page.execute_script <<-SCRIPT var ckeditor = CKEDITOR.instances.#{locator} @@ -55,5 +54,7 @@ module Verifications ckeditor.focus() ckeditor.updateElement() SCRIPT + + expect(page).to have_ckeditor text, with: params[:with] end end