Files
nairobi/spec/system/admin/site_customization/documents_spec.rb
Javi Martín 7c6134fdee Unify the way we display document information
We were displaying documents in five places, and in five different ways.
Sometimes with the metadata in parenthesis after the title, sometimes
with the metadata below the title, sometimes without metadata, sometimes
with an icon in front of the document, and sometimes with a separate
link to download the file.

So we're now displaying the same thing everywhere. Not sure whether this
is the best solution, but at least it's consistent.

We aren't unifying the way we display a list of documents, though, since
different sections look pretty different and I'm not sure whether the
same style would look well everywhere.

Note that we're renaming the `document` HTML class in the documents
table to `document-row` so the styles for the `document` class don't
apply here.
2023-10-23 18:15:54 +02:00

88 lines
2.4 KiB
Ruby

require "rails_helper"
describe "Documents", :admin do
scenario "Navigation" do
visit admin_root_path
within("#side_menu") do
click_link "Site content"
click_link "Custom documents"
end
expect(page).to have_link "Add new document",
href: new_admin_site_customization_document_path
end
scenario "Index" do
3.times { create(:document, :admin) }
1.times { create(:document) }
document = Document.first
url = polymorphic_path(document.attachment)
visit admin_site_customization_documents_path
expect(page).to have_content "There are 3 documents"
expect(page).to have_link "Download file", href: url
end
scenario "Index (empty)" do
visit admin_site_customization_documents_path
expect(page).to have_content "There are no documents."
end
scenario "Index (pagination)" do
per_page = 3
allow(Document).to receive(:default_per_page).and_return(per_page)
(per_page + 2).times { create(:document, :admin) }
visit admin_site_customization_documents_path
expect(page).to have_selector("#documents .document-row", count: per_page)
within("ul.pagination") do
expect(page).to have_content("1")
expect(page).to have_link("2", href: admin_site_customization_documents_path(page: 2))
expect(page).not_to have_content("3")
click_link "Next", exact: false
end
expect(page).to have_selector("#documents .document-row", count: 2)
end
scenario "Create" do
visit new_admin_site_customization_document_path
attach_file("document_attachment", file_fixture("logo.pdf"))
click_button "Upload"
expect(page).to have_content "Document uploaded successfully"
within("tr", text: "logo.pdf") { expect(page).to have_link "Download file" }
end
scenario "Errors on create" do
visit new_admin_site_customization_document_path
click_button "Upload"
expect(page).to have_content "Invalid document"
end
scenario "Destroy" do
document = create(:document, :admin)
visit admin_site_customization_documents_path
within("#document_#{document.id}") do
accept_confirm("Are you sure? This action will delete \"#{document.title}\" and can't be undone.") do
click_button "Delete"
end
end
expect(page).to have_content "Document deleted successfully"
expect(page).not_to have_content document.title
end
end