Files
grecia/spec/system/admin/poll/questions/answers/images/images_spec.rb
Javi Martín 92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00

65 lines
1.8 KiB
Ruby

require "rails_helper"
describe "Images", :admin do
it_behaves_like "nested imageable",
"poll_question_answer",
"new_admin_answer_image_path",
{ "answer_id": "id" },
nil,
"Save image",
"Image uploaded successfully",
true
context "Index" do
scenario "Answer with no images" do
answer = create(:poll_question_answer)
visit admin_answer_images_path(answer)
expect(page).not_to have_css("img[title='']")
end
scenario "Answer with images" do
answer = create(:poll_question_answer)
image = create(:image, imageable: answer)
visit admin_answer_images_path(answer)
expect(page).to have_css("img[title='#{image.title}']")
expect(page).to have_content(image.title)
end
end
scenario "Add image to answer" do
answer = create(:poll_question_answer)
image = create(:image)
visit admin_answer_images_path(answer)
expect(page).not_to have_css("img[title='clippy.jpg']")
expect(page).not_to have_content("clippy.jpg")
visit new_admin_answer_image_path(answer)
imageable_attach_new_file(image, Rails.root.join("spec/fixtures/files/clippy.jpg"))
click_button "Save image"
expect(page).to have_css("img[title='clippy.jpg']")
expect(page).to have_content("clippy.jpg")
end
scenario "Remove image from answer" do
answer = create(:poll_question_answer)
image = create(:image, imageable: answer)
visit admin_answer_images_path(answer)
expect(page).to have_css("img[title='#{image.title}']")
expect(page).to have_content(image.title)
accept_confirm "Are you sure?" do
click_link "Remove image"
end
expect(page).not_to have_css("img[title='#{image.title}']")
expect(page).not_to have_content(image.title)
end
end