mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Few changes in test files for date(time)picker in order to make tests more readable
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user