Render link to budget header

- Allow to define a link (text and url) on budget form for render on the budget
header.
- Improve styles

Co-authored-by: Senén Rodero Rodríguez <senenrodero@gmail.com>
This commit is contained in:
decabeza
2021-05-06 12:20:50 +02:00
committed by taitus
parent 090f1bcddb
commit d78f2e03ad
17 changed files with 130 additions and 12 deletions

View File

@@ -21,6 +21,22 @@ describe Budgets::BudgetComponent, type: :component do
expect(page).to have_link("Help with participatory budgets")
end
end
it "shows budget main link when defined" do
render_inline Budgets::BudgetComponent.new(budget)
within(".budget-header") do
expect(page).not_to have_css("a.main-link")
end
budget.update!(main_link_text: "Partitipate now!", main_link_url: "https://consulproject.org")
render_inline Budgets::BudgetComponent.new(budget)
within(".budget-header") do
expect(page).to have_css("a.main-link", text: "Participate now!", href: "https://consulproject.org")
end
end
end
describe "map" do

View File

@@ -114,6 +114,29 @@ describe Budget do
end
end
describe "main_link_url" do
it "is not required if main_link_text is not provided" do
valid_budget = build(:budget, main_link_text: nil)
expect(valid_budget).to be_valid
end
it "is required if main_link_text is provided" do
invalid_budget = build(:budget, main_link_text: "link text")
expect(invalid_budget).not_to be_valid
expect(invalid_budget.errors.count).to be 1
expect(invalid_budget.errors[:main_link_url].count).to be 1
expect(invalid_budget.errors[:main_link_url].first).to eq "can't be blank"
end
it "is valid if main_link_text and main_link_url are both provided" do
valid_budget = build(:budget, main_link_text: "Text link", main_link_url: "https://consulproject.org")
expect(valid_budget).to be_valid
end
end
describe "phase" do
it "is validated" do
Budget::Phase::PHASE_KINDS.each do |phase|

View File

@@ -13,6 +13,9 @@ shared_examples_for "globalizable" do |factory_name|
let(:attribute) { required_fields.sample || fields.sample }
before do
if factory_name == :budget
record.main_link_url = "https://consulproject.org"
end
record.update!(attribute => "In English")
I18n.with_locale(:es) do

View File

@@ -233,6 +233,21 @@ describe "Admin budgets", :admin do
end
end
scenario "Show CTA link in public site if added" do
visit edit_admin_budget_path(budget)
expect(page).to have_content("Main call to action (optional)")
fill_in "Text on the link", with: "Participate now"
fill_in "The link takes you to (add a link)", with: "https://consulproject.org"
click_button "Update Budget"
expect(page).to have_content "Participatory budget updated successfully"
visit budgets_path
expect(page).to have_link("Participate now", href: "https://consulproject.org")
end
scenario "Changing name for current locale will update the slug if budget is in draft phase" do
budget.update!(published: false, name: "Old English Name")

View File

@@ -122,7 +122,7 @@ describe "Admin edit translatable records", :admin do
let(:translatable) { create(:budget_investment) }
context "Input field" do
let(:translatable) { create(:budget) }
let(:translatable) { create(:budget, main_link_url: "https://consulproject.org") }
scenario "Shows validation erros" do
visit edit_admin_budget_path(translatable)