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.
This commit is contained in:
Javi Martín
2021-03-26 19:33:18 +01:00
parent 24a66f16f2
commit 0c95ababdf
3 changed files with 24 additions and 34 deletions

View File

@@ -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

View File

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

View File

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