From 3012df29e718e3eda56217f08b645779d023df2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 24 Sep 2019 15:27:31 +0200 Subject: [PATCH 1/4] Add matcher for CKEditor fields --- spec/features/admin/translatable_spec.rb | 10 +++++----- spec/features/translatable_spec.rb | 2 +- spec/support/matchers/have_ckeditor.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 spec/support/matchers/have_ckeditor.rb diff --git a/spec/features/admin/translatable_spec.rb b/spec/features/admin/translatable_spec.rb index 9a9b76d98..c40919d81 100644 --- a/spec/features/admin/translatable_spec.rb +++ b/spec/features/admin/translatable_spec.rb @@ -55,15 +55,15 @@ describe "Admin edit translatable records" do visit path - within_frame(0) { expect(page).to have_content "Content in English" } + expect(page).to have_ckeditor "Content", with: "Content in English" select "Español", from: :select_language - within_frame(0) { expect(page).to have_content "Contenido en español" } + expect(page).to have_ckeditor "Content", with: "Contenido en español" select "Français", from: :select_language - within_frame(0) { expect(page).to have_content "Contenu en Français" } + expect(page).to have_ckeditor "Content", with: "Contenu en Français" end end @@ -155,7 +155,7 @@ describe "Admin edit translatable records" do select "Français", from: :select_language - within_frame(0) { expect(page.text).to be_empty } + expect(page). to have_ckeditor "Description", with: "" end end @@ -237,7 +237,7 @@ describe "Admin edit translatable records" do select("Español", from: "locale-switcher") expect(page).to have_field "Respuesta", with: "Respuesta corregida" - within_frame(0) { expect(page).to have_content "Descripción corregida" } + expect(page).to have_ckeditor "Descripción", with: "Descripción corregida" end end diff --git a/spec/features/translatable_spec.rb b/spec/features/translatable_spec.rb index a750947fa..d075f1487 100644 --- a/spec/features/translatable_spec.rb +++ b/spec/features/translatable_spec.rb @@ -212,7 +212,7 @@ describe "Public area translatable records" do select "Español", from: "locale-switcher" expect(page).to have_field "Título del debate", with: "Título corregido" - within_frame(0) { expect(page).to have_content "Texto corregido" } + expect(page).to have_ckeditor "Texto inicial del debate", with: "Texto corregido" end end diff --git a/spec/support/matchers/have_ckeditor.rb b/spec/support/matchers/have_ckeditor.rb new file mode 100644 index 000000000..7e23245ec --- /dev/null +++ b/spec/support/matchers/have_ckeditor.rb @@ -0,0 +1,19 @@ +RSpec::Matchers.define :have_ckeditor do |label, with:| + match do + return false unless has_css?(".ckeditor", text: label) + + page.within(".ckeditor", text: label) do + within_frame(0) { has_content?(with) } + end + end + + failure_message do + if has_css?(".ckeditor", text: label) + text = page.within(".ckeditor", text: label) { within_frame(0) { page.text } } + + "expected to find visible CKEditor '#{label}' with '#{with}', but had '#{text}'" + else + "expected to find visible CKEditor '#{label}' but there were no matches." + end + end +end From 025923ac4eb6701f861baa5625542c7e9984b513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 10 Jul 2019 14:06:03 +0200 Subject: [PATCH 2/4] Set current locale as HTML language in all layouts The same way it's done in the application layout. Not doing so causes accessibility issues affecting screen reader users. --- app/views/layouts/admin.html.erb | 2 +- app/views/layouts/devise.html.erb | 2 +- app/views/layouts/mailer.html.erb | 2 +- app/views/layouts/management.html.erb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 0f9a82856..50f74a80c 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -1,5 +1,5 @@ - + <%= render "layouts/common_head", default_title: "Admin" %> diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index f2cb29bba..55916e678 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -1,5 +1,5 @@ - + <%= render "layouts/common_head", default_title: "Gobierno abierto" %> <%= render "layouts/meta_tags" %> diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb index a3911df41..6691fe4fb 100644 --- a/app/views/layouts/mailer.html.erb +++ b/app/views/layouts/mailer.html.erb @@ -1,5 +1,5 @@ - + <%= t("mailers.title") %> diff --git a/app/views/layouts/management.html.erb b/app/views/layouts/management.html.erb index 6f224b0c5..a3dc288f9 100644 --- a/app/views/layouts/management.html.erb +++ b/app/views/layouts/management.html.erb @@ -1,5 +1,5 @@ - + <%= render "layouts/common_head", default_title: "Management" %> From 6ef07f8a548108a0d352b589d2c320348a1a0b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 10 Jul 2019 15:36:01 +0200 Subject: [PATCH 3/4] Use `text_area` instead of `cktext_area` We're going to change CKEditor to an inline editor, and the "ckeditor" gem doesn't provide an option to do so. Since using `cktext_area` would automatically generate a "classic" iframe CKEditor, we need to use `text_area` and load the editor using JavaScript. Personally I prefer this option anyway. Note in the jQuery selector we need to use `textarea.html-area`; using just `.html-area` would fail if there's an error message associated to the textarea, since Rails will add the `.html-area` class to the error message. --- app/assets/javascripts/application.js | 2 ++ app/assets/javascripts/html_editor.js | 14 ++++++++++++++ app/views/admin/budget_investments/edit.html.erb | 4 ++-- app/views/admin/budget_phases/_form.html.erb | 14 ++++++++------ app/views/admin/dashboard/actions/_form.html.erb | 2 +- .../admin/legislation/homepages/_form.html.erb | 8 ++++---- .../legislation/milestones/_summary_form.html.erb | 2 +- app/views/admin/newsletters/_form.html.erb | 2 +- app/views/admin/poll/active_polls/_form.html.erb | 2 +- .../admin/poll/questions/answers/_form.html.erb | 2 +- .../admin/site_customization/pages/_form.html.erb | 3 +-- app/views/budgets/investments/_form.html.erb | 4 ++-- .../polls/_question_answer_fields.html.erb | 6 +++--- app/views/debates/_form.html.erb | 4 ++-- app/views/legislation/proposals/_form.html.erb | 4 ++-- app/views/proposals/_form.html.erb | 6 +++--- lib/consul_form_builder.rb | 2 +- 17 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 app/assets/javascripts/html_editor.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5ca18f609..359a273ff 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -55,6 +55,7 @@ //= require checkbox_toggle //= require markdown-it //= require markdown_editor +//= require html_editor //= require cocoon //= require answers //= require questions @@ -114,6 +115,7 @@ var initialize_modules = function() { App.SocialShare.initialize(); App.CheckboxToggle.initialize(); App.MarkdownEditor.initialize(); + App.HTMLEditor.initialize(); App.LegislationAdmin.initialize(); App.LegislationAllegations.initialize(); App.Legislation.initialize(); diff --git a/app/assets/javascripts/html_editor.js b/app/assets/javascripts/html_editor.js new file mode 100644 index 000000000..4325fa255 --- /dev/null +++ b/app/assets/javascripts/html_editor.js @@ -0,0 +1,14 @@ +(function() { + "use strict"; + App.HTMLEditor = { + initialize: function() { + $("textarea.html-area").each(function() { + if ($(this).hasClass("admin")) { + CKEDITOR.replace(this.name, { language: $("html").attr("lang"), toolbar: "admin", height: 500 }); + } else { + CKEDITOR.replace(this.name, { language: $("html").attr("lang") }); + } + }); + } + }; +}).call(this); diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index bb3acc7f1..da30985db 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -22,9 +22,9 @@
- <%= translations_form.cktext_area :description, + <%= translations_form.text_area :description, maxlength: Budget::Investment.description_max_length, - ckeditor: { language: I18n.locale } %> + class: "html-area" %>
<% end %> diff --git a/app/views/admin/budget_phases/_form.html.erb b/app/views/admin/budget_phases/_form.html.erb index a75ce79b8..5753603f1 100644 --- a/app/views/admin/budget_phases/_form.html.erb +++ b/app/views/admin/budget_phases/_form.html.erb @@ -23,17 +23,19 @@ <%= f.translatable_fields do |translations_form| %>
- <%= translations_form.cktext_area :description, - maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH, - hint: t("admin.budget_phases.edit.description_help_text") %> + <%= translations_form.text_area :description, + maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH, + class: "html-area", + hint: t("admin.budget_phases.edit.description_help_text") %>
- <%= translations_form.cktext_area :summary, - maxlength: Budget::Phase::SUMMARY_MAX_LENGTH, - hint: t("admin.budget_phases.edit.summary_help_text") %> + <%= translations_form.text_area :summary, + maxlength: Budget::Phase::SUMMARY_MAX_LENGTH, + class: "html-area", + hint: t("admin.budget_phases.edit.summary_help_text") %>
<% end %> diff --git a/app/views/admin/dashboard/actions/_form.html.erb b/app/views/admin/dashboard/actions/_form.html.erb index b80765e84..c2d150c41 100644 --- a/app/views/admin/dashboard/actions/_form.html.erb +++ b/app/views/admin/dashboard/actions/_form.html.erb @@ -32,7 +32,7 @@
- <%= f.cktext_area :description, ckeditor: { language: I18n.locale } %> + <%= f.text_area :description, class: "html-area" %>
diff --git a/app/views/admin/legislation/homepages/_form.html.erb b/app/views/admin/legislation/homepages/_form.html.erb index 2c2485cfe..fea2d3a5b 100644 --- a/app/views/admin/legislation/homepages/_form.html.erb +++ b/app/views/admin/legislation/homepages/_form.html.erb @@ -16,10 +16,10 @@ <%= f.translatable_fields do |translations_form| %>
- <%= translations_form.cktext_area :homepage, - language: I18n.locale, - ckeditor: { height: 500, toolbar: "admin" }, - hint: t("admin.legislation.processes.form.homepage_description") %> + <%= translations_form.text_area :homepage, + language: I18n.locale, + class: "html-area admin", + hint: t("admin.legislation.processes.form.homepage_description") %>
<% end %> diff --git a/app/views/admin/legislation/milestones/_summary_form.html.erb b/app/views/admin/legislation/milestones/_summary_form.html.erb index 3c4297049..6b708c8c4 100644 --- a/app/views/admin/legislation/milestones/_summary_form.html.erb +++ b/app/views/admin/legislation/milestones/_summary_form.html.erb @@ -7,7 +7,7 @@
<%= f.translatable_fields do |translations_form| %>
- <%= translations_form.cktext_area :milestones_summary, ckeditor: { language: I18n.locale } %> + <%= translations_form.text_area :milestones_summary, class: "html-area" %>
<% end %>
diff --git a/app/views/admin/newsletters/_form.html.erb b/app/views/admin/newsletters/_form.html.erb index a389a090d..a1c5f1abb 100644 --- a/app/views/admin/newsletters/_form.html.erb +++ b/app/views/admin/newsletters/_form.html.erb @@ -5,7 +5,7 @@ @newsletter[:segment_recipient]) %> <%= f.text_field :subject %> <%= f.text_field :from %> - <%= f.cktext_area :body, ckeditor: { language: I18n.locale } %> + <%= f.text_area :body, class: "html-area" %>
<%= f.submit class: "button success" %> diff --git a/app/views/admin/poll/active_polls/_form.html.erb b/app/views/admin/poll/active_polls/_form.html.erb index d3aeaedab..0911e09f1 100644 --- a/app/views/admin/poll/active_polls/_form.html.erb +++ b/app/views/admin/poll/active_polls/_form.html.erb @@ -8,7 +8,7 @@ <%= f.translatable_fields do |translations_form| %>
<%= t("admin.active_polls.form.description.help_text") %> - <%= translations_form.cktext_area :description, + <%= translations_form.text_area :description, class: "html-area", maxlength: ActivePoll.description_max_length %>
<% end %> diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 873ce5785..68114d2a6 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -15,7 +15,7 @@ <%= translations_form.text_field :title %>
- <%= translations_form.cktext_area :description, maxlength: Poll::Question.description_max_length %> + <%= translations_form.text_area :description, maxlength: Poll::Question.description_max_length, class: "html-area" %>
<% end %> diff --git a/app/views/admin/site_customization/pages/_form.html.erb b/app/views/admin/site_customization/pages/_form.html.erb index 72be1eacf..5a9475b03 100644 --- a/app/views/admin/site_customization/pages/_form.html.erb +++ b/app/views/admin/site_customization/pages/_form.html.erb @@ -47,8 +47,7 @@ <%= translations_form.text_field :subtitle %>
- <%= translations_form.cktext_area :content, - ckeditor: { language: I18n.locale, toolbar: "admin" } %> + <%= translations_form.text_area :content, class: "html-area admin" %>
<% end %> diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index c118611fd..330931d59 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -23,9 +23,9 @@
- <%= translations_form.cktext_area :description, + <%= translations_form.text_area :description, maxlength: Budget::Investment.description_max_length, - ckeditor: { language: I18n.locale } %> + class: "html-area" %>
<% end %> diff --git a/app/views/dashboard/polls/_question_answer_fields.html.erb b/app/views/dashboard/polls/_question_answer_fields.html.erb index 4f3dfae57..b3e6d9e4e 100644 --- a/app/views/dashboard/polls/_question_answer_fields.html.erb +++ b/app/views/dashboard/polls/_question_answer_fields.html.erb @@ -15,9 +15,9 @@
- <%= f.cktext_area :description, - maxlength: Poll::Question.description_max_length, - ckeditor: { language: I18n.locale } %> + <%= f.text_area :description, + maxlength: Poll::Question.description_max_length, + class: "html-area" %>
diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 38b4e2bcc..08b24eceb 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -17,9 +17,9 @@
- <%= translations_form.cktext_area :description, + <%= translations_form.text_area :description, maxlength: Debate.description_max_length, - ckeditor: { language: I18n.locale } %> + class: "html-area" %>
<% end %> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index d0c387482..e21a605f6 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -16,9 +16,9 @@
- <%= f.cktext_area :description, + <%= f.text_area :description, maxlength: Legislation::Proposal.description_max_length, - ckeditor: { language: I18n.locale } %> + class: "html-area" %>
diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 6f2a34e82..86f86e918 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -22,9 +22,9 @@
- <%= translations_form.cktext_area :description, - maxlength: Proposal.description_max_length, - ckeditor: { language: I18n.locale } %> + <%= translations_form.text_area :description, + maxlength: Proposal.description_max_length, + class: "html-area" %>
<% end %> diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index 86c84589f..33b0fc1af 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -9,7 +9,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder select attribute, choices, options, html_options end - %i[text_field text_area cktext_area number_field password_field email_field].each do |field| + %i[text_field text_area number_field password_field email_field].each do |field| define_method field do |attribute, options = {}| label_with_hint(attribute, options.merge(label_options: label_options_for(options))) + super(attribute, options.merge( From e844b0b2db6ff1d51c992f49c41b7cb158c5a715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 25 Oct 2019 17:00:18 +0200 Subject: [PATCH 4/4] Remove CKEditor divs This way the HTML does not depend on CKEditor, and changing the editor we use in textareas will require very few changes. --- app/assets/stylesheets/layout.scss | 4 ++-- .../admin/budget_investments/edit.html.erb | 2 +- app/views/admin/budget_phases/_form.html.erb | 20 +++++++---------- .../admin/dashboard/actions/_form.html.erb | 4 +--- .../legislation/homepages/_form.html.erb | 10 ++++----- .../milestones/_summary_form.html.erb | 2 +- .../admin/poll/active_polls/_form.html.erb | 2 +- .../poll/questions/answers/_form.html.erb | 2 +- .../site_customization/pages/_form.html.erb | 2 +- app/views/budgets/investments/_form.html.erb | 2 +- .../polls/_question_answer_fields.html.erb | 8 +++---- app/views/debates/_form.html.erb | 2 +- .../legislation/proposals/_form.html.erb | 2 +- app/views/proposals/_form.html.erb | 2 +- .../admin/site_customization/pages_spec.rb | 5 ++--- spec/support/matchers/have_ckeditor.rb | 22 ++++++++++++++----- 16 files changed, 46 insertions(+), 45 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index b7e0265dc..85a5a304f 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1072,8 +1072,8 @@ form { margin: $line-height / 2 0 $line-height / 2 $line-height / 4; } - .ckeditor { - min-height: $line-height * 13; + .cke { + margin-bottom: $line-height; } .checkbox, diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index da30985db..e7d36337f 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -21,7 +21,7 @@ maxlength: Budget::Investment.title_max_length %> -
+
<%= translations_form.text_area :description, maxlength: Budget::Investment.description_max_length, class: "html-area" %> diff --git a/app/views/admin/budget_phases/_form.html.erb b/app/views/admin/budget_phases/_form.html.erb index 5753603f1..f8e5cd964 100644 --- a/app/views/admin/budget_phases/_form.html.erb +++ b/app/views/admin/budget_phases/_form.html.erb @@ -22,21 +22,17 @@
<%= f.translatable_fields do |translations_form| %>
-
- <%= translations_form.text_area :description, - maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH, - class: "html-area", - hint: t("admin.budget_phases.edit.description_help_text") %> -
+ <%= translations_form.text_area :description, + maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH, + class: "html-area", + hint: t("admin.budget_phases.edit.description_help_text") %>
-
- <%= translations_form.text_area :summary, - maxlength: Budget::Phase::SUMMARY_MAX_LENGTH, - class: "html-area", - hint: t("admin.budget_phases.edit.summary_help_text") %> -
+ <%= translations_form.text_area :summary, + maxlength: Budget::Phase::SUMMARY_MAX_LENGTH, + class: "html-area", + hint: t("admin.budget_phases.edit.summary_help_text") %>
<% end %>
diff --git a/app/views/admin/dashboard/actions/_form.html.erb b/app/views/admin/dashboard/actions/_form.html.erb index c2d150c41..810726868 100644 --- a/app/views/admin/dashboard/actions/_form.html.erb +++ b/app/views/admin/dashboard/actions/_form.html.erb @@ -31,9 +31,7 @@ <%= f.text_field :short_description %>
-
- <%= f.text_area :description, class: "html-area" %> -
+ <%= f.text_area :description, class: "html-area" %>
diff --git a/app/views/admin/legislation/homepages/_form.html.erb b/app/views/admin/legislation/homepages/_form.html.erb index fea2d3a5b..a0758efed 100644 --- a/app/views/admin/legislation/homepages/_form.html.erb +++ b/app/views/admin/legislation/homepages/_form.html.erb @@ -15,12 +15,10 @@
<%= f.translatable_fields do |translations_form| %>
-
- <%= translations_form.text_area :homepage, - language: I18n.locale, - class: "html-area admin", - hint: t("admin.legislation.processes.form.homepage_description") %> -
+ <%= translations_form.text_area :homepage, + language: I18n.locale, + class: "html-area admin", + hint: t("admin.legislation.processes.form.homepage_description") %>
<% end %>
diff --git a/app/views/admin/legislation/milestones/_summary_form.html.erb b/app/views/admin/legislation/milestones/_summary_form.html.erb index 6b708c8c4..27442d377 100644 --- a/app/views/admin/legislation/milestones/_summary_form.html.erb +++ b/app/views/admin/legislation/milestones/_summary_form.html.erb @@ -6,7 +6,7 @@ <%= translatable_form_for [:admin, @process] do |f| %>
<%= f.translatable_fields do |translations_form| %> -
+
<%= translations_form.text_area :milestones_summary, class: "html-area" %>
<% end %> diff --git a/app/views/admin/poll/active_polls/_form.html.erb b/app/views/admin/poll/active_polls/_form.html.erb index 0911e09f1..5794b641f 100644 --- a/app/views/admin/poll/active_polls/_form.html.erb +++ b/app/views/admin/poll/active_polls/_form.html.erb @@ -6,7 +6,7 @@
<%= f.translatable_fields do |translations_form| %> -
+
<%= t("admin.active_polls.form.description.help_text") %> <%= translations_form.text_area :description, class: "html-area", maxlength: ActivePoll.description_max_length %> diff --git a/app/views/admin/poll/questions/answers/_form.html.erb b/app/views/admin/poll/questions/answers/_form.html.erb index 68114d2a6..53eceae17 100644 --- a/app/views/admin/poll/questions/answers/_form.html.erb +++ b/app/views/admin/poll/questions/answers/_form.html.erb @@ -14,7 +14,7 @@
<%= translations_form.text_field :title %>
-
+
<%= translations_form.text_area :description, maxlength: Poll::Question.description_max_length, class: "html-area" %>
<% end %> diff --git a/app/views/admin/site_customization/pages/_form.html.erb b/app/views/admin/site_customization/pages/_form.html.erb index 5a9475b03..b5a8b42c3 100644 --- a/app/views/admin/site_customization/pages/_form.html.erb +++ b/app/views/admin/site_customization/pages/_form.html.erb @@ -46,7 +46,7 @@
<%= translations_form.text_field :subtitle %>
-
+
<%= translations_form.text_area :content, class: "html-area admin" %>
<% end %> diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 330931d59..3eff59f72 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -22,7 +22,7 @@
-
+
<%= translations_form.text_area :description, maxlength: Budget::Investment.description_max_length, class: "html-area" %> diff --git a/app/views/dashboard/polls/_question_answer_fields.html.erb b/app/views/dashboard/polls/_question_answer_fields.html.erb index b3e6d9e4e..3cf81e8ee 100644 --- a/app/views/dashboard/polls/_question_answer_fields.html.erb +++ b/app/views/dashboard/polls/_question_answer_fields.html.erb @@ -14,11 +14,9 @@
-
- <%= f.text_area :description, - maxlength: Poll::Question.description_max_length, - class: "html-area" %> -
+ <%= f.text_area :description, + maxlength: Poll::Question.description_max_length, + class: "html-area" %>
diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 08b24eceb..155bb7da5 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -16,7 +16,7 @@
-
+
<%= translations_form.text_area :description, maxlength: Debate.description_max_length, class: "html-area" %> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index e21a605f6..9985bfa03 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -15,7 +15,7 @@ hint: t("proposals.form.proposal_summary_note") %>
-
+
<%= f.text_area :description, maxlength: Legislation::Proposal.description_max_length, class: "html-area" %> diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 86f86e918..eba35f60d 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -21,7 +21,7 @@ hint: t("proposals.form.proposal_summary_note") %>
-
+
<%= translations_form.text_area :description, maxlength: Proposal.description_max_length, class: "html-area" %> diff --git a/spec/features/admin/site_customization/pages_spec.rb b/spec/features/admin/site_customization/pages_spec.rb index 42042f028..3671ba64a 100644 --- a/spec/features/admin/site_customization/pages_spec.rb +++ b/spec/features/admin/site_customization/pages_spec.rb @@ -86,10 +86,9 @@ describe "Admin custom pages" do scenario "Allows images in CKEditor", :js do visit edit_admin_site_customization_page_path(custom_page) + fill_in_ckeditor "Content", with: "Will add an image" - within(".ckeditor") do - expect(page).to have_css(".cke_toolbar .cke_button__image_icon") - end + expect(page).to have_css(".cke_toolbar .cke_button__image_icon") end end diff --git a/spec/support/matchers/have_ckeditor.rb b/spec/support/matchers/have_ckeditor.rb index 7e23245ec..8072ad511 100644 --- a/spec/support/matchers/have_ckeditor.rb +++ b/spec/support/matchers/have_ckeditor.rb @@ -1,15 +1,27 @@ RSpec::Matchers.define :have_ckeditor do |label, with:| - match do - return false unless has_css?(".ckeditor", text: label) + define_method :textarea_id do + find("label", text: label)[:for] + end - page.within(".ckeditor", text: label) do + define_method :ckeditor_id do + "#cke_#{textarea_id}" + end + + define_method :has_ckeditor? do + has_css?("label", text: label) && has_css?(ckeditor_id) + end + + match do + return false unless has_ckeditor? + + page.within(ckeditor_id) do within_frame(0) { has_content?(with) } end end failure_message do - if has_css?(".ckeditor", text: label) - text = page.within(".ckeditor", text: label) { within_frame(0) { page.text } } + if has_ckeditor? + text = page.within(ckeditor_id) { within_frame(0) { page.text } } "expected to find visible CKEditor '#{label}' with '#{with}', but had '#{text}'" else