|
3 | 3 | describe RouteSummaryCardDataPresenter do |
4 | 4 | include Capybara::RSpecMatchers |
5 | 5 |
|
6 | | - subject(:service) { described_class.new(form:, page: current_page, pages:) } |
| 6 | + subject(:service) { described_class.new(form:, pages:, page: current_page, routes:) } |
7 | 7 |
|
8 | 8 | let(:form) { build :form, id: 99, pages: } |
9 | 9 |
|
10 | 10 | let(:current_page) do |
11 | 11 | build(:page, id: 1, position: 1, question_text: "Current Question", next_page: next_page.id, routing_conditions:) |
12 | 12 | end |
13 | 13 |
|
| 14 | + let(:routes) do |
| 15 | + PageRoutesService.new(form:, pages:, page: current_page).routes |
| 16 | + end |
| 17 | + |
14 | 18 | let(:next_page) do |
15 | 19 | build(:page, id: 2, position: 2, question_text: "Next Question", routing_conditions: next_page_routing_conditions) |
16 | 20 | end |
|
29 | 33 | allow(form).to receive(:group).and_return(build(:group)) |
30 | 34 | end |
31 | 35 |
|
32 | | - describe ".call" do |
33 | | - it "instantiates and returns a new instance" do |
34 | | - service = described_class.call(form:, page: current_page, pages:) |
35 | | - expect(service).to be_an_instance_of(described_class) |
36 | | - end |
37 | | - end |
38 | | - |
39 | 36 | describe "#summary_card_data" do |
40 | 37 | context "with conditional routes" do |
41 | 38 | it "returns an array of route cards including conditional and default routes" do |
|
142 | 139 | expect(result[0][:rows][0][:value][:text]).to eq("Check your answers before submitting") |
143 | 140 | end |
144 | 141 | end |
145 | | - |
146 | | - describe "#all_routes" do |
147 | | - context "when no pages have conditions" do |
148 | | - let(:routing_conditions) { [] } |
149 | | - |
150 | | - it "is an empty array when there are no matching conditions" do |
151 | | - expect(service.all_routes).to be_empty |
152 | | - end |
153 | | - end |
154 | | - |
155 | | - context "when pages have conditions with matching check_page_ids" do |
156 | | - let(:pages) do |
157 | | - [ |
158 | | - build(:page, id: 1, position: 1, question_text: "Current Question", next_page: next_page.id, routing_conditions: [ |
159 | | - build(:condition, id: 1, routing_page_id: 1, check_page_id: 1, answer_value: "Yes", goto_page_id: 2, skip_to_end: false), |
160 | | - ]), |
161 | | - build(:page, id: 2, position: 2, question_text: "Next Question", routing_conditions: [ |
162 | | - build(:condition, id: 1, routing_page_id: 2, check_page_id: 1, answer_value: nil, goto_page_id: nil, skip_to_end: true), |
163 | | - ]), |
164 | | - build(:page, id: 3, position: 3, question_text: "unrelated question", routing_conditions: [ |
165 | | - build(:condition, id: 1, routing_page_id: 3, check_page_id: 3, answer_value: "Unrelated", goto_page_id: 5, skip_to_end: false), |
166 | | - ]), |
167 | | - ] |
168 | | - end |
169 | | - |
170 | | - it "returns all condtions which match the check_page_id" do |
171 | | - expected_condtions = pages.first.routing_conditions + pages.second.routing_conditions |
172 | | - expect(service.all_routes).to match_array(expected_condtions) |
173 | | - end |
174 | | - end |
175 | | - end |
176 | 142 | end |
177 | 143 | end |
0 commit comments