From 52e0d45ff7c248e6fd59dacbefb45669fa6f4a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 23 Mar 2021 18:12:21 +0100 Subject: [PATCH 1/4] Fix filling in dates in advanced search tests We were filling in dates with times, which is not what users would do. --- spec/system/advanced_search_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/system/advanced_search_spec.rb b/spec/system/advanced_search_spec.rb index a18795f65..d02d723bd 100644 --- a/spec/system/advanced_search_spec.rb +++ b/spec/system/advanced_search_spec.rb @@ -272,8 +272,8 @@ describe "Advanced search", :js do click_link "Advanced search" select "Customized", from: "js-advanced-search-date-min" - fill_in "advanced_search_date_min", with: 7.days.ago - fill_in "advanced_search_date_max", with: 1.day.ago + fill_in "advanced_search_date_min", with: 7.days.ago.strftime("%d/%m/%Y") + fill_in "advanced_search_date_max", with: 1.day.ago.strftime("%d/%m/%Y") click_button "Filter" within("#debates") do @@ -294,7 +294,7 @@ describe "Advanced search", :js do click_link "Advanced search" select "Customized", from: "js-advanced-search-date-min" - fill_in "advanced_search_date_min", with: 4000.years.ago + fill_in "advanced_search_date_min", with: 4000.years.ago.strftime("%d/%m/%Y") fill_in "advanced_search_date_max", with: "wrong date" click_button "Filter" From 863f70044bec03482f44a902d476482bed79c17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 23 Mar 2021 18:32:37 +0100 Subject: [PATCH 2/4] Fix test trying to set a wrong date The line `fill_in "advanced_search_date_max", with: "wrong date"` doesn't work because the jQuery UI datepicker prevents users from entering that value. --- spec/system/advanced_search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/advanced_search_spec.rb b/spec/system/advanced_search_spec.rb index d02d723bd..24dfc3361 100644 --- a/spec/system/advanced_search_spec.rb +++ b/spec/system/advanced_search_spec.rb @@ -295,7 +295,7 @@ describe "Advanced search", :js do click_link "Advanced search" select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 4000.years.ago.strftime("%d/%m/%Y") - fill_in "advanced_search_date_max", with: "wrong date" + fill_in "advanced_search_date_max", with: "13/13/2199" click_button "Filter" expect(page).to have_content("There are 3 citizen proposals") From 24a66f16f29b1253c3f6b6002b8ee6eb1e82a97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 23 Mar 2021 18:33:07 +0100 Subject: [PATCH 3/4] Close datepicker in tests after filling in dates Some tests were failing depending on the window resolution due to the datepicker making it impossible to click the "Filter" button. They were also failing if using `clear: :backspace` to fill in those fields. So we're focusing on a different field in order to hide the datepicker and click the "Filter" button. --- spec/system/advanced_search_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/system/advanced_search_spec.rb b/spec/system/advanced_search_spec.rb index 24dfc3361..f05545839 100644 --- a/spec/system/advanced_search_spec.rb +++ b/spec/system/advanced_search_spec.rb @@ -274,6 +274,7 @@ describe "Advanced search", :js do select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 7.days.ago.strftime("%d/%m/%Y") fill_in "advanced_search_date_max", with: 1.day.ago.strftime("%d/%m/%Y") + find_field("With the text").click click_button "Filter" within("#debates") do @@ -296,6 +297,7 @@ describe "Advanced search", :js do select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 4000.years.ago.strftime("%d/%m/%Y") fill_in "advanced_search_date_max", with: "13/13/2199" + find_field("With the text").click click_button "Filter" expect(page).to have_content("There are 3 citizen proposals") @@ -355,6 +357,7 @@ describe "Advanced search", :js do select "Customized", from: "js-advanced-search-date-min" fill_in "advanced_search_date_min", with: 7.days.ago.strftime("%d/%m/%Y") fill_in "advanced_search_date_max", with: 1.day.ago.strftime("%d/%m/%Y") + find_field("With the text").click click_button "Filter" expect(page).to have_content("citizen proposals cannot be found") From 0c95ababdf8fc2ccde86e235b979224b3f7ce41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 26 Mar 2021 19:33:18 +0100 Subject: [PATCH 4/4] Use dates to fill in admin date input fields Tests are easier to read now. Besides, since we changed the inputs in the admin section so they don't use jQuery but an HTML date field, formatting with %d/%m/%Y might not work depending on the browser's locale. --- spec/system/admin/banners_spec.rb | 6 ++-- .../admin/legislation/processes_spec.rb | 36 ++++++++----------- spec/system/admin/poll/polls_spec.rb | 16 ++++----- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/spec/system/admin/banners_spec.rb b/spec/system/admin/banners_spec.rb index cab045f7a..234b7e296 100644 --- a/spec/system/admin/banners_spec.rb +++ b/spec/system/admin/banners_spec.rb @@ -82,10 +82,8 @@ describe "Admin banners magement", :admin do fill_in "Title", with: "Such banner" fill_in "Description", with: "many text wow link" fill_in "banner_target_url", with: "https://www.url.com" - last_week = Time.current - 7.days - next_week = Time.current + 7.days - fill_in "post_started_at", with: last_week.strftime("%d/%m/%Y") - fill_in "post_ended_at", with: next_week.strftime("%d/%m/%Y") + fill_in "post_started_at", with: Date.current - 7.days + fill_in "post_ended_at", with: Date.current + 7.days fill_in "banner_background_color", with: "#850000" fill_in "banner_font_color", with: "#ffb2b2" check section.name.titleize diff --git a/spec/system/admin/legislation/processes_spec.rb b/spec/system/admin/legislation/processes_spec.rb index 2c88b0140..2dd71e859 100644 --- a/spec/system/admin/legislation/processes_spec.rb +++ b/spec/system/admin/legislation/processes_spec.rb @@ -72,25 +72,17 @@ describe "Admin collaborative legislation", :admin do fill_in "Description", with: "Describing the process" base_date = Date.current - fill_in "legislation_process[start_date]", with: base_date.strftime("%d/%m/%Y") - fill_in "legislation_process[end_date]", with: (base_date + 5.days).strftime("%d/%m/%Y") + fill_in "legislation_process[start_date]", with: base_date + fill_in "legislation_process[end_date]", with: base_date + 5.days - fill_in "legislation_process[debate_start_date]", - with: base_date.strftime("%d/%m/%Y") - fill_in "legislation_process[debate_end_date]", - with: (base_date + 2.days).strftime("%d/%m/%Y") - fill_in "legislation_process[draft_start_date]", - with: (base_date - 3.days).strftime("%d/%m/%Y") - fill_in "legislation_process[draft_end_date]", - with: (base_date - 1.day).strftime("%d/%m/%Y") - fill_in "legislation_process[draft_publication_date]", - with: (base_date + 3.days).strftime("%d/%m/%Y") - fill_in "legislation_process[allegations_start_date]", - with: (base_date + 3.days).strftime("%d/%m/%Y") - fill_in "legislation_process[allegations_end_date]", - with: (base_date + 5.days).strftime("%d/%m/%Y") - fill_in "legislation_process[result_publication_date]", - with: (base_date + 7.days).strftime("%d/%m/%Y") + fill_in "legislation_process[debate_start_date]", with: base_date + fill_in "legislation_process[debate_end_date]", with: base_date + 2.days + fill_in "legislation_process[draft_start_date]", with: base_date - 3.days + fill_in "legislation_process[draft_end_date]", with: base_date - 1.day + fill_in "legislation_process[draft_publication_date]", with: base_date + 3.days + fill_in "legislation_process[allegations_start_date]", with: base_date + 3.days + fill_in "legislation_process[allegations_end_date]", with: base_date + 5.days + fill_in "legislation_process[result_publication_date]", with: base_date + 7.days click_button "Create process" @@ -126,11 +118,11 @@ describe "Admin collaborative legislation", :admin do fill_in "Description", with: "Describing the process" base_date = Date.current - 2.days - fill_in "legislation_process[start_date]", with: base_date.strftime("%d/%m/%Y") - fill_in "legislation_process[end_date]", with: (base_date + 5.days).strftime("%d/%m/%Y") + fill_in "legislation_process[start_date]", with: base_date + fill_in "legislation_process[end_date]", with: base_date + 5.days - fill_in "legislation_process[draft_start_date]", with: base_date.strftime("%d/%m/%Y") - fill_in "legislation_process[draft_end_date]", with: (base_date + 3.days).strftime("%d/%m/%Y") + fill_in "legislation_process[draft_start_date]", with: base_date + fill_in "legislation_process[draft_end_date]", with: base_date + 3.days check "legislation_process[draft_phase_enabled]" click_button "Create process" diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index 5d5baf257..de23b7768 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -62,12 +62,12 @@ describe "Admin polls", :admin do visit admin_polls_path click_link "Create poll" - start_date = 1.week.from_now - end_date = 2.weeks.from_now + start_date = 1.week.from_now.to_date + end_date = 2.weeks.from_now.to_date fill_in "Name", with: "Upcoming poll" - fill_in "poll_starts_at", with: start_date.strftime("%d/%m/%Y") - fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y") + fill_in "poll_starts_at", with: start_date + fill_in "poll_ends_at", with: end_date fill_in "Summary", with: "Upcoming poll's summary. This poll..." fill_in "Description", with: "Upcomming poll's description. This poll..." @@ -78,8 +78,8 @@ describe "Admin polls", :admin do expect(page).to have_content "Poll created successfully" expect(page).to have_content "Upcoming poll" - expect(page).to have_content I18n.l(start_date.to_date) - expect(page).to have_content I18n.l(end_date.to_date) + expect(page).to have_content I18n.l(start_date) + expect(page).to have_content I18n.l(end_date) expect(Poll.last.slug).to eq "#{Poll.last.name.to_s.parameterize}" end @@ -89,12 +89,12 @@ describe "Admin polls", :admin do visit admin_poll_path(poll) click_link "Edit poll" - end_date = 1.year.from_now + end_date = 1.year.from_now.to_date expect(page).to have_css("img[alt='#{poll.image.title}']") fill_in "Name", with: "Next Poll" - fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y") + fill_in "poll_ends_at", with: end_date click_button "Update poll"