Add proper labels to shift date selectors

We were using one label for both date selectors, but it wasn't
associated with any of them.

So we're now rendering one label per control and, just like we only show
one of these date selectors at a time, we're only showing one label at a
time.
This commit is contained in:
Javi Martín
2024-10-12 19:33:41 +02:00
parent 79b7ec91dd
commit ddaf320d8a
3 changed files with 23 additions and 19 deletions

View File

@@ -6,12 +6,12 @@
change: function() { change: function() {
switch ($(this).val()) { switch ($(this).val()) {
case "vote_collection": case "vote_collection":
$("select[class='js-shift-vote-collection-dates']").show(); $(".js-shift-vote-collection-dates").show();
$("select[class='js-shift-recount-scrutiny-dates']").hide(); $(".js-shift-recount-scrutiny-dates").hide();
break; break;
case "recount_scrutiny": case "recount_scrutiny":
$("select[class='js-shift-recount-scrutiny-dates']").show(); $(".js-shift-recount-scrutiny-dates").show();
$("select[class='js-shift-vote-collection-dates']").hide(); $(".js-shift-vote-collection-dates").hide();
} }
} }
}); });

View File

@@ -20,11 +20,18 @@
</div> </div>
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<label><%= t("admin.poll_shifts.new.date") %></label> <%= label_tag :shift_date_vote_collection_date,
t("admin.poll_shifts.new.date"),
class: "js-shift-vote-collection-dates" %>
<%= select "shift[date]", "vote_collection_date", <%= select "shift[date]", "vote_collection_date",
options_for_select(shift_vote_collection_dates), options_for_select(shift_vote_collection_dates),
{ prompt: voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days") }, { prompt: voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days") },
class: "js-shift-vote-collection-dates" %> class: "js-shift-vote-collection-dates" %>
<%= label_tag :shift_date_recount_scrutiny_date,
t("admin.poll_shifts.new.date"),
class: "js-shift-recount-scrutiny-dates",
hidden: "hidden" %>
<%= select "shift[date]", "recount_scrutiny_date", <%= select "shift[date]", "recount_scrutiny_date",
options_for_select(shift_recount_scrutiny_dates), options_for_select(shift_recount_scrutiny_dates),
{ prompt: t("admin.poll_shifts.new.select_date") }, { prompt: t("admin.poll_shifts.new.select_date") },

View File

@@ -53,10 +53,10 @@ describe "Admin shifts", :admin do
click_button "Search" click_button "Search"
click_link "Edit shifts" click_link "Edit shifts"
expect(page).to have_select("shift_date_vote_collection_date", expect(page).to have_select "Date", options: ["Select day", *vote_collection_dates]
options: ["Select day", *vote_collection_dates]) expect(page).not_to have_select with_options: recount_scrutiny_dates
expect(page).not_to have_select("shift_date_recount_scrutiny_date")
select I18n.l(Date.current, format: :long), from: "shift_date_vote_collection_date" select I18n.l(Date.current, format: :long), from: "Date"
click_button "Add shift" click_button "Add shift"
expect(page).to have_content "Shift added" expect(page).to have_content "Shift added"
@@ -82,10 +82,9 @@ describe "Admin shifts", :admin do
select "Recount & Scrutiny", from: "shift_task" select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date", expect(page).to have_select "Date", options: ["Select day", *recount_scrutiny_dates]
options: ["Select day", *recount_scrutiny_dates]) expect(page).not_to have_select with_options: vote_collection_dates
expect(page).not_to have_select("shift_date_vote_collection_date") select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "Date"
select I18n.l(poll.ends_at.to_date + 4.days, format: :long), from: "shift_date_recount_scrutiny_date"
click_button "Add shift" click_button "Add shift"
expect(page).to have_content "Shift added" expect(page).to have_content "Shift added"
@@ -126,11 +125,9 @@ describe "Admin shifts", :admin do
click_button "Search" click_button "Search"
click_link "Edit shifts" click_link "Edit shifts"
expect(page).to have_select("shift_date_vote_collection_date", expect(page).to have_select "Date", options: ["Select day", *vote_collection_dates]
options: ["Select day", *vote_collection_dates])
select "Recount & Scrutiny", from: "shift_task" select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date", expect(page).to have_select "Date", options: ["Select day", *recount_scrutiny_dates]
options: ["Select day", *recount_scrutiny_dates])
end end
scenario "Change option from Recount & Scrutinity to Collect Votes" do scenario "Change option from Recount & Scrutinity to Collect Votes" do
@@ -144,11 +141,11 @@ describe "Admin shifts", :admin do
select "Recount & Scrutiny", from: "shift_task" select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day"]) expect(page).to have_select "Date", options: ["Select day"]
select "Collect Votes", from: "shift_task" select "Collect Votes", from: "shift_task"
expect(page).to have_select("shift_date_vote_collection_date", options: ["Voting days ended"]) expect(page).to have_select "Date", options: ["Voting days ended"]
end end
scenario "Error on create" do scenario "Error on create" do