diff --git a/spec/components/budgets/executions/image_component_spec.rb b/spec/components/budgets/executions/image_component_spec.rb index a40d8d1ce..4cead4790 100644 --- a/spec/components/budgets/executions/image_component_spec.rb +++ b/spec/components/budgets/executions/image_component_spec.rb @@ -1,13 +1,50 @@ require "rails_helper" 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 - let(:component) { Budgets::Executions::ImageComponent.new(Budget::Investment.new) } + let(:investment) { Budget::Investment.new(title: "New and empty") } it "shows the default image" do 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 it "shows a custom default image when available" do @@ -18,7 +55,7 @@ describe Budgets::Executions::ImageComponent do 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']" end end diff --git a/spec/system/budgets/executions_spec.rb b/spec/system/budgets/executions_spec.rb index eb0044e78..88d21ec02 100644 --- a/spec/system/budgets/executions_spec.rb +++ b/spec/system/budgets/executions_spec.rb @@ -83,31 +83,6 @@ describe "Executions" do end 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 create(:milestone, milestoneable: investment4) @@ -116,23 +91,8 @@ describe "Executions" do click_link "See results" click_link "Milestones" - expect(page).to have_content(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']") + expect(page).to have_content investment4.title + expect(page).to have_css "img[alt='#{investment4.title}']" end end