From 410caced3e145d9ef96919082664c96f1fbd9513 Mon Sep 17 00:00:00 2001 From: Vicente Mendoza Date: Tue, 23 Jan 2018 15:29:55 +0100 Subject: [PATCH 1/2] test added for changes at documentable's view --- app/assets/javascripts/documentable.js.coffee | 12 ++++++++---- app/helpers/documents_helper.rb | 2 +- app/views/documents/_nested_documents.html.erb | 2 +- config/locales/en/documents.yml | 1 + config/locales/es/documents.yml | 1 + spec/controllers/application_controller_spec.rb | 2 +- spec/shared/features/nested_documentable.rb | 7 +++++++ 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/documentable.js.coffee b/app/assets/javascripts/documentable.js.coffee index 7cc71f39d..a61458150 100644 --- a/app/assets/javascripts/documentable.js.coffee +++ b/app/assets/javascripts/documentable.js.coffee @@ -11,10 +11,9 @@ App.Documentable = $('#nested-documents').on 'cocoon:after-insert', (e, nested_document) -> input = $(nested_document).find('.js-document-attachment') + input["lockUpload"] = $(nested_document).closest('#nested-documents').find('.document:visible').length >= $('#nested-documents').data('max-documents-allowed') App.Documentable.initializeDirectUploadInput(input) - - if $(nested_document).closest('#nested-documents').find('.document:visible').length >= $('#nested-documents').data('max-documents-allowed') - App.Documentable.lockUploads() + App.Documentable.lockUploads() if input["lockUpload"] initializeDirectUploadInput: (input) -> @@ -65,6 +64,9 @@ App.Documentable = e.stopPropagation() App.Documentable.doDeleteCachedAttachmentRequest(this.href, data) + App.Documentable.showNotice() if input["lockUpload"] + + progress: (e, data) -> progress = parseInt(data.loaded / data.total * 100, 10) $(data.progressBar).find('.loading-bar').css 'width', progress + '%' @@ -114,13 +116,15 @@ App.Documentable = $(data.errorContainer).append(errors) lockUploads: -> - $('#max-documents-notice').removeClass('hide') $('#new_document_link').addClass('hide') unlockUploads: -> $('#max-documents-notice').addClass('hide') $('#new_document_link').removeClass('hide') + showNotice: -> + $('#max-documents-notice').removeClass('hide') + doDeleteCachedAttachmentRequest: (url, data) -> $.ajax type: "POST" diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index cbc94c9bb..4766de0aa 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -27,7 +27,7 @@ module DocumentsHelper remote: true, class: "delete remove-cached-attachment" else - link_to_remove_association t('documents.form.delete_button'), builder, class: "delete remove-document" + link_to_remove_association document.new_record? ? t('documents.form.cancel_button') : t('documents.form.delete_button') , builder, class: "delete remove-document" end end diff --git a/app/views/documents/_nested_documents.html.erb b/app/views/documents/_nested_documents.html.erb index 04fd4e8a2..a72cbe270 100644 --- a/app/views/documents/_nested_documents.html.erb +++ b/app/views/documents/_nested_documents.html.erb @@ -17,7 +17,7 @@ association_insertion_method: "append" } %> -
"> +
"> <%= t "documents.max_documents_allowed_reached_html" %>
diff --git a/config/locales/en/documents.yml b/config/locales/en/documents.yml index 7db70b25a..5d2c5d5ff 100644 --- a/config/locales/en/documents.yml +++ b/config/locales/en/documents.yml @@ -8,6 +8,7 @@ en: title_placeholder: Add a descriptive title for the document attachment_label: Choose document delete_button: Remove document + cancel_button: Cancelar note: "You can upload up to a maximum of %{max_documents_allowed} documents of following content types: %{accepted_content_types}, up to %{max_file_size} MB per file." add_new_document: Add new document actions: diff --git a/config/locales/es/documents.yml b/config/locales/es/documents.yml index 0e57897e6..c3c65eb86 100644 --- a/config/locales/es/documents.yml +++ b/config/locales/es/documents.yml @@ -8,6 +8,7 @@ es: title_placeholder: Añade un título descriptivo para el documento attachment_label: Selecciona un documento delete_button: Eliminar documento + cancel_button: Cancelar note: 'Puedes subir hasta un máximo de %{max_documents_allowed} documentos en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo.' add_new_document: Añadir nuevo documento actions: diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index f11068b65..53212032e 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -16,4 +16,4 @@ describe ApplicationController do end -end \ No newline at end of file +end diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 02dd1e54d..c5f29aac4 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -52,6 +52,13 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_link "Add new document" end + within "#nested-documents" do + find_all(".document input[type=file]", visible: true).each do |document| + attach_file(document, "spec/fixtures/files/empty.pdf", make_visible: true) + end + end + + expect(page).to have_content I18n.t 'documents.buttons.destroy_document' expect(page).to have_css ".max-documents-notice", visible: true end From c3327a5da0fa935536feda8bf2027ca53d4e6e4e Mon Sep 17 00:00:00 2001 From: Vicente Mendoza Date: Tue, 23 Jan 2018 16:44:45 +0100 Subject: [PATCH 2/2] rebase and fix test to attach max number of files --- spec/shared/features/nested_documentable.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index c5f29aac4..28c5a57d0 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -47,19 +47,12 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should show max documents warning when max documents allowed limit is reached", :js do login_as user_to_login visit send(path, arguments) - documentable.class.max_documents_allowed.times.each do - click_link "Add new document" + documentable_attach_new_file("spec/fixtures/files/empty.pdf") end - within "#nested-documents" do - find_all(".document input[type=file]", visible: true).each do |document| - attach_file(document, "spec/fixtures/files/empty.pdf", make_visible: true) - end - end - - expect(page).to have_content I18n.t 'documents.buttons.destroy_document' expect(page).to have_css ".max-documents-notice", visible: true + expect(page).to have_content 'Remove document' end scenario "Should hide max documents warning after any document removal", :js do @@ -70,7 +63,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na click_link "Add new document" end - all("a", text: "Remove document").last.click + all("a", text: "Cancel").last.click expect(page).to have_css ".max-documents-notice", visible: false end