Move executions images system tests to the component

We forgot to do so in commit f0ab7bcfc. We're still leaving one system
spec to test that these images are rendered when browsing the site.

We're also changing the existing component tests to check the `alt`
attribute, just like the remaining system test does.
This commit is contained in:
Javi Martín
2024-10-29 01:46:58 +01:00
parent 75b03791b1
commit 10cdfadb9b
2 changed files with 42 additions and 45 deletions

View File

@@ -1,13 +1,50 @@
require "rails_helper" require "rails_helper"
describe Budgets::Executions::ImageComponent do describe Budgets::Executions::ImageComponent do
let(:component) { Budgets::Executions::ImageComponent.new(investment) }
context "investment with image" do
let(:investment) { create(:budget_investment, :with_image) }
it "shows a milestone image if available" do
create(:milestone, :with_image, image_title: "Building in progress", milestoneable: investment)
render_inline component
expect(page).to have_css "img[alt='Building in progress']"
expect(page).not_to have_css "img[alt='#{investment.image.title}']"
end
it "shows the investment image if no milestone image is available" do
create(:milestone, :with_image, image_title: "Not related", milestoneable: create(:budget_investment))
render_inline component
expect(page).to have_css "img[alt='#{investment.image.title}']"
expect(page).not_to have_css "img[alt='Not related']"
end
it "shows the last milestone's image if the investment has multiple milestones with images associated" do
create(:milestone, milestoneable: investment)
create(:milestone, :with_image, image_title: "First image", milestoneable: investment)
create(:milestone, :with_image, image_title: "Second image", milestoneable: investment)
create(:milestone, milestoneable: investment)
render_inline component
expect(page).to have_css "img[alt='Second image']"
expect(page).not_to have_css "img[alt='First image']"
expect(page).not_to have_css "img[alt='#{investment.image.title}']"
end
end
context "investment and milestone without image" do context "investment and milestone without image" do
let(:component) { Budgets::Executions::ImageComponent.new(Budget::Investment.new) } let(:investment) { Budget::Investment.new(title: "New and empty") }
it "shows the default image" do it "shows the default image" do
render_inline component render_inline component
expect(page).to have_css "img[src*='budget_execution_no_image']" expect(page).to have_css "img[src*='budget_execution_no_image'][alt='New and empty']"
end end
it "shows a custom default image when available" do it "shows a custom default image when available" do
@@ -18,7 +55,7 @@ describe Budgets::Executions::ImageComponent do
render_inline component render_inline component
expect(page).to have_css "img[src$='logo_header-260x80.png']" expect(page).to have_css "img[src$='logo_header-260x80.png'][alt='New and empty']"
expect(page).not_to have_css "img[src*='budget_execution_no_image']" expect(page).not_to have_css "img[src*='budget_execution_no_image']"
end end
end end

View File

@@ -83,31 +83,6 @@ describe "Executions" do
end end
context "Images" do context "Images" do
scenario "renders milestone image if available" do
milestone1 = create(:milestone, :with_image, milestoneable: investment1)
visit budget_path(budget)
click_link "See results"
click_link "Milestones"
expect(page).to have_content(investment1.title)
expect(page).to have_css("img[alt='#{milestone1.image.title}']")
end
scenario "renders investment image if no milestone image is available" do
create(:milestone, milestoneable: investment2)
create(:image, imageable: investment2)
visit budget_path(budget)
click_link "See results"
click_link "Milestones"
expect(page).to have_content(investment2.title)
expect(page).to have_css("img[alt='#{investment2.image.title}']")
end
scenario "renders default image if no milestone nor investment images are available" do scenario "renders default image if no milestone nor investment images are available" do
create(:milestone, milestoneable: investment4) create(:milestone, milestoneable: investment4)
@@ -116,23 +91,8 @@ describe "Executions" do
click_link "See results" click_link "See results"
click_link "Milestones" click_link "Milestones"
expect(page).to have_content(investment4.title) expect(page).to have_content investment4.title
expect(page).to have_css("img[alt='#{investment4.title}']") expect(page).to have_css "img[alt='#{investment4.title}']"
end
scenario "renders last milestone's image if investment has multiple milestones with images associated" do
create(:milestone, milestoneable: investment1)
create(:milestone, :with_image, image_title: "First image", milestoneable: investment1)
create(:milestone, :with_image, image_title: "Second image", milestoneable: investment1)
create(:milestone, milestoneable: investment1)
visit budget_path(budget)
click_link "See results"
click_link "Milestones"
expect(page).to have_content(investment1.title)
expect(page).to have_css("img[alt='Second image']")
end end
end end