|
12 | 12 | let(:attributes) do |
13 | 13 | { |
14 | 14 | id: 1, |
15 | | - page_id: 2, |
| 15 | + page_id: page.id, |
16 | 16 | goto: goto_page.id, |
17 | 17 | answer_value: "Yes", |
18 | 18 | page: page, |
|
27 | 27 | describe "attributes" do |
28 | 28 | it "can be initialized with a hash of attributes" do |
29 | 29 | expect(route_input.id).to eq(1) |
30 | | - expect(route_input.page_id).to eq(2) |
| 30 | + expect(route_input.page_id).to eq(page.id) |
31 | 31 | expect(route_input.goto).to eq(goto_page.id) |
32 | 32 | expect(route_input.answer_value).to eq("Yes") |
33 | 33 | expect(route_input.page).to eq(page) |
34 | 34 | end |
35 | | - |
36 | | - it "allows access to other accessors like label" do |
37 | | - route_input.label = "Go to next page" |
38 | | - expect(route_input.label).to eq("Go to next page") |
39 | | - end |
40 | 35 | end |
41 | 36 |
|
42 | 37 | describe "#goes_to_default_next_page?" do |
|
104 | 99 | end |
105 | 100 | end |
106 | 101 |
|
| 102 | + describe "#label" do |
| 103 | + context "when the route is to the next page" do |
| 104 | + it "returns the correct label" do |
| 105 | + expect(route_input.label).to eq({ text: "After question 1, go to:" }) |
| 106 | + end |
| 107 | + end |
| 108 | + |
| 109 | + context "when the route is for a generic page" do |
| 110 | + let(:middle_page) { build_stubbed(:page, position: 2) } |
| 111 | + let(:goto_page) { build_stubbed(:page, position: 3) } |
| 112 | + |
| 113 | + it "sets the label correctly for a generic page" do |
| 114 | + expect(route_input.label).to eq({ text: "After question 1, go to:" }) |
| 115 | + end |
| 116 | + end |
| 117 | + |
| 118 | + context "when the route is for a selection page" do |
| 119 | + let(:page) { build_stubbed(:page, :with_selection_settings, position: 1) } |
| 120 | + let(:goto_page) { build_stubbed(:page, position: 2) } |
| 121 | + let(:attributes) { super().merge(answer_value: "Option 1") } |
| 122 | + |
| 123 | + it "sets the label correctly for a selection page" do |
| 124 | + expect(route_input.label).to eq({ text: "If option 1 (Option 1), go to:" }) |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + context "when the route is for a selection page with a none of the above option" do |
| 129 | + let(:page) { build_stubbed(:page, :with_selection_settings, position: 1) } |
| 130 | + let(:goto_page) { build_stubbed(:page, position: 2) } |
| 131 | + let(:attributes) { super().merge(answer_value: Condition::NONE_OF_THE_ABOVE) } |
| 132 | + |
| 133 | + it "sets the label correctly for a selection page with a none of the above option" do |
| 134 | + expect(route_input.label).to eq({ text: "If option 3 (None of the above), go to:" }) |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | + |
107 | 139 | describe "#route_is_not_backwards" do |
108 | 140 | context "when the route is not backwards" do |
109 | 141 | let(:page) { build_stubbed(:page, position: 1) } |
|
0 commit comments