diff --git a/app/components/admin/budgets/links_component.html.erb b/app/components/admin/budgets/links_component.html.erb index db6b436bd..8fa1ce144 100644 --- a/app/components/admin/budgets/links_component.html.erb +++ b/app/components/admin/budgets/links_component.html.erb @@ -1,9 +1,9 @@ diff --git a/app/components/admin/budgets/links_component.rb b/app/components/admin/budgets/links_component.rb index 909a4002b..a84273420 100644 --- a/app/components/admin/budgets/links_component.rb +++ b/app/components/admin/budgets/links_component.rb @@ -19,4 +19,12 @@ class Admin::Budgets::LinksComponent < ApplicationComponent t("admin.budgets.actions.preview_results") end end + + def preview_text + if budget.published? + t("admin.shared.view") + else + t("admin.budgets.actions.preview") + end + end end diff --git a/spec/components/admin/budgets/links_component_spec.rb b/spec/components/admin/budgets/links_component_spec.rb index 18968f515..6648260a3 100644 --- a/spec/components/admin/budgets/links_component_spec.rb +++ b/spec/components/admin/budgets/links_component_spec.rb @@ -44,6 +44,8 @@ describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do expect(page).to have_link "Preview results" expect(page).not_to have_link "See results" + expect(page).not_to have_link "View" + expect(page).not_to have_link "Preview" end it "is not shown while balloting" do @@ -56,4 +58,24 @@ describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do end end end + + describe "preview/view link" do + it "shows a link to preview an unpublished budget" do + budget = create(:budget, :drafting) + + render_inline Admin::Budgets::LinksComponent.new(budget) + + expect(page).to have_link "Preview" + expect(page).not_to have_link "View" + end + + it "shows a link to view a published budget" do + budget = create(:budget, :informing) + + render_inline Admin::Budgets::LinksComponent.new(budget) + + expect(page).to have_link "View" + expect(page).not_to have_link "Preview" + end + end end diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index cb0620543..fd37d0262 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -115,13 +115,12 @@ describe "Admin budgets", :admin do scenario "Can preview budget before it is published" do visit admin_budget_path(budget) + click_link "Preview" - within_window(window_opened_by { click_link "Preview" }) do - expect(page).to have_current_path budget_path(budget) - end + expect(page).to have_current_path budget_path(budget) end - scenario "Can preview a budget after it is published" do + scenario "Can view a budget after it is published" do visit admin_budget_path(budget) accept_confirm { click_button "Publish budget" } @@ -130,9 +129,9 @@ describe "Admin budgets", :admin do expect(page).not_to have_content "This participatory budget is in draft mode" expect(page).not_to have_button "Publish budget" - within_window(window_opened_by { click_link "Preview" }) do - expect(page).to have_current_path budget_path(budget) - end + click_link "View" + + expect(page).to have_current_path budget_path(budget) end end