From a8bd5eb19289552e8502e70bd7154a6752e7c209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 12 Oct 2023 21:38:08 +0200 Subject: [PATCH] Rename document/image fields HTML classes Using the `document` or `documents` classes meant styles defined for the public list of documents conflict with these ones. So now we're using HTML classes that match the name of the Ruby component classes, as we usually do. --- app/assets/javascripts/documentable.js | 6 ++++-- app/assets/javascripts/imageable.js | 2 +- .../stylesheets/admin/budget_phases/form.scss | 2 +- app/assets/stylesheets/mixins/uploads.scss | 4 ++-- .../attachable/fields_component.html.erb | 2 +- app/components/documents/nested_component.html.erb | 2 +- app/components/images/nested_component.html.erb | 2 +- spec/shared/system/nested_documentable.rb | 10 +++++----- spec/shared/system/nested_imageable.rb | 14 +++++++------- spec/support/common_actions/documents.rb | 4 ++-- spec/support/common_actions/images.rb | 4 ++-- 11 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/documentable.js b/app/assets/javascripts/documentable.js index 3a2880da5..2a6829f5c 100644 --- a/app/assets/javascripts/documentable.js +++ b/app/assets/javascripts/documentable.js @@ -9,9 +9,11 @@ App.Documentable.unlockUploads(); }); $("#nested-documents").on("cocoon:after-insert", function(e, nested_document) { - var input; + var input, document_fields; input = $(nested_document).find(".js-document-attachment"); - input.lockUpload = $(nested_document).closest("#nested-documents").find(".document:visible").length >= $("#nested-documents").data("max-documents-allowed"); + document_fields = $(nested_document).closest("#nested-documents").find(".document-fields:visible"); + + input.lockUpload = document_fields.length >= $("#nested-documents").data("max-documents-allowed"); App.Documentable.initializeDirectUploadInput(input); if (input.lockUpload) { App.Documentable.lockUploads(); diff --git a/app/assets/javascripts/imageable.js b/app/assets/javascripts/imageable.js index 84ad8ce8f..82189d081 100644 --- a/app/assets/javascripts/imageable.js +++ b/app/assets/javascripts/imageable.js @@ -9,7 +9,7 @@ $("#new_image_link").removeClass("hide"); }); $("#nested-image").on("cocoon:before-insert", function() { - $(".js-image-attachment").closest(".image").remove(); + $(".js-image-attachment").closest(".image-fields").remove(); }); $("#nested-image").on("cocoon:after-insert", function(e, nested_image) { var input; diff --git a/app/assets/stylesheets/admin/budget_phases/form.scss b/app/assets/stylesheets/admin/budget_phases/form.scss index 693077b38..4faa8ffd0 100644 --- a/app/assets/stylesheets/admin/budget_phases/form.scss +++ b/app/assets/stylesheets/admin/budget_phases/form.scss @@ -23,7 +23,7 @@ } } - .images { + .images-nested { @include direct-uploads; } diff --git a/app/assets/stylesheets/mixins/uploads.scss b/app/assets/stylesheets/mixins/uploads.scss index 04db8ad91..fa5fdbf70 100644 --- a/app/assets/stylesheets/mixins/uploads.scss +++ b/app/assets/stylesheets/mixins/uploads.scss @@ -10,8 +10,8 @@ margin-bottom: $line-height; } - .document, - .image { + .document-fields, + .image-fields { .document-attachment, .image-attachment { diff --git a/app/components/attachable/fields_component.html.erb b/app/components/attachable/fields_component.html.erb index e5e9854a6..d51997e53 100644 --- a/app/components/attachable/fields_component.html.erb +++ b/app/components/attachable/fields_component.html.erb @@ -1,4 +1,4 @@ -
+
<%= f.hidden_field :id %> <%= f.hidden_field :user_id, value: current_user.id %> <%= f.hidden_field :cached_attachment %> diff --git a/app/components/documents/nested_component.html.erb b/app/components/documents/nested_component.html.erb index d47185ae8..8d3bc2c63 100644 --- a/app/components/documents/nested_component.html.erb +++ b/app/components/documents/nested_component.html.erb @@ -1,4 +1,4 @@ -
+
<%= t("documents.form.title") %>

<%= note %>

diff --git a/app/components/images/nested_component.html.erb b/app/components/images/nested_component.html.erb index 578cb53fe..58889a02c 100644 --- a/app/components/images/nested_component.html.erb +++ b/app/components/images/nested_component.html.erb @@ -1,4 +1,4 @@ -
+
<%= t("images.form.title") %>

<%= note %>

diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index d21c380ef..f73ab60e6 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -163,7 +163,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_link "Add new document" click_on submit_button - within "#nested-documents .document" do + within "#nested-documents .document-fields" do expect(page).to have_content("can't be blank", count: 2) end end @@ -175,7 +175,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na documentable_attach_new_file(file_fixture("empty.pdf")) click_link "Remove document" - expect(page).not_to have_css("#nested-documents .document") + expect(page).not_to have_css("#nested-documents .document-fields") end scenario "Should show successful notice when @@ -248,7 +248,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na do_login_for user_to_login, management: management visit send(path, arguments) - expect(page).to have_css ".document", count: 1 + expect(page).to have_css ".document-fields", count: 1 end scenario "Should not show add document button when @@ -264,7 +264,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) do_login_for user_to_login, management: management visit send(path, arguments) - last_document = all("#nested-documents .document").last + last_document = all("#nested-documents .document-fields").last within last_document do click_on "Remove document" end @@ -278,7 +278,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na visit send(path, arguments) click_on "Remove document" - expect(page).not_to have_css ".document" + expect(page).not_to have_css ".document-fields" end scenario "Same attachment URL after editing the title" do diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index ca49a42d7..f055e055c 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -57,7 +57,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) click_link "Add image" - input_title = find(".image input[name$='[title]']") + input_title = find(".image-fields input[name$='[title]']") fill_in input_title[:id], with: "Title" attach_file "Choose image", file_fixture("clippy.jpg") @@ -119,7 +119,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p click_link "Add image" click_on submit_button - within "#nested-image .image" do + within "#nested-image .image-fields" do expect(page).to have_content("can't be blank", count: 2) end end @@ -143,11 +143,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p imageable_attach_new_file(file_fixture("clippy.jpg")) - within "#nested-image .image" do + within "#nested-image .image-fields" do click_link "Remove image" end - expect(page).not_to have_selector("#nested-image .image") + expect(page).not_to have_selector("#nested-image .image-fields") end scenario "Should show successful notice when resource filled correctly without any nested images", @@ -216,7 +216,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) - expect(page).to have_css ".image", count: 1 + expect(page).to have_css ".image-fields", count: 1 expect(page).not_to have_css "a#new_image_link" end @@ -227,7 +227,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p visit send(path, arguments) click_link "Remove image" - expect(page).not_to have_css ".image" + expect(page).not_to have_css ".image-fields" expect(page).to have_link id: "new_image_link" end @@ -239,7 +239,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p click_link "Remove image" click_link "Add image" - expect(page).to have_css ".image", count: 1, visible: :all + expect(page).to have_css ".image-fields", count: 1, visible: :all end end end diff --git a/spec/support/common_actions/documents.rb b/spec/support/common_actions/documents.rb index c6b8e0b44..e7752ad84 100644 --- a/spec/support/common_actions/documents.rb +++ b/spec/support/common_actions/documents.rb @@ -9,7 +9,7 @@ module Documents def documentable_attach_new_file(path, success = true) click_link "Add new document" - document = all(".document").last + document = all(".document-fields").last attach_file "Choose document", path within document do @@ -22,7 +22,7 @@ module Documents end def expect_document_has_title(index, title) - document = all(".document")[index] + document = all(".document-fields")[index] within document do expect(find("input[name$='[title]']").value).to eq title diff --git a/spec/support/common_actions/images.rb b/spec/support/common_actions/images.rb index 8f372be43..1c7a248e1 100644 --- a/spec/support/common_actions/images.rb +++ b/spec/support/common_actions/images.rb @@ -11,7 +11,7 @@ module Images def imageable_attach_new_file(path, success = true) click_link "Add image" within "#nested-image" do - image = find(".image") + image = find(".image-fields") attach_file "Choose image", path within image do if success @@ -40,7 +40,7 @@ module Images end def expect_image_has_title(title) - image = find(".image") + image = find(".image-fields") within image do expect(find("input[name$='[title]']").value).to eq title