refactor(champ): remove type_de_champ_id and champ factories
This commit is contained in:
parent
860e06256f
commit
229483d16c
120 changed files with 1144 additions and 1540 deletions
|
@ -1,25 +1,29 @@
|
|||
describe EditableChamp::DatetimeComponent, type: :component do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :datetime, stable_id: 99 }]) }
|
||||
let(:dossier) { create(:dossier, procedure:) }
|
||||
|
||||
let(:component) {
|
||||
described_class.new(form: instance_double(ActionView::Helpers::FormBuilder, object_name: "dossier[champs_public_attributes]"), champ:)
|
||||
}
|
||||
|
||||
describe '#formatted_value_for_datetime_locale' do
|
||||
# before { champ.validate(:prefill) }
|
||||
subject { component.formatted_value_for_datetime_locale }
|
||||
|
||||
context 'when the value is nil' do
|
||||
let(:champ) { create(:champ_datetime, dossier: create(:dossier), value: nil) }
|
||||
let(:champ) { Champs::DatetimeChamp.new(value: nil, dossier:, stable_id: 99) }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when the value is not a valid datetime' do
|
||||
let(:champ) { create(:champ_datetime, dossier: create(:dossier), value: 'invalid') }
|
||||
let(:champ) { Champs::DatetimeChamp.new(value: 'invalid', dossier:, stable_id: 99) }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context 'when the value is a valid datetime' do
|
||||
let(:champ) { create(:champ_datetime, dossier: create(:dossier), value: '2020-01-01T00:00:00+01:00') }
|
||||
let(:champ) { Champs::DatetimeChamp.new(value: '2020-01-01T00:00:00+01:00', dossier:, stable_id: 99) }
|
||||
|
||||
it { is_expected.to eq('2020-01-01T00:00') }
|
||||
end
|
||||
|
|
|
@ -1,71 +1,60 @@
|
|||
describe EditableChamp::EditableChampComponent, type: :component do
|
||||
let(:component) { described_class.new(form: nil, champ: champ) }
|
||||
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:) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
|
||||
let(:component) { described_class.new(form: nil, champ:) }
|
||||
|
||||
describe "editable_champ_controller" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:champ) { create(:champ, dossier: dossier) }
|
||||
let(:controllers) { [] }
|
||||
let(:data) { controllers.join(' ') }
|
||||
|
||||
subject { component.send(:stimulus_controller) }
|
||||
|
||||
context 'when an editable champ' do
|
||||
context 'when an editable public champ' do
|
||||
let(:controllers) { ['autosave'] }
|
||||
let(:types_de_champ_public) { [{ type: :text }] }
|
||||
|
||||
it { expect(subject).to eq(data) }
|
||||
end
|
||||
|
||||
context 'when a repetition champ' do
|
||||
let(:champ) { create(:champ_repetition, dossier: dossier) }
|
||||
let(:types_de_champ_public) { [{ type: :repetition, children: [{ type: :text }] }] }
|
||||
|
||||
it { expect(subject).to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when a carte champ' do
|
||||
let(:champ) { create(:champ_carte, dossier: dossier) }
|
||||
let(:types_de_champ_public) { [{ type: :carte }] }
|
||||
|
||||
it { expect(subject).to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when a private champ' do
|
||||
let(:champ) { create(:champ, dossier: dossier, private: true) }
|
||||
let(:types_de_champ_private) { [{ type: :text }] }
|
||||
|
||||
it { expect(subject).to eq('autosave') }
|
||||
end
|
||||
|
||||
context 'when a dossier is en_construction' do
|
||||
let(:controllers) { ['autosave'] }
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
|
||||
it { expect(subject).to eq(data) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
|
||||
|
||||
context 'when a public dropdown champ' do
|
||||
let(:controllers) { ['autosave'] }
|
||||
let(:champ) { create(:champ_drop_down_list, dossier: dossier) }
|
||||
let(:types_de_champ_public) { [{ type: :drop_down_list }] }
|
||||
|
||||
it { expect(subject).to eq(data) }
|
||||
end
|
||||
|
||||
context 'when a private dropdown champ' do
|
||||
let(:controllers) { ['autosave'] }
|
||||
let(:champ) { create(:champ_drop_down_list, dossier: dossier, private: true) }
|
||||
let(:types_de_champ_private) { [{ type: :drop_down_list }] }
|
||||
|
||||
it { expect(subject).to eq(data) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a public dropdown champ' do
|
||||
let(:controllers) { ['autosave'] }
|
||||
let(:champ) { create(:champ_drop_down_list, dossier: dossier) }
|
||||
|
||||
it { expect(subject).to eq(data) }
|
||||
end
|
||||
|
||||
context 'when a private dropdown champ' do
|
||||
let(:controllers) { ['autosave'] }
|
||||
let(:champ) { create(:champ_drop_down_list, dossier: dossier, private: true) }
|
||||
|
||||
it { expect(subject).to eq(data) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
describe EditableChamp::ExplicationComponent, type: :component do
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
||||
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
|
||||
let(:component) {
|
||||
described_class.new(form: instance_double(ActionView::Helpers::FormBuilder, object_name: "dossier[champs_public_attributes]"), champ:)
|
||||
}
|
||||
|
||||
let(:champ) { create(:champ_explication) }
|
||||
|
||||
describe 'no description' do
|
||||
let(:types_de_champ_public) { [{ type: :explication }] }
|
||||
|
||||
subject { render_inline(component).to_html }
|
||||
|
||||
it { is_expected.not_to have_button("Lire plus") }
|
||||
end
|
||||
|
||||
describe 'collapsed text is collapsed' do
|
||||
subject { render_inline(component).to_html }
|
||||
let(:types_de_champ_public) { [{ type: :explication, collapsible_explanation_enabled: "1", collapsible_explanation_text: "hide me" }] }
|
||||
|
||||
before do
|
||||
champ.type_de_champ.update!(collapsible_explanation_enabled: "1", collapsible_explanation_text: "hide me")
|
||||
end
|
||||
subject { render_inline(component).to_html }
|
||||
|
||||
it { is_expected.to have_button("Lire plus") }
|
||||
it { is_expected.to have_selector(".fr-collapse", text: "hide me") }
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
describe EditableChamp::PieceJustificativeComponent, type: :component do
|
||||
let(:champ) { create(:champ_piece_justificative, dossier: create(:dossier)) }
|
||||
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
||||
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
||||
let(:dossier) { create(:dossier, :with_populated_champs, procedure:) }
|
||||
let(:champ) { dossier.champs.first }
|
||||
|
||||
let(:component) {
|
||||
described_class.new(form: instance_double(ActionView::Helpers::FormBuilder, object_name: "dossier[champs_public_attributes]"), champ:)
|
||||
}
|
||||
|
@ -9,7 +13,6 @@ describe EditableChamp::PieceJustificativeComponent, type: :component do
|
|||
}
|
||||
|
||||
context 'when there is a template' do
|
||||
let(:template) { champ.type_de_champ.piece_justificative_template }
|
||||
let(:profil) { :user }
|
||||
|
||||
before do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue