Add a break to avoid case fallthrough

In JavaScript, when there isn't a `break` or `return` statement inside a
`switch` case, the next case will be executed as well.

That wasn't a problem here because CoffeeScript automatically inserts a
`return` statement in this specific situation. However, since we don't
want to return the result of the `hide()` operation, it might be easy to
accidentally remove the `return` statement, causing the code to break.

I've added a test for the scenario where neither `break` nor `return`
statements are present, so we don't run into this error.
This commit is contained in:
Javi Martín
2019-07-02 21:22:14 +02:00
parent 10a2e91f1c
commit 5ad41d9ac7
2 changed files with 19 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ App.PollsAdmin =
when "vote_collection"
$("select[class='js-shift-vote-collection-dates']").show()
$("select[class='js-shift-recount-scrutiny-dates']").hide()
break
when "recount_scrutiny"
$("select[class='js-shift-recount-scrutiny-dates']").show()
$("select[class='js-shift-vote-collection-dates']").hide()

View File

@@ -124,6 +124,24 @@ describe "Admin shifts" do
expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day", *recount_scrutiny_dates])
end
scenario "Change option from Recount & Scrutinity to Collect Votes", :js do
booth = create(:poll_booth)
officer = create(:poll_officer)
create(:poll_shift, :vote_collection_task, officer: officer, booth: booth)
create(:poll_shift, :recount_scrutiny_task, officer: officer, booth: booth)
visit new_admin_booth_shift_path(booth, officer_id: officer.id)
select "Recount & Scrutiny", from: "shift_task"
expect(page).to have_select("shift_date_recount_scrutiny_date", options: ["Select day"])
select "Collect Votes", from: "shift_task"
expect(page).to have_select("shift_date_vote_collection_date", options: ["Voting days ended"])
end
scenario "Error on create", :js do
poll = create(:poll, :current)
booth = create(:poll_booth)