demarches-normaliennes/spec/components/instructeurs/instruction_menu_component_spec.rb

56 lines
1.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe Instructeurs::InstructionMenuComponent, type: :component do
include DossierHelper
subject do
render_inline(described_class.new(dossier:))
end
matcher :have_dropdown_title do |expected_title|
match do |subject|
expect(subject).to have_selector('.dropdown .dropdown-button', text: expected_title)
end
end
matcher :have_dropdown_items do |options|
match do |subject|
expected_count = options[:count] || 1
expect(subject).to have_selector('ul.dropdown-items li:not(.hidden)', count: expected_count)
end
end
matcher :have_dropdown_item do |expected_title, options = {}|
match do |subject|
expected_href = options[:href]
if (expected_href.present?)
expect(subject).to have_selector("ul.dropdown-items li a[href='#{expected_href}']", text: expected_title)
else
expect(subject).to have_selector('ul.dropdown-items li', text: expected_title)
end
end
end
context 'en_construction' do
let(:dossier) { create(:dossier, :en_construction) }
it 'renders a dropdown' do
expect(subject).to have_dropdown_title('Demander une correction')
expect(subject).to have_dropdown_items(count: 2) # form is already expanded so we have 2 visible items
end
end
context 'en_instruction' do
let(:dossier) { create(:dossier, :en_instruction) }
it 'renders a dropdown' do
expect(subject).to have_dropdown_title('Instruire le dossier')
expect(subject).to have_dropdown_items(count: 4)
expect(subject).to have_dropdown_item('Accepter')
expect(subject).to have_dropdown_item('Classer sans suite')
expect(subject).to have_dropdown_item('Refuser')
expect(subject).to have_dropdown_item('Demander une correction')
end
end
end