Skip to content

Commit 8fafef8

Browse files
committed
Refactor spec for PageList answer_value_groups
Change the spec for PageListComponent::View#answer_value_groups to use a stub form and pages, rather than using create. This is a bit longer but making it more explicit will let us change the order of the options later. Supplying the selection_options like this ensures lets us build valid conditions for the page. Not using create speeds up the tests.
1 parent 910b36a commit 8fafef8

1 file changed

Lines changed: 40 additions & 13 deletions

File tree

spec/components/page_list_component/view_spec.rb

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -520,21 +520,48 @@
520520
end
521521

522522
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
529556

530557
it "groups conditions by goto_page_id" do
531-
expect(page_list_component.answer_value_groups(pages.first.reload)).to eq(
532-
[
533-
[pages.third.id, [first_condition, second_condition]],
534-
[pages.fourth.id, [third_condition]],
535-
[nil, [fourth_condition]],
536-
],
537-
)
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
538565
end
539566
end
540567
end

0 commit comments

Comments
 (0)