|
520 | 520 | end |
521 | 521 |
|
522 | 522 | describe "#answer_value_groups" do |
523 | | - let(:form) { create :form, :ready_for_routing } |
524 | | - let(:pages) { form.reload.pages } |
525 | | - let!(:first_condition) { create :condition, routing_page_id: pages.first.id, answer_value: "Option 1", goto_page_id: pages.third.id } |
526 | | - let!(:second_condition) { create :condition, routing_page_id: pages.first.id, answer_value: "Option 2", goto_page_id: pages.third.id } |
527 | | - let!(:third_condition) { create :condition, routing_page_id: pages.first.id, answer_value: "Option 3", goto_page_id: pages.fourth.id } |
528 | | - let!(:fourth_condition) { create :condition, routing_page_id: pages.first.id, answer_value: "Option 3", goto_page_id: nil, skip_to_end: true } |
| 523 | + let(:form) { build_stubbed :form, :ready_for_routing } |
| 524 | + |
| 525 | + let(:pages) do |
| 526 | + [ |
| 527 | + build_stubbed( |
| 528 | + :page, |
| 529 | + :with_selection_settings, |
| 530 | + id: 101, |
| 531 | + selection_options:, |
| 532 | + routing_conditions: conditions, |
| 533 | + ), |
| 534 | + build_stubbed(:page, id: 102), |
| 535 | + build_stubbed(:page, id: 103), |
| 536 | + build_stubbed(:page, id: 104), |
| 537 | + ] |
| 538 | + end |
| 539 | + |
| 540 | + let(:selection_options) do |
| 541 | + [ |
| 542 | + { value: "Option 1" }, |
| 543 | + { value: "Option 2" }, |
| 544 | + { value: "Option 3" }, |
| 545 | + ] |
| 546 | + end |
| 547 | + |
| 548 | + let(:conditions) do |
| 549 | + [ |
| 550 | + build_stubbed(:condition, routing_page_id: 101, answer_value: "Option 1", goto_page_id: 103), |
| 551 | + build_stubbed(:condition, routing_page_id: 101, answer_value: "Option 2", goto_page_id: 103), |
| 552 | + build_stubbed(:condition, routing_page_id: 101, answer_value: "Option 3", goto_page_id: 104), |
| 553 | + build_stubbed(:condition, routing_page_id: 101, answer_value: nil, goto_page_id: nil, skip_to_end: true), |
| 554 | + ] |
| 555 | + end |
529 | 556 |
|
530 | 557 | it "groups conditions by goto_page_id" do |
531 | | - expect(page_list_component.answer_value_groups(pages.first.reload)).to eq( |
| 558 | + expected = [ |
| 559 | + [103, [conditions.first, conditions.second]], |
| 560 | + [104, [conditions.third]], |
| 561 | + [nil, [conditions.fourth]], |
| 562 | + ] |
| 563 | + result = page_list_component.answer_value_groups(pages.first) |
| 564 | + expect(result).to eq expected |
| 565 | + end |
| 566 | + |
| 567 | + context "when given a different order of selection options" do |
| 568 | + let(:selection_options) do |
532 | 569 | [ |
533 | | - [pages.third.id, [first_condition, second_condition]], |
534 | | - [pages.fourth.id, [third_condition]], |
535 | | - [nil, [fourth_condition]], |
536 | | - ], |
537 | | - ) |
| 570 | + { value: "Option 3" }, |
| 571 | + { value: "Option 2" }, |
| 572 | + { value: "Option 1" }, |
| 573 | + ] |
| 574 | + end |
| 575 | + |
| 576 | + it "returns the conditions in the same order" do |
| 577 | + expected = [ |
| 578 | + [103, [conditions.second, conditions.first]], |
| 579 | + [104, [conditions.third]], |
| 580 | + [nil, [conditions.fourth]], |
| 581 | + ] |
| 582 | + |
| 583 | + result = page_list_component.answer_value_groups(pages.first) |
| 584 | + expect(result).to eq expected |
| 585 | + end |
538 | 586 | end |
539 | 587 | end |
540 | 588 | end |
0 commit comments