Skip to content

Commit ca72820

Browse files
committed
Show the end date's year on meetings when year is different
1 parent 2c1e218 commit ca72820

6 files changed

Lines changed: 130 additions & 0 deletions

File tree

decidim-meetings/app/cells/decidim/meetings/dates_and_map/show.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
</div>
1717
<div class="meeting__calendar-year">
1818
<span><%= year %></span>
19+
<% unless same_year? %>
20+
<span class="meeting__calendar-separator">-</span>
21+
<span><%= end_year %></span>
22+
<% end %>
1923
</div>
2024
</div>
2125

decidim-meetings/app/cells/decidim/meetings/dates_and_map_cell.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def year
2121
l model.start_time, format: "%Y"
2222
end
2323

24+
def end_year
25+
l model.end_time, format: "%Y"
26+
end
27+
2428
private
2529

2630
def same_month?
@@ -31,6 +35,10 @@ def same_day?
3135
start_time.day == end_time.day
3236
end
3337

38+
def same_year?
39+
start_time.year == end_time.year
40+
end
41+
3442
def display_map?
3543
maps_enabled? && !online? && model.address.present?
3644
end

decidim-meetings/app/cells/decidim/meetings/meeting_l/image.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
</span>
1616
<span class="card__calendar-year">
1717
<span><%= l(meeting.start_time, format: "%Y") %></span>
18+
<% unless same_year? %>
19+
<span class="card__calendar-separator">-</span>
20+
<span><%= l(meeting.end_time, format: "%Y") %></span>
21+
<% end %>
1822
</span>
1923
</time>

decidim-meetings/app/cells/decidim/meetings/meeting_l_cell.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ def same_day?
4848
meeting.start_time.to_date == meeting.end_time.to_date
4949
end
5050

51+
def same_year?
52+
return true if meeting.end_time.blank?
53+
54+
meeting.start_time.year == meeting.end_time.year
55+
end
56+
5157
def metadata_cell
5258
"decidim/meetings/meeting_card_metadata"
5359
end
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
module Decidim::Meetings
6+
describe DatesAndMapCell, type: :cell do
7+
controller Decidim::Meetings::MeetingsController
8+
9+
subject { my_cell.call }
10+
11+
let!(:meeting) { create(:meeting, :published, start_time: Time.new(2020, 10, 15, 10, 4, 5, 0), end_time: Time.new(2020, 10, 15, 12, 0, 0, 0)) }
12+
let(:my_cell) { cell("decidim/meetings/dates_and_map", meeting) }
13+
14+
context "when rendering" do
15+
it "renders the calendar container" do
16+
expect(subject).to have_css(".meeting__calendar-container")
17+
end
18+
19+
it "shows the start time's month" do
20+
expect(subject).to have_css(".meeting__calendar-month", text: "October")
21+
end
22+
23+
it "shows the start time's day" do
24+
expect(subject).to have_css(".meeting__calendar-day", text: "15")
25+
end
26+
27+
it "shows the start time's year" do
28+
expect(subject).to have_css(".meeting__calendar-year", text: "2020")
29+
end
30+
31+
it "does not show separator" do
32+
expect(subject).to have_no_css(".meeting__calendar-separator")
33+
end
34+
end
35+
36+
context "when meeting spans multiple days in the same month" do
37+
let!(:meeting) { create(:meeting, :published, start_time: Time.new(2020, 10, 15, 10, 0, 0, 0), end_time: Time.new(2020, 10, 17, 12, 0, 0, 0)) }
38+
39+
it "shows the start day" do
40+
expect(subject).to have_css(".meeting__calendar-day", text: "15")
41+
end
42+
43+
it "shows the end day" do
44+
expect(subject).to have_css(".meeting__calendar-day", text: "17")
45+
end
46+
47+
it "shows the separator" do
48+
expect(subject).to have_css(".meeting__calendar-separator")
49+
end
50+
end
51+
52+
context "when meeting spans multiple months" do
53+
let!(:meeting) { create(:meeting, :published, start_time: Time.new(2020, 10, 15, 10, 0, 0, 0), end_time: Time.new(2020, 11, 17, 12, 0, 0, 0)) }
54+
55+
it "shows the start month" do
56+
expect(subject).to have_css(".meeting__calendar-month", text: "Oct")
57+
end
58+
59+
it "shows the end month" do
60+
expect(subject).to have_css(".meeting__calendar-month", text: "Nov")
61+
end
62+
63+
it "shows the start day" do
64+
expect(subject).to have_css(".meeting__calendar-day", text: "15")
65+
end
66+
67+
it "shows the end day" do
68+
expect(subject).to have_css(".meeting__calendar-day", text: "17")
69+
end
70+
71+
it "shows month separator" do
72+
expect(subject).to have_css(".meeting__calendar-separator")
73+
end
74+
end
75+
76+
context "when meeting spans multiple years" do
77+
let!(:meeting) { create(:meeting, :published, start_time: Time.new(2020, 12, 15, 10, 0, 0, 0), end_time: Time.new(2021, 1, 17, 12, 0, 0, 0)) }
78+
79+
it "shows the start year" do
80+
expect(subject).to have_css(".meeting__calendar-year", text: "2020")
81+
end
82+
83+
it "shows the end year" do
84+
expect(subject).to have_css(".meeting__calendar-year", text: "2021")
85+
end
86+
87+
it "shows the separator" do
88+
expect(subject).to have_css(".meeting__calendar-separator")
89+
end
90+
end
91+
end
92+
end

decidim-meetings/spec/cells/decidim/meetings/meeting_l_cell_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ module Decidim::Meetings
9494
end
9595
end
9696

97+
context "when meeting spans multiple years" do
98+
let!(:meeting) { create(:meeting, :published, start_time: Time.new(2020, 12, 15, 10, 0, 0, 0), end_time: Time.new(2021, 1, 17, 12, 0, 0, 0)) }
99+
100+
it "shows the start year" do
101+
expect(subject).to have_css(".card__calendar-year", text: "2020")
102+
end
103+
104+
it "shows the end year" do
105+
expect(subject).to have_css(".card__calendar-year", text: "2021")
106+
end
107+
108+
it "shows the separator" do
109+
expect(subject).to have_css(".card__calendar-separator")
110+
end
111+
end
112+
97113
context "when title contains special html entities" do
98114
let!(:original_title) { meeting.title["en"] }
99115

0 commit comments

Comments
 (0)