Files
grecia/spec/components/admin/poll/officers/officers_component_spec.rb
Javi Martín f52a86b465 Apply (but don't add) Capybara/SpecificMatcher rule
This rule was added in rubocop-rspec 2.12.0, and we were already
following it most of the time.

However, the rule isn't working correctly in some cases, such as input
selectors, so we aren't enabling it.
2023-09-06 19:00:56 +02:00

41 lines
1.3 KiB
Ruby

require "rails_helper"
describe Admin::Poll::Officers::OfficersComponent, :admin do
let(:existing_officer) { create(:poll_officer, name: "Old officer") }
let(:new_officer) { build(:poll_officer, name: "New officer") }
let(:officers) { [existing_officer, new_officer] }
let(:component) { Admin::Poll::Officers::OfficersComponent.new(officers) }
it "renders as many rows as officers" do
render_inline component
tbody = page.find("tbody")
expect(tbody).to have_css "tr", count: 2
expect(tbody).to have_button count: 2
end
it "renders button to destroy for existing officers" do
render_inline component
row = page.find("tr", text: "Old officer")
expect(row).to have_button "Delete position"
expect(row).to have_css "input[name='_method'][value='delete']", visible: :hidden
end
it "renders button to add for new officers" do
render_inline component
row = page.find("tr", text: "New officer")
expect(row).to have_button "Add"
expect(row).to have_css "form[method='post']"
expect(row).not_to have_css "input[name='_method']", visible: :all
end
it "accepts table options" do
render_inline Admin::Poll::Officers::OfficersComponent.new(officers, class: "my-officers-table")
expect(page).to have_table class: "my-officers-table"
end
end