Extract dashboard_action from shared nested documentable spec to system specs
Removed 'documentable_path_arguments' and 'management' parameters because they are not used by dashboard_action. Also moved and renamed the 'documentable_fill_new_valid_dashboard_action' method from the common actions helper to this file, since it is now only used here. Hardcoded 'path', 'submit_button_text', and 'notice_text' for dashboard_action. These remain fixed for now until dynamic values are required in future commits.
This commit is contained in:
@@ -201,8 +201,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
|||||||
expect(page).to have_content documentable_success_notice
|
expect(page).to have_content documentable_success_notice
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Should show new document after successful creation with one uploaded file",
|
scenario "Should show new document after successful creation with one uploaded file" do
|
||||||
unless: documentable_factory_name == "dashboard_action" do
|
|
||||||
do_login_for user_to_login, management: management
|
do_login_for user_to_login, management: management
|
||||||
visit send(path, arguments)
|
visit send(path, arguments)
|
||||||
send(fill_resource_method_name) if fill_resource_method_name
|
send(fill_resource_method_name) if fill_resource_method_name
|
||||||
@@ -223,7 +222,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Should show resource with new document after successful creation with
|
scenario "Should show resource with new document after successful creation with
|
||||||
maximum allowed uploaded files", unless: documentable_factory_name == "dashboard_action" do
|
maximum allowed uploaded files" do
|
||||||
do_login_for user_to_login, management: management
|
do_login_for user_to_login, management: management
|
||||||
visit send(path, arguments)
|
visit send(path, arguments)
|
||||||
|
|
||||||
|
|||||||
@@ -35,11 +35,6 @@ module Documents
|
|||||||
check :proposal_terms_of_service
|
check :proposal_terms_of_service
|
||||||
end
|
end
|
||||||
|
|
||||||
def documentable_fill_new_valid_dashboard_action
|
|
||||||
fill_in :dashboard_action_title, with: "Dashboard title"
|
|
||||||
fill_in_ckeditor "Description", with: "Dashboard description"
|
|
||||||
end
|
|
||||||
|
|
||||||
def documentable_fill_new_valid_budget_investment
|
def documentable_fill_new_valid_budget_investment
|
||||||
fill_in_new_investment_title with: "Budget investment title"
|
fill_in_new_investment_title with: "Budget investment title"
|
||||||
fill_in_ckeditor "Description", with: "Budget investment description"
|
fill_in_ckeditor "Description", with: "Budget investment description"
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "Admin dashboard actions", :admin do
|
describe "Admin dashboard actions", :admin do
|
||||||
it_behaves_like "nested documentable",
|
|
||||||
"administrator",
|
|
||||||
"dashboard_action",
|
|
||||||
"new_admin_dashboard_action_path",
|
|
||||||
{},
|
|
||||||
"documentable_fill_new_valid_dashboard_action",
|
|
||||||
"Save",
|
|
||||||
"Action created successfully"
|
|
||||||
|
|
||||||
context "when visiting index" do
|
context "when visiting index" do
|
||||||
context "and no actions defined" do
|
context "and no actions defined" do
|
||||||
before do
|
before do
|
||||||
|
|||||||
213
spec/system/nested_documentable_spec.rb
Normal file
213
spec/system/nested_documentable_spec.rb
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe "Nested documentable" do
|
||||||
|
factories = [
|
||||||
|
:dashboard_action
|
||||||
|
]
|
||||||
|
|
||||||
|
let(:factory) { factories.sample }
|
||||||
|
let!(:documentable) { create(factory) }
|
||||||
|
let!(:user) { create(:administrator).user }
|
||||||
|
let(:path) { new_admin_dashboard_action_path }
|
||||||
|
let(:submit_button_text) { "Save" }
|
||||||
|
let(:notice_text) { "Action created successfully" }
|
||||||
|
|
||||||
|
context "New path" do
|
||||||
|
describe "When allow attached documents setting is enabled" do
|
||||||
|
scenario "Should show new document link when max documents allowed limit is not reached" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
expect(page).to have_link "Add new document"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not show new document link when
|
||||||
|
documentable max documents allowed limit is reached" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable.class.max_documents_allowed.times.each do
|
||||||
|
click_link "Add new document"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).not_to have_css "#new_document_link"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not show max documents warning when no documents added" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
expect(page).not_to have_css ".max-documents-notice"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should show max documents warning when max documents allowed limit is reached" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable.class.max_documents_allowed.times.each do
|
||||||
|
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css ".max-documents-notice"
|
||||||
|
expect(page).to have_content "Remove document"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should hide max documents warning after any document removal" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable.class.max_documents_allowed.times.each do
|
||||||
|
click_link "Add new document"
|
||||||
|
end
|
||||||
|
|
||||||
|
all("a", text: "Cancel").last.click
|
||||||
|
|
||||||
|
expect(page).not_to have_css ".max-documents-notice"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should update nested document file name after choosing a file" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
click_link "Add new document"
|
||||||
|
within "#nested-documents" do
|
||||||
|
attach_file "Choose document", file_fixture("empty.pdf")
|
||||||
|
|
||||||
|
expect(page).to have_css ".loading-bar.complete"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css ".file-name", text: "empty.pdf"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should update nested document file title with
|
||||||
|
file name after choosing a file when no title defined" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||||
|
|
||||||
|
expect_document_has_title(0, "empty.pdf")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not update nested document file title with
|
||||||
|
file name after choosing a file when title already defined" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
click_link "Add new document"
|
||||||
|
within "#nested-documents" do
|
||||||
|
input = find("input[name$='[title]']")
|
||||||
|
fill_in input[:id], with: "My Title"
|
||||||
|
attach_file "Choose document", file_fixture("empty.pdf")
|
||||||
|
|
||||||
|
expect(page).to have_css ".loading-bar.complete"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect_document_has_title(0, "My Title")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should update loading bar style after valid file upload" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||||
|
|
||||||
|
expect(page).to have_css ".loading-bar.complete"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should update loading bar style after invalid file upload" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
|
||||||
|
|
||||||
|
expect(page).to have_css ".loading-bar.errors"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should update document cached_attachment field after valid file upload" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
click_link "Add new document"
|
||||||
|
|
||||||
|
cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden)
|
||||||
|
expect(cached_attachment_field.value).to be_empty
|
||||||
|
|
||||||
|
attach_file "Choose document", file_fixture("empty.pdf")
|
||||||
|
|
||||||
|
expect(page).to have_css(".loading-bar.complete")
|
||||||
|
expect(cached_attachment_field.value).not_to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not update document cached_attachment field after invalid file upload" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
|
||||||
|
|
||||||
|
cached_attachment_field = find("input[name$='[cached_attachment]']", visible: :hidden)
|
||||||
|
expect(cached_attachment_field.value).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should show document errors after documentable submit with empty document fields" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
click_link "Add new document"
|
||||||
|
click_button submit_button_text
|
||||||
|
|
||||||
|
within "#nested-documents .document-fields" do
|
||||||
|
expect(page).to have_content("can't be blank", count: 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should delete document after valid file upload and click on remove button" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||||
|
click_link "Remove document"
|
||||||
|
|
||||||
|
expect(page).not_to have_css("#nested-documents .document-fields")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should show successful notice when resource filled correctly without any nested documents" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
fill_dashboard_action
|
||||||
|
click_button submit_button_text
|
||||||
|
|
||||||
|
expect(page).to have_content notice_text
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should show successful notice when resource filled correctly and after valid file uploads" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
fill_dashboard_action
|
||||||
|
|
||||||
|
documentable_attach_new_file(file_fixture("empty.pdf"))
|
||||||
|
click_button submit_button_text
|
||||||
|
|
||||||
|
expect(page).to have_content notice_text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "When allow attached documents setting is disabled" do
|
||||||
|
before { Setting["feature.allow_attached_documents"] = false }
|
||||||
|
|
||||||
|
scenario "Add new document button should not be available" do
|
||||||
|
login_as user
|
||||||
|
visit path
|
||||||
|
|
||||||
|
expect(page).not_to have_content("Add new document")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def fill_dashboard_action
|
||||||
|
fill_in :dashboard_action_title, with: "Dashboard title"
|
||||||
|
fill_in_ckeditor "Description", with: "Dashboard description"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user