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] 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"