Update single heading budget view

Co-Authored-By: Julian Herrero <microweb10@gmail.com>
This commit is contained in:
decabeza
2020-03-15 06:51:52 +01:00
committed by Javi Martín
parent 122195e33c
commit 0273156c20
5 changed files with 83 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
.single-heading {
margin-bottom: $line-height * 2;
padding-bottom: $line-height;
position: relative;
&::after {
background: $brand;
bottom: 0;
content: "";
height: rem-calc(6);
position: absolute;
width: 20%;
}
h2 {
font-size: rem-calc(60);
font-weight: normal;
}
p {
font-size: rem-calc(48);
}
}

View File

@@ -26,7 +26,11 @@
<div id="budget_info" class="budget-info">
<div class="row margin-top">
<div class="small-12 column">
<%= render Budgets::GroupsAndHeadingsComponent.new(budget) %>
<% if budget.single_heading? %>
<%= render Budgets::SingleHeadingComponent.new(budget) %>
<% else %>
<%= render Budgets::GroupsAndHeadingsComponent.new(budget) %>
<% end %>
<% unless budget.informing? %>
<div class="map inline">

View File

@@ -0,0 +1,4 @@
<div class="single-heading">
<h2><%= title %></h2>
<p><%= price %></p>
</div>

View File

@@ -0,0 +1,21 @@
class Budgets::SingleHeadingComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def heading
budget.headings.first
end
def title
heading.name
end
def price
budget.formatted_heading_price(heading)
end
end

View File

@@ -126,6 +126,36 @@ describe "Budgets" do
expect(page).to have_content "There are no budgets"
end
scenario "Show heading for budget with single heading" do
group = create(:budget_group, budget: budget, name: "Single group")
create(:budget_heading, group: group, name: "New heading", price: 10_000)
visit budgets_path
expect(page).not_to have_content "Single group"
within ".single-heading" do
expect(page).to have_content "New heading"
expect(page).to have_content "€10,000"
end
end
scenario "Show group and headings for budget with multiple headings" do
group = create(:budget_group, budget: budget, name: "New group")
create(:budget_heading, group: group, name: "New heading", price: 10_000)
create(:budget_heading, group: group, name: "Other new heading", price: 30_000)
visit budgets_path
within("#groups_and_headings") do
expect(page).to have_content "New group"
expect(page).to have_content "New heading"
expect(page).to have_content "€10,000"
expect(page).to have_content "Other new heading"
expect(page).to have_content "€30,000"
end
end
end
scenario "Index shows only published phases" do