refactor(instruction): menu repasser en construction + demander une correction

This commit is contained in:
Colin Darie 2023-04-18 18:06:24 +02:00
parent 3c4ea6f8cf
commit fd4a9a6a2f
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
15 changed files with 164 additions and 70 deletions

View file

@ -0,0 +1,53 @@
# frozen_string_literal: true
RSpec.describe Instructeurs::EnConstructionMenuComponent, 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('Repasser en construction')
expect(subject).to have_dropdown_item('Demander une correction')
expect(subject).to have_dropdown_item('Repasser en construction')
expect(subject).to have_dropdown_items(count: 3)
end
end
end