- <%= f.text_field :publication_date,
- value: @milestone.publication_date.present? ? l(@milestone.publication_date.to_date) : nil,
- class: "js-calendar-full" %>
+ <%= f.date_field :publication_date %>
<%= render "images/admin_image", imageable: @milestone, f: f %>
diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb
index 75b28dc40..4011ab4ec 100644
--- a/app/views/admin/poll/polls/_form.html.erb
+++ b/app/views/admin/poll/polls/_form.html.erb
@@ -6,15 +6,11 @@
- <%= f.text_field :starts_at,
- value: @poll.starts_at.present? ? l(@poll.starts_at.to_date) : nil,
- class: "js-calendar-full" %>
+ <%= f.date_field :starts_at %>
- <%= f.text_field :ends_at,
- value: @poll.ends_at.present? ? l(@poll.ends_at.to_date) : nil,
- class: "js-calendar-full" %>
+ <%= f.date_field :ends_at %>
diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb
index 066257d8f..778f0e8eb 100644
--- a/lib/consul_form_builder.rb
+++ b/lib/consul_form_builder.rb
@@ -9,7 +9,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
select attribute, choices, options, html_options
end
- %i[text_field text_area number_field password_field email_field].each do |field|
+ %i[text_field text_area date_field number_field password_field email_field].each do |field|
define_method field do |attribute, options = {}|
label_with_hint(attribute, options.merge(label_options: label_options_for(options))) +
super(attribute, options.merge(
diff --git a/spec/system/admin/banners_spec.rb b/spec/system/admin/banners_spec.rb
index 9cd5e643c..7bd3f0d88 100644
--- a/spec/system/admin/banners_spec.rb
+++ b/spec/system/admin/banners_spec.rb
@@ -114,14 +114,9 @@ describe "Admin banners magement" do
fill_in "Title", with: "En Français"
fill_in "Description", with: "Link en Français"
-
fill_in "Link", with: "https://www.url.com"
-
- last_week = Time.current - 1.week
- next_week = Time.current + 1.week
-
- 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: Time.current - 1.week
+ fill_in "Post ended at", with: Time.current + 1.week
click_button "Save changes"
click_link "Edit banner"
@@ -179,45 +174,6 @@ describe "Admin banners magement" do
expect(page).not_to have_content "Wrong text"
end
- scenario "when change date field on edit banner page display expected format", :js do
- banner = create(:banner)
- visit edit_admin_banner_path(banner)
-
- fill_in "Post started at", with: "20/02/2002"
- find_field("Post started at").click
- within(".ui-datepicker") { click_link "22" }
-
- expect(page).to have_field "Post started at", with: "22/02/2002"
- end
-
- scenario "when date picker is opened and click on browser history back datepicker is closed", :js do
- banner = create(:banner)
- visit admin_banners_path(banner)
- click_link "Edit banner"
- find_field("Post started at").click
-
- expect(page).to have_css "#ui-datepicker-div"
-
- go_back
-
- expect(page).to have_content("Banners")
- expect(page).not_to have_css "#ui-datepicker-div"
- end
-
- scenario "date picker works after using the browser back button", :js do
- banner = create(:banner)
-
- visit edit_admin_banner_path(banner)
- click_link "Manage banners"
-
- expect(page).to have_link "Edit banner"
-
- go_back
- find_field("Post started at").click
-
- expect(page).to have_css "#ui-datepicker-div"
- end
-
scenario "Delete a banner" do
create(:banner, title: "Ugly banner",
description: "Bad text",
diff --git a/spec/system/admin/legislation/processes_spec.rb b/spec/system/admin/legislation/processes_spec.rb
index 1397f9feb..e85fdc353 100644
--- a/spec/system/admin/legislation/processes_spec.rb
+++ b/spec/system/admin/legislation/processes_spec.rb
@@ -162,8 +162,8 @@ describe "Admin collaborative legislation" do
fill_in "Summary", with: "Summary of 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
imageable_attach_new_file(create(:image), Rails.root.join("spec/fixtures/files/clippy.jpg"))
click_button "Create process"
@@ -258,8 +258,8 @@ describe "Admin collaborative legislation" do
check "legislation_process[published]"
- expect(page).to have_field "start_date", disabled: false, with: "07/07/2007"
- expect(page).to have_field "end_date", disabled: false, with: "08/08/2008"
+ expect(page).to have_field "start_date", disabled: false, with: "2007-07-07"
+ expect(page).to have_field "end_date", disabled: false, with: "2008-08-08"
end
scenario "Enabling/disabling a phase does not enable/disable another phase date fields", :js do
diff --git a/spec/system/dashboard/polls_spec.rb b/spec/system/dashboard/polls_spec.rb
index 024624d17..9de22d6b6 100644
--- a/spec/system/dashboard/polls_spec.rb
+++ b/spec/system/dashboard/polls_spec.rb
@@ -41,6 +41,44 @@ describe "Polls" do
expect(page).to have_content I18n.l(start_date.to_date)
end
+ describe "Datepicker", :js do
+ scenario "displays the expected format when changing the date field" do
+ visit new_proposal_dashboard_poll_path(proposal)
+
+ fill_in "Start Date", with: "20/02/2002"
+ find_field("Start Date").click
+ within(".ui-datepicker") { click_link "22" }
+
+ expect(page).to have_field "Start Date", with: "22/02/2002"
+ end
+
+ scenario "is closed after using the browser back button" do
+ visit proposal_dashboard_polls_path(proposal)
+
+ click_link "Create poll"
+ find_field("Start Date").click
+
+ expect(page).to have_css "#ui-datepicker-div"
+
+ go_back
+
+ expect(page).to have_link "Create poll"
+ expect(page).not_to have_css "#ui-datepicker-div"
+ end
+
+ scenario "works after using the browser back button" do
+ visit new_proposal_dashboard_poll_path(proposal)
+ click_link "Polls"
+
+ expect(page).to have_link "Create poll"
+
+ go_back
+ find_field("Start Date").click
+
+ expect(page).to have_css "#ui-datepicker-div"
+ end
+ end
+
scenario "Create a poll redirects back to form when invalid data", js: true do
click_link "Polls"
click_link "Create poll"