Skip to content

Commit a346089

Browse files
Merge branch 'main' into feature/19656-configure-github-minitest-reporter
2 parents 411d160 + a6b5eef commit a346089

File tree

9 files changed

+102
-7
lines changed

9 files changed

+102
-7
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.11.0
1+
20.19.0

app/models/timer_session.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,22 @@ def relevant_issues
4444
end
4545

4646
def overlaps?(other_session)
47-
(timer_start...timer_end).overlaps?(other_session.timer_start...other_session.timer_end)
47+
return false unless timer_end.present? && other_session.timer_start.present?
48+
49+
this_start = round_to_nearest_minute(timer_start)
50+
this_end = round_to_nearest_minute(timer_end)
51+
other_start = round_to_nearest_minute(other_session.timer_start)
52+
other_end = round_to_nearest_minute(other_session.timer_end)
53+
54+
(this_start...this_end).overlaps?(other_start...other_end)
4855
end
4956

5057
private
5158

59+
def round_to_nearest_minute(time)
60+
Time.at((time.to_f / 60).round * 60).utc
61+
end
62+
5263
def set_recorded_hours
5364
return unless timer_start.present? && timer_end.present?
5465

app/views/time_tracker/cancel.js.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.location.href='<%= timer_sessions_path %>';
1+
window.location.href = '<%= timer_sessions_path %>' + window.location.search;

app/views/time_tracker/stop.js.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.location.href='<%= timer_sessions_path %>';
1+
window.location.href = '<%= timer_sessions_path %>' + window.location.search;

app/views/timer_sessions/_timer_sessions_day_block.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<%= render TimerSessionEntryComponent.new(
1212
timer_session_entry: time_entity,
1313
discrepancy_detected: @non_matching_timer_session_ids.include?(time_entity.id),
14-
overlap_detected: timer_sessions.any? { |other_entity| time_entity != other_entity && other_entity.overlaps?(time_entity) },
14+
overlap_detected: timer_sessions.any? { |other_entity| time_entity != other_entity && other_entity&.overlaps?(time_entity) },
1515
gap_separator: draw_gap_separator(time_entity, previous_time_entity)
1616
) %>
1717
<% end %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.location.href='<%= timer_sessions_path %>';
1+
window.location.href = '<%= timer_sessions_path %>' + window.location.search;

test/system/timer_management_test.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,46 @@ class TimerManagementTest < ApplicationSystemTestCase
111111
assert has_content?(Issue.first.subject, wait: 5)
112112
assert has_content?(Issue.second.subject)
113113
end
114+
115+
test 'preserves filter parameters when stopping a timer' do
116+
filter_date = 1.week.ago.strftime('%Y-%m-%d')
117+
current_date = Date.today.strftime('%Y-%m-%d')
118+
119+
visit timer_sessions_path(filter: { min_date: filter_date, max_date: current_date })
120+
121+
assert_equal filter_date, find('input[name="filter[min_date]"]').value
122+
assert_equal current_date, find('input[name="filter[max_date]"]').value
123+
124+
find('[data-name="timer-start"]').click
125+
assert has_content?(I18n.t('timer_sessions.timer.stop'))
126+
127+
fill_in 'timer_session[issue_id]', with: Issue.first.subject
128+
sleep(1)
129+
find('#timer_session_issue_id').send_keys(:arrow_down)
130+
find('#timer_session_issue_id').send_keys(:tab)
131+
132+
find('[data-name="timer-stop"]', wait: 5).click
133+
134+
assert_equal filter_date, find('input[name="filter[min_date]"]').value
135+
assert_equal current_date, find('input[name="filter[max_date]"]').value
136+
end
137+
138+
test 'preserves filter parameters when canceling a timer' do
139+
filter_date = 1.week.ago.strftime('%Y-%m-%d')
140+
current_date = Date.today.strftime('%Y-%m-%d')
141+
142+
visit timer_sessions_path(filter: { min_date: filter_date, max_date: current_date })
143+
144+
assert_equal filter_date, find('input[name="filter[min_date]"]').value
145+
assert_equal current_date, find('input[name="filter[max_date]"]').value
146+
147+
find('[data-name="timer-start"]').click
148+
assert has_content?(I18n.t('timer_sessions.timer.cancel'))
149+
150+
find('[data-name="timer-cancel"]', wait: 5).click
151+
page.driver.browser.switch_to.alert.accept
152+
153+
assert_equal filter_date, find('input[name="filter[min_date]"]').value
154+
assert_equal current_date, find('input[name="filter[max_date]"]').value
155+
end
114156
end

test/system/timer_sessions_management_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,25 @@ class TimerSessionsManagementTest < ApplicationSystemTestCase
8181
click_button I18n.t('timer_sessions.work_report_query.buttons.submit')
8282
assert has_content?(I18n.t(:label_spent_time))
8383
end
84+
85+
test 'preserves filter parameters when updating a timer session' do
86+
filter_date = 1.week.ago.strftime('%Y-%m-%d')
87+
current_date = Date.today.strftime('%Y-%m-%d')
88+
89+
visit timer_sessions_path(filter: { min_date: filter_date, max_date: current_date })
90+
91+
assert_equal filter_date, find('input[name="filter[min_date]"]').value
92+
assert_equal current_date, find('input[name="filter[max_date]"]').value
93+
94+
find('[data-timer-session-edit-button]', match: :first).click
95+
assert has_content?(I18n.t('timer_sessions.edit.title'))
96+
97+
within '.edit-modal' do
98+
fill_in TimerSession.human_attribute_name(:comments), with: 'Updated with filters'
99+
find('[data-modal-update-button]', match: :first).click
100+
end
101+
102+
assert_equal filter_date, find('input[name="filter[min_date]"]').value
103+
assert_equal current_date, find('input[name="filter[max_date]"]').value
104+
end
84105
end

test/unit/timer_session_test.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TimerSessionTest < ActiveSupport::TestCase
5858
assert_not @timer_session.valid?
5959
end
6060

61-
test 'overlaps?' do
61+
test 'overlaps?' do # rubocop:disable Metrics/BlockLength
6262
session1 = FactoryBot.create(:timer_session, user: User.current, timer_start: Time.zone.now,
6363
timer_end: Time.zone.now + 1.hour)
6464
session2 = FactoryBot.create(:timer_session, user: User.current, timer_start: Time.zone.now + 1.hour,
@@ -72,5 +72,26 @@ class TimerSessionTest < ActiveSupport::TestCase
7272

7373
assert session3.overlaps?(session1)
7474
assert session1.overlaps?(session3)
75+
76+
base_time = Time.utc(2023, 1, 1, 10, 0, 0)
77+
session1 = FactoryBot.create(:timer_session, user: User.current,
78+
timer_start: base_time,
79+
timer_end: base_time + 1.hour + 25.seconds)
80+
session2 = FactoryBot.create(:timer_session, user: User.current,
81+
timer_start: base_time + 1.hour + 5.seconds,
82+
timer_end: base_time + 2.hours)
83+
84+
assert_not session1.overlaps?(session2)
85+
assert_not session2.overlaps?(session1)
86+
87+
session1 = FactoryBot.create(:timer_session, user: User.current,
88+
timer_start: base_time,
89+
timer_end: base_time + 1.hour + 32.seconds)
90+
session2 = FactoryBot.create(:timer_session, user: User.current,
91+
timer_start: base_time + 1.hour,
92+
timer_end: base_time + 2.hours)
93+
94+
assert session1.overlaps?(session2)
95+
assert session2.overlaps?(session1)
7596
end
7697
end

0 commit comments

Comments
 (0)