|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe PageListComponent::View, type: :component do |
4 | | - let(:form) { create :form } |
| 4 | + let(:form) { create :form, :with_group } |
5 | 5 | let(:pages) { form.reload.pages } |
6 | 6 | let(:page_list_component) { described_class.new(pages:, form:) } |
7 | 7 |
|
|
46 | 46 | end |
47 | 47 |
|
48 | 48 | context "when the form has multiple pages" do |
49 | | - let(:form) { create :form, :with_pages } |
| 49 | + let(:form) { create :form, :with_pages, :with_group } |
50 | 50 | let(:first_page) { form.pages.first } |
51 | 51 | let(:second_page) { form.pages.second } |
52 | 52 |
|
|
79 | 79 | end |
80 | 80 |
|
81 | 81 | context "when the form has conditions" do |
82 | | - let(:form) { create :form, :ready_for_routing } |
| 82 | + let(:form) { create :form, :ready_for_routing, :with_group } |
83 | 83 | let(:edit_condition_path) { "/forms/0/pages/1/conditions/1" } |
84 | 84 |
|
85 | 85 | context "when the page has a single condition" do |
|
144 | 144 | end |
145 | 145 |
|
146 | 146 | context "when the form has a valid branch route" do |
147 | | - let(:form) { create :form, :ready_for_routing } |
| 147 | + let(:form) { create :form, :ready_for_routing, :with_group } |
148 | 148 | let!(:secondary_skip_condition) { create :condition, routing_page_id: pages.second.id, check_page_id: pages.first.id, answer_value: nil, goto_page_id: pages.fourth.id } |
149 | 149 |
|
150 | 150 | before do |
|
164 | 164 | end |
165 | 165 |
|
166 | 166 | context "when the form has a branch route with an error" do |
167 | | - let(:form) { create :form, :ready_for_routing } |
| 167 | + let(:form) { create :form, :ready_for_routing, :with_group } |
168 | 168 |
|
169 | 169 | before do |
170 | 170 | create :condition, routing_page_id: pages.first.id, check_page_id: pages.first.id, answer_value: "Option 1", goto_page_id: pages.third.id |
|
183 | 183 | end |
184 | 184 |
|
185 | 185 | describe "class methods" do |
186 | | - let(:form) { create :form, :with_pages } |
| 186 | + let(:form) { create :form, :with_pages, :with_group } |
187 | 187 |
|
188 | 188 | describe "show_up_button" do |
189 | 189 | it "returns false when index is 0" do |
|
322 | 322 | end |
323 | 323 | end |
324 | 324 | end |
| 325 | + |
| 326 | + describe "#branch_condition_description" do |
| 327 | + context "when condition has all values set" do |
| 328 | + let(:condition) do |
| 329 | + create( |
| 330 | + :condition, |
| 331 | + routing_page_id: pages.first.id, |
| 332 | + check_page_id: pages.first.id, |
| 333 | + answer_value: "Option 1", |
| 334 | + goto_page_id: pages.third.id, |
| 335 | + ) |
| 336 | + end |
| 337 | + |
| 338 | + it "returns complete condition description" do |
| 339 | + expected_text = "“#{condition.answer_value}” go to #{pages.third.position}, “#{pages.third.question_text}”" |
| 340 | + expect(page_list_component.branch_condition_description(condition)).to eq(expected_text) |
| 341 | + end |
| 342 | + end |
| 343 | + |
| 344 | + context "when answer value is 'none_of_the_above'" do |
| 345 | + let(:condition) do |
| 346 | + create( |
| 347 | + :condition, |
| 348 | + routing_page_id: pages.first.id, |
| 349 | + check_page_id: pages.first.id, |
| 350 | + answer_value: "none_of_the_above", |
| 351 | + goto_page_id: pages.third.id, |
| 352 | + ) |
| 353 | + end |
| 354 | + |
| 355 | + it "returns description with 'None of the above' text" do |
| 356 | + expected_text = "“None of the above” go to #{pages.third.position}, “#{pages.third.question_text}”" |
| 357 | + expect(page_list_component.branch_condition_description(condition)).to eq(expected_text) |
| 358 | + end |
| 359 | + end |
| 360 | + |
| 361 | + context "when skip_to_end is true" do |
| 362 | + let(:condition) do |
| 363 | + create( |
| 364 | + :condition, |
| 365 | + routing_page_id: pages.first.id, |
| 366 | + check_page_id: pages.first.id, |
| 367 | + answer_value: "Option 1", |
| 368 | + goto_page_id: nil, |
| 369 | + skip_to_end: true, |
| 370 | + ) |
| 371 | + end |
| 372 | + |
| 373 | + it "returns description with 'Check your answers' text" do |
| 374 | + expected_text = "“#{condition.answer_value}” go to end of form." |
| 375 | + expect(page_list_component.branch_condition_description(condition)).to eq(expected_text) |
| 376 | + end |
| 377 | + end |
| 378 | + |
| 379 | + context "when showing an unconditional route" do |
| 380 | + let(:condition) do |
| 381 | + create( |
| 382 | + :condition, |
| 383 | + routing_page_id: pages.second.id, |
| 384 | + check_page_id: pages.first.id, |
| 385 | + answer_value: nil, |
| 386 | + goto_page_id: pages.fourth.id, |
| 387 | + ) |
| 388 | + end |
| 389 | + |
| 390 | + it "returns correct description" do |
| 391 | + expected_text = "Go to #{pages.fourth.position}, “#{pages.fourth.question_text}”" |
| 392 | + expect(page_list_component.branch_condition_description(condition)).to eq(expected_text) |
| 393 | + end |
| 394 | + end |
| 395 | + end |
325 | 396 | end |
326 | 397 | end |
0 commit comments