|
616 | 616 | end |
617 | 617 | end |
618 | 618 |
|
619 | | - describe "#parent" do |
620 | | - let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, mandatory: false, children: [{ type: :text }] }]) } |
| 619 | + describe "#ancestors, #parent, #section and #repetition" do |
| 620 | + let(:procedure) do |
| 621 | + create(:procedure, types_de_champ_public: [ |
| 622 | + { type: :text, libelle: 't0' }, |
| 623 | + { type: :header_section, level: 1, libelle: 's1' }, |
| 624 | + { type: :header_section, level: 2, libelle: 's1.1' }, |
| 625 | + { |
| 626 | + type: :repetition, mandatory: false, libelle: 'rep', children: [ |
| 627 | + { type: :header_section, level: 1, libelle: 'rs1' }, |
| 628 | + { type: :text, libelle: 'rt1' }, |
| 629 | + ], |
| 630 | + }, |
| 631 | + ]) |
| 632 | + end |
621 | 633 | let(:dossier) { create(:dossier, :with_populated_champs, procedure:) } |
| 634 | + let(:champ) { dossier.filled_champs_public.find { _1.libelle == 'rt1' } } |
| 635 | + |
| 636 | + it "returns the projected champs above, outermost first" do |
| 637 | + expect(champ.ancestors.map(&:libelle)).to eq(['s1', 's1.1', 'rep', 'rs1']) |
| 638 | + expect(champ.ancestors.map(&:row_id)).to eq([nil, nil, nil, champ.row_id]) |
| 639 | + end |
| 640 | + |
| 641 | + it "memoizes ancestors" do |
| 642 | + expect(champ.ancestors).to equal(champ.ancestors) |
| 643 | + end |
622 | 644 |
|
623 | | - let(:champ) { dossier.champ_data.where(type: "Champs::TextChamp").first } |
| 645 | + it "exposes parent, section and repetition" do |
| 646 | + expect(champ.parent.libelle).to eq('rs1') |
| 647 | + expect(champ.parent.row_id).to eq(champ.row_id) |
| 648 | + expect(champ.section.libelle).to eq('rs1') |
| 649 | + expect(champ.repetition.libelle).to eq('rep') |
| 650 | + expect(champ.repetition.row_id).to be_nil |
624 | 651 |
|
625 | | - it "returns the parent" do |
626 | | - expect(champ.parent).to eq(TypeDeChamp.find_by(type_champ: "repetition")) |
| 652 | + root_champ = dossier.project_champs_public.find { _1.libelle == 't0' } |
| 653 | + expect(root_champ.ancestors).to eq([]) |
| 654 | + expect(root_champ.parent).to be_nil |
| 655 | + expect(root_champ.section).to be_nil |
| 656 | + expect(root_champ.repetition).to be_nil |
627 | 657 | end |
628 | 658 | end |
629 | 659 |
|
|
0 commit comments