Skip to content

Commit

Permalink
refacotr: Reduce duplication and dead-code
Browse files Browse the repository at this point in the history
The modal behavior being more reliable now, the `retry_block` is not
needed anymore. Also the `#select_day` method was similar in the parent
class. Better keep only the one from the parent class.
  • Loading branch information
cbliard committed Sep 6, 2024
1 parent 3594502 commit 07e7070
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
1 change: 0 additions & 1 deletion spec/features/admin/working_days_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ def working_days_setting
end

it "can add non-working days" do
# Initial loading can sometimes take a while
datepicker.open_modal!

# Check if a date is correctly highlighted after selecting it in different time zones
Expand Down
5 changes: 5 additions & 0 deletions spec/support/components/datepicker/datepicker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def select_day(value)
.first(".flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)",
text: value)
.click

# safeguard
unless flatpickr_container.has_css?(".flatpickr-day.selected", text: value, wait: 1)
raise "Expected #{value} to be selected"
end
end
end

Expand Down
28 changes: 2 additions & 26 deletions spec/support/components/datepicker/datepicker_modal.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module Components
class DatepickerModal < Datepicker
def open_modal!
retry_block do
click_on "Non-working day", wait: 10
unless page.has_css?(".flatpickr-calendar", wait: 10)
click_on "Cancel"
raise "Flatpickr should render a calendar"
end
end
click_on "Non-working day"
expect_visible
end

def set_date_input(date)
Expand All @@ -17,24 +12,5 @@ def set_date_input(date)
raise "Expected date to equal #{date}, but got #{input.value}" unless input.value == date.iso8601
end
end

##
# Select day from datepicker
def select_day(value)
unless (1..31).cover?(value.to_i)
raise ArgumentError, "Invalid value #{value} for day, expected 1-31"
end

expect(flatpickr_container).to have_text(value)

retry_block do
flatpickr_container
.first(".flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)",
text: value)
.click

raise "Expected #{value} to be selected" unless flatpickr_container.has_css?(".flatpickr-day.selected", text: value)
end
end
end
end

0 comments on commit 07e7070

Please sign in to comment.