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,37 @@
require "rails_helper"
describe Officing::MenuComponent do
let(:booth) { create(:poll_booth) }
let(:officer) { create(:poll_officer) }
let(:component) { Officing::MenuComponent.new(voter_user: nil) }
before do
create(:poll_booth_assignment, booth: booth)
sign_in(officer.user)
end
it "shows the validate document link when there are vote collection shifts assigned" do
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection)
render_inline component
expect(page).to have_content "Validate document"
expect(page).not_to have_content "Total recounts and results"
end
it "shows the total recounts link when there are recount scrutinity shifts assigned" do
create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :recount_scrutiny)
render_inline component
expect(page).not_to have_content "Validate document"
expect(page).to have_content "Total recounts and results"
end
it "does not show any links when there are no shifts assigned" do
render_inline component
expect(page).not_to have_content "Validate document"
expect(page).not_to have_content "Total recounts and results"
end
end