Move officing menu partial to a component

This way we can move some system tests to component tests and stop
creating records after starting the browser with a `visit`.

We could also split the system test in two, but since these tests
aren't checking any user interactions, moving the to component tests we
check the same things while making the tests faster.

Since the partial was using an instance variable, we're passing it to
the component. We're naming it `voter_user` instead of `user` because
passing something named `user` could make us think that we're passing
the `current_user`. I wasn't sure about naming it `voter` because it's a
`User` record and not a `Poll::Voter` record, but naming it `voter`
would definitely be an option.
This commit is contained in:
Javi Martín
2025-03-27 18:54:28 +01:00
parent 4c4aa210a1
commit 985d3da032
6 changed files with 58 additions and 46 deletions

View File

@@ -0,0 +1,17 @@
<div class="admin-sidebar">
<ul id="officing_menu">
<% if vote_collection_shift? %>
<li class="<%= "js-vote-collection" %>
<%= " is-active" if controller_name == "voters" %>
<%= " is-hidden" if controller_name == "voters" && Poll.votable_by(voter_user).any? %>">
<%= link_to t("officing.menu.voters"), new_officing_residence_path, class: "users-link" %>
</li>
<% end %>
<% if final_recount_shift? %>
<li <%= "class=is-active" if ["results", "ballot_sheets"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
<%= link_to t("officing.menu.total_recounts"), final_officing_polls_path, class: "users-link" %>
</li>
<% end %>
</ul>
</div>

View File

@@ -0,0 +1,18 @@
class Officing::MenuComponent < ApplicationComponent
attr_reader :voter_user
use_helpers :current_user
def initialize(voter_user:)
@voter_user = voter_user
end
private
def vote_collection_shift?
current_user.poll_officer.officer_assignments.voting_days.where(date: Time.current.to_date).any?
end
def final_recount_shift?
current_user.poll_officer.officer_assignments.final.where(date: Time.current.to_date).any?
end
end