2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-09-08 11:25:39 +02:00
|
|
|
describe EditableChamp::EditableChampComponent, type: :component do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
|
|
|
|
let(:types_de_champ_public) { [] }
|
|
|
|
let(:types_de_champ_private) { [] }
|
|
|
|
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
2024-09-27 15:44:57 +02:00
|
|
|
let(:champ) { (dossier.project_champs_public + dossier.project_champs_private).first }
|
2024-07-01 15:31:32 +02:00
|
|
|
|
|
|
|
let(:component) { described_class.new(form: nil, champ:) }
|
2022-09-08 11:25:39 +02:00
|
|
|
|
2022-07-21 17:59:20 +02:00
|
|
|
describe "editable_champ_controller" do
|
|
|
|
let(:controllers) { [] }
|
2022-09-08 11:25:39 +02:00
|
|
|
let(:data) { controllers.join(' ') }
|
|
|
|
|
|
|
|
subject { component.send(:stimulus_controller) }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
context 'when an editable public champ' do
|
2022-07-21 17:59:20 +02:00
|
|
|
let(:controllers) { ['autosave'] }
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :text }] }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
2022-09-08 11:25:39 +02:00
|
|
|
it { expect(subject).to eq(data) }
|
2022-07-21 17:59:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a repetition champ' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :repetition, children: [{ type: :text }] }] }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
2022-09-08 11:25:39 +02:00
|
|
|
it { expect(subject).to eq(nil) }
|
2022-07-21 17:59:20 +02:00
|
|
|
end
|
|
|
|
|
2023-06-06 15:54:03 +02:00
|
|
|
context 'when a carte champ' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :carte }] }
|
2023-06-06 15:54:03 +02:00
|
|
|
|
|
|
|
it { expect(subject).to eq(nil) }
|
|
|
|
end
|
|
|
|
|
2022-07-21 17:59:20 +02:00
|
|
|
context 'when a private champ' do
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_private) { [{ type: :text }] }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
2023-03-01 18:30:10 +01:00
|
|
|
it { expect(subject).to eq('autosave') }
|
2022-07-21 17:59:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a dossier is en_construction' do
|
2022-09-08 11:25:39 +02:00
|
|
|
let(:controllers) { ['autosave'] }
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
|
|
|
context 'when a public dropdown champ' do
|
2023-03-30 00:24:11 +02:00
|
|
|
let(:controllers) { ['autosave'] }
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_public) { [{ type: :drop_down_list }] }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
2022-09-08 11:25:39 +02:00
|
|
|
it { expect(subject).to eq(data) }
|
2022-07-21 17:59:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a private dropdown champ' do
|
2023-03-30 00:24:11 +02:00
|
|
|
let(:controllers) { ['autosave'] }
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:types_de_champ_private) { [{ type: :drop_down_list }] }
|
2022-07-21 17:59:20 +02:00
|
|
|
|
2022-09-08 11:25:39 +02:00
|
|
|
it { expect(subject).to eq(data) }
|
2022-07-21 17:59:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|