Few changes in test files for date(time)picker in order to make tests more readable

This commit is contained in:
Thierry Jet
2021-11-03 09:57:23 +01:00
parent c8340d5c3b
commit fd5e34bf5c
3 changed files with 9 additions and 6 deletions

View File

@@ -4,8 +4,7 @@ module Features
module DatepickerHelper
def choose_today_from_datepicker
within(".flatpickr-calendar.open") do
# Now that we have added the Close button, find the first button to avoid any ambiguous match
find('.shortcut-buttons-flatpickr-buttons > button:nth-child(1)').click
find("button", text: "TODAY").click
end
end

View File

@@ -161,7 +161,7 @@ describe '
within(".flatpickr-calendar.open") do
expect(page).to have_selector '.shortcut-buttons-flatpickr-buttons'
select_datetime_from_datepicker test_value
find(".shortcut-buttons-flatpickr-buttons > button:nth-last-child(1)").click
find("button", text: "CLOSE").click
end
# Should no more have opened flatpickr

View File

@@ -7,23 +7,25 @@ describe "Test Flatpickr", js: true do
include WebHelper
context "orders" do
it "opens the datepicker and closes it using the last button (the 'Close' one)" do
it "opens the datepicker and closes it using the 'CLOSE' button" do
login_as_admin_and_visit 'admin/orders'
open_datepicker('#q_completed_at_gteq')
# Looks for the close button and click it
within(".flatpickr-calendar.open") do
expect(page).to have_selector '.shortcut-buttons-flatpickr-buttons'
find(".shortcut-buttons-flatpickr-buttons > button:nth-last-child(1)").click
find("button", text: "CLOSE").click
end
# Should no more have opened flatpickr
expect(page).not_to have_selector '.flatpickr-calendar.open'
end
it "opens the datepicker and sets date to today" do
login_as_admin_and_visit 'admin/orders'
open_datepicker('#q_completed_at_gteq')
choose_today_from_datepicker
check_fielddate('#q_completed_at_gteq', Date.today())
end
it "opens the datepicker and closes it by clicking outside" do
login_as_admin_and_visit 'admin/orders'
open_datepicker('#q_completed_at_gteq')
@@ -33,13 +35,15 @@ describe "Test Flatpickr", js: true do
end
end
private
private
def open_datepicker(field)
# Opens a datepicker
find(field).click
# Should have opened flatpickr
expect(page).to have_selector '.flatpickr-calendar.open'
end
def check_fielddate(field, date)
# Check the value is correct
expect(find(field, match: :first).value).to eq date.to_datetime.strftime("%Y-%m-%d")