Remove sleep from documentable shared feature specs. Use matchers able to wait new content to appear.

This commit is contained in:
Senén Rodero Rodríguez
2017-09-14 19:54:25 +02:00
parent 314b7d73f7
commit 60e91c7a24
3 changed files with 25 additions and 24 deletions

View File

@@ -13,8 +13,9 @@
id: document_nested_field_id(document, index, :cached_attachment) %> id: document_nested_field_id(document, index, :cached_attachment) %>
<%= label_tag :title, t("activerecord.attributes.document.title") %> <%= label_tag :title, t("activerecord.attributes.document.title") %>
<%= text_field_tag :title, <%= text_field_tag :title,
document.title, document.errors.has_key?(:attachment) ? "" : document.title,
name: document_nested_field_name(document, index, :title), name: document_nested_field_name(document, index, :title),
id: document_nested_field_id(document, index, :title), id: document_nested_field_id(document, index, :title),
class: "document-title" %> class: "document-title" %>

View File

@@ -2,7 +2,10 @@
<div class="small-12 column"> <div class="small-12 column">
<%= label_tag :document_title, t("activerecord.attributes.document.title") %> <%= label_tag :document_title, t("activerecord.attributes.document.title") %>
<%= text_field_tag :document_title, document.title, name: "document[title]", class: "document-title" %> <%= text_field_tag :document_title,
document.errors.has_key?(:attachment) ? "" : document.title,
name: "document[title]",
class: "document-title" %>
<% if document.errors.has_key?(:title) %> <% if document.errors.has_key?(:title) %>
<small class="error"><%= document.errors[:title].join(", ") %></small> <small class="error"><%= document.errors[:title].join(", ") %></small>
<% end %> <% end %>

View File

@@ -179,7 +179,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true
sleep 1
expect(page).to have_content "empty.pdf" expect(page).to have_content "empty.pdf"
end end
@@ -189,8 +188,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/logo_header.png", make_visible: true attach_document("spec/fixtures/files/logo_header.png", false)
sleep 1
expect(page).not_to have_content "logo_header.jpg" expect(page).not_to have_content "logo_header.jpg"
end end
@@ -200,8 +198,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true attach_document("spec/fixtures/files/empty.pdf", true)
sleep 1
expect(page).to have_selector ".loading-bar.complete" expect(page).to have_selector ".loading-bar.complete"
end end
@@ -211,8 +208,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/logo_header.png", make_visible: true attach_document("spec/fixtures/files/logo_header.png", false)
sleep 1
expect(page).to have_selector ".loading-bar.errors" expect(page).to have_selector ".loading-bar.errors"
end end
@@ -222,10 +218,9 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true attach_document("spec/fixtures/files/empty.pdf", true)
sleep 1
expect(find("input[name='document[title]']").value).to eq("empty.pdf") expect(page).to have_css("input[name='document[title]'][value='empty.pdf']")
end end
scenario "Should not update document title with attachment original file name after file selection when title already defined by user", :js do scenario "Should not update document title with attachment original file name after file selection when title already defined by user", :js do
@@ -234,8 +229,7 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
documentable_id: documentable.id) documentable_id: documentable.id)
fill_in :document_title, with: "My custom title" fill_in :document_title, with: "My custom title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true attach_document("spec/fixtures/files/empty.pdf", true)
sleep 1
expect(find("input[name='document[title]']").value).to eq("My custom title") expect(find("input[name='document[title]']").value).to eq("My custom title")
end end
@@ -245,10 +239,9 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true attach_document("spec/fixtures/files/empty.pdf", true)
sleep 1
expect(find("input[name='document[cached_attachment]']", visible: false).value).to include("empty.pdf") expect(page).to have_css("input[name='document[cached_attachment]'][value$='empty.pdf']", visible: false)
end end
scenario "Should not show 'Choose document' button after valid upload", :js do scenario "Should not show 'Choose document' button after valid upload", :js do
@@ -291,10 +284,9 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,
documentable_id: documentable.id) documentable_id: documentable.id)
attach_file :document_attachment, "spec/fixtures/files/logo_header.png", make_visible: true attach_document("spec/fixtures/files/logo_header.png", false)
sleep 1
expect(find("input[name='document[cached_attachment]']", visible: false).value).to eq "" expect(find("input[name='document[cached_attachment]']", visible: false).value).to eq("")
end end
scenario "Should show documentable custom recomentations" do scenario "Should show documentable custom recomentations" do
@@ -330,7 +322,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
documentable_id: documentable.id, documentable_id: documentable.id,
from: send(documentable_path, arguments)) from: send(documentable_path, arguments))
attach_file :document_attachment, "spec/fixtures/files/empty.pdf" attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
sleep 1
click_on "Upload document" click_on "Upload document"
expect(page).to have_content "Cannot create document. Check form errors and try again." expect(page).to have_content "Cannot create document. Check form errors and try again."
@@ -344,7 +335,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
from: send(documentable_path, arguments)) from: send(documentable_path, arguments))
fill_in :document_title, with: "Document title" fill_in :document_title, with: "Document title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf" attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
sleep 1
click_on "Upload document" click_on "Upload document"
expect(page).to have_content "Document was created successfully." expect(page).to have_content "Document was created successfully."
@@ -358,7 +348,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
from: send(documentable_path, arguments)) from: send(documentable_path, arguments))
fill_in :document_title, with: "Document title" fill_in :document_title, with: "Document title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf" attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
sleep 1
click_on "Upload document" click_on "Upload document"
within "##{dom_id(documentable)}" do within "##{dom_id(documentable)}" do
@@ -374,7 +363,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
from: send(documentable_path, arguments)) from: send(documentable_path, arguments))
fill_in :document_title, with: "Document title" fill_in :document_title, with: "Document title"
attach_file :document_attachment, "spec/fixtures/files/empty.pdf" attach_file :document_attachment, "spec/fixtures/files/empty.pdf"
sleep 1
click_on "Upload document" click_on "Upload document"
expect(page).to have_link "Documents (1)" expect(page).to have_link "Documents (1)"
@@ -437,3 +425,12 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
end end
end end
def attach_document(path, success = true)
attach_file :document_attachment, path, make_visible: true
if success
have_css ".loading-bar.complete"
else
have_css ".loading-bar.errors"
end
end