2023-03-24 10:31:01 +01:00
|
|
|
RSpec.describe TypesDeChampEditor::HeaderSectionComponent, type: :component do
|
|
|
|
include ActionView::Context
|
|
|
|
include ActionView::Helpers::FormHelper
|
|
|
|
include ActionView::Helpers::FormOptionsHelper
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public:) }
|
2023-03-24 10:31:01 +01:00
|
|
|
|
|
|
|
let(:component) do
|
|
|
|
cmp = nil
|
|
|
|
form_for(tdc, url: '/') do |form|
|
|
|
|
cmp = described_class.new(form: form, tdc: tdc, upper_tdcs: upper_tdcs)
|
|
|
|
end
|
|
|
|
cmp
|
|
|
|
end
|
|
|
|
subject { render_inline(component).to_html }
|
|
|
|
|
|
|
|
describe 'header_section_options_for_select' do
|
|
|
|
context 'without upper tdc' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :header_section, level: 1 }] }
|
|
|
|
let(:tdc) { procedure.draft_revision.types_de_champ_public.first }
|
2023-03-24 10:31:01 +01:00
|
|
|
let(:upper_tdcs) { [] }
|
|
|
|
|
|
|
|
it 'allows up to level 1 header section' do
|
|
|
|
expect(subject).to have_selector("option", count: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with upper tdc of level 1' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) do
|
|
|
|
[
|
|
|
|
{ type: :header_section, level: 1 },
|
|
|
|
{ type: :header_section, level: 2 }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
let(:tdc) { procedure.draft_revision.types_de_champ_public.last }
|
|
|
|
let(:upper_tdcs) { [procedure.draft_revision.types_de_champ_public.first] }
|
2023-03-24 10:31:01 +01:00
|
|
|
|
|
|
|
it 'allows up to level 2 header section' do
|
|
|
|
expect(subject).to have_selector("option", count: 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with upper tdc of level 2' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) do
|
2023-03-24 10:31:01 +01:00
|
|
|
[
|
2024-07-01 15:31:32 +02:00
|
|
|
{ type: :header_section, level: 1 },
|
|
|
|
{ type: :header_section, level: 2 },
|
|
|
|
{ type: :header_section, level: 3 }
|
|
|
|
]
|
2023-03-24 10:31:01 +01:00
|
|
|
end
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:tdc) { procedure.draft_revision.types_de_champ_public.third }
|
|
|
|
let(:upper_tdcs) { [procedure.draft_revision.types_de_champ_public.first, procedure.draft_revision.types_de_champ_public.second] }
|
2023-03-24 10:31:01 +01:00
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
it 'allows up to level 3 header section' do
|
2023-03-24 10:31:01 +01:00
|
|
|
expect(subject).to have_selector("option", count: 3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with error' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :header_section, level: 2 }] }
|
|
|
|
let(:tdc) { procedure.draft_revision.types_de_champ_public.first }
|
2023-03-24 10:31:01 +01:00
|
|
|
let(:upper_tdcs) { [] }
|
|
|
|
|
|
|
|
it 'includes disabled levels' do
|
|
|
|
expect(subject).to have_selector("option", count: 3)
|
|
|
|
expect(subject).to have_selector("option[disabled]", count: 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'errors' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :header_section, level: 2 }] }
|
|
|
|
let(:tdc) { procedure.draft_revision.types_de_champ_public.first }
|
2023-03-24 10:31:01 +01:00
|
|
|
let(:upper_tdcs) { [] }
|
|
|
|
|
|
|
|
it 'returns errors' do
|
|
|
|
expect(subject).to have_selector('.errors-summary')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|