demarches-normaliennes/spec/models/procedure_presentation_spec.rb

73 lines
2.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
describe ProcedurePresentation do
include ActiveSupport::Testing::TimeHelpers
let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private: [{}]) }
let(:procedure_id) { procedure.id }
let(:types_de_champ_public) { [{}] }
let(:instructeur) { create(:instructeur) }
let(:assign_to) { create(:assign_to, procedure:, instructeur:) }
let(:first_type_de_champ) { assign_to.procedure.active_revision.types_de_champ_public.first }
2020-10-30 15:01:13 +01:00
let(:first_type_de_champ_id) { first_type_de_champ.stable_id.to_s }
let(:procedure_presentation) {
create(:procedure_presentation,
assign_to:,
2017-09-28 11:04:18 +02:00
displayed_fields: [
{ label: "test1", table: "user", column: "email" },
{ label: "test2", table: "type_de_champ", column: first_type_de_champ_id }
],
sort: { table: "user", column: "email", "order" => "asc" },
filters: filters)
2017-09-28 11:04:18 +02:00
}
let(:procedure_presentation_id) { procedure_presentation.id }
let(:filters) { { "a-suivre" => [], "suivis" => [{ "label" => "label1", "table" => "self", "column" => "created_at" }] } }
def to_filter((label, filter)) = FilteredColumn.new(column: procedure.find_column(label: label), filter: filter)
describe 'validation' do
it { expect(build(:procedure_presentation)).to be_valid }
2024-10-07 15:00:05 +02:00
context 'of displayed columns' do
it do
pp = build(:procedure_presentation, displayed_columns: [{ table: "user", column: "reset_password_token", procedure_id: }])
expect { pp.displayed_columns }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'of filters' do
it 'validates the filter_column objects' do
expect(build(:procedure_presentation, "suivis_filters": [{ id: { column_id: "user/email", procedure_id: }, "filter": "not so long filter value" }])).to be_valid
expect(build(:procedure_presentation, "suivis_filters": [{ id: { column_id: "user/email", procedure_id: }, "filter": "exceedingly long filter value" * 400 }])).to be_invalid
end
end
2017-09-28 11:04:18 +02:00
end
2024-10-07 22:04:44 +02:00
describe '#update_displayed_fields' do
let(:en_construction_column) { procedure.find_column(label: 'Date de passage en construction') }
let(:mise_a_jour_column) { procedure.find_column(label: 'Date du dernier évènement') }
2024-10-07 15:00:05 +02:00
2024-10-07 22:04:44 +02:00
let(:procedure_presentation) do
create(:procedure_presentation, assign_to:).tap do |pp|
pp.update(sorted_column: SortedColumn.new(column: procedure.find_column(label: 'Demandeur'), order: 'desc'))
2024-10-07 22:04:44 +02:00
end
end
subject do
2024-10-07 15:00:05 +02:00
procedure_presentation.update(displayed_columns: [
en_construction_column.id, mise_a_jour_column.id
2024-10-07 22:04:44 +02:00
])
end
it 'should update displayed_fields' do
2024-10-07 15:00:05 +02:00
expect(procedure_presentation.displayed_columns).to eq(procedure.default_displayed_columns)
2024-10-07 22:04:44 +02:00
subject
expect(procedure_presentation.displayed_columns).to eq([
2024-10-07 15:00:05 +02:00
en_construction_column, mise_a_jour_column
2024-10-07 22:04:44 +02:00
])
2024-10-07 22:02:43 +02:00
end
end
end