|
40 | 40 | end |
41 | 41 |
|
42 | 42 | describe "GET #show" do |
| 43 | + before do |
| 44 | + get add_another_answer_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: first_step_in_form.id) |
| 45 | + end |
| 46 | + |
43 | 47 | it "renders the show template" do |
44 | | - get "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer" |
45 | 48 | expect(response).to render_template(:show) |
46 | 49 | end |
47 | 50 |
|
48 | 51 | it "assigns @rows" do |
49 | | - get "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer" |
50 | 52 | expect(assigns(:rows).count).to eq 2 |
51 | 53 | end |
52 | 54 |
|
53 | 55 | it "adds the change and remove links to each row" do |
54 | | - get "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer" |
55 | 56 | expect(assigns(:rows).first[:actions].first[:text]).to eq("Change") |
56 | 57 | expect(assigns(:rows).first[:actions].second[:text]).to eq("Remove") |
57 | 58 | expect(response.body).to include(form_remove_answer_path(form.id, form.form_slug, first_step_in_form.id, answer_index: 1, changing_existing_answer: nil)) |
58 | 59 | end |
59 | 60 |
|
60 | 61 | it "initializes @add_another_answer_input" do |
61 | | - get "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer" |
62 | 62 | expect(assigns(:add_another_answer_input)).to be_a(AddAnotherAnswerInput) |
63 | 63 | end |
64 | 64 | end |
65 | 65 |
|
66 | 66 | describe "POST #save" do |
| 67 | + before do |
| 68 | + post add_another_answer_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: first_step_in_form.id), params: |
| 69 | + end |
| 70 | + |
67 | 71 | context "with valid params" do |
68 | 72 | context "when adding another answer" do |
| 73 | + let(:params) { { add_another_answer_input: { add_another_answer: "yes" } } } |
| 74 | + |
69 | 75 | it "redirects to first page to add another" do |
70 | | - post "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer", params: { add_another_answer_input: { add_another_answer: "yes" } } |
71 | | - expect(response).to redirect_to("/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/3") |
| 76 | + expect(response).to redirect_to(form_page_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: first_step_in_form.id, answer_index: 3)) |
72 | 77 | end |
73 | 78 | end |
74 | 79 |
|
75 | 80 | context "when not adding another answer" do |
| 81 | + let(:params) { { add_another_answer_input: { add_another_answer: "no" } } } |
| 82 | + |
76 | 83 | it "redirects to next page" do |
77 | | - post "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer", params: { add_another_answer_input: { add_another_answer: "no" } } |
78 | | - expect(response).to redirect_to("/preview-draft/#{form.id}/#{form.form_slug}/#{second_step_in_form.id}") |
| 84 | + expect(response).to redirect_to(form_page_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: second_step_in_form.id)) |
79 | 85 | end |
80 | 86 | end |
81 | 87 | end |
82 | 88 |
|
83 | 89 | context "with invalid params" do |
| 90 | + let(:params) { { add_another_answer_input: { add_another_answer: "" } } } |
| 91 | + |
84 | 92 | it "renders the show template" do |
85 | | - post "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer", params: { add_another_answer_input: { add_another_answer: "" } } |
86 | 93 | expect(response).to render_template(:show) |
87 | 94 | end |
88 | 95 |
|
89 | 96 | it "assigns @rows" do |
90 | | - post "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer", params: { add_another_answer_input: { add_another_answer: "" } } |
91 | 97 | expect(assigns(:rows).count).to be_present |
92 | 98 | end |
93 | 99 | end |
94 | 100 |
|
95 | 101 | context "with the maximum number of answers" do |
96 | 102 | let(:stored_answers) { Array.new(RepeatableStep::MAX_ANSWERS) { |i| { text: i.to_s } } } |
| 103 | + let(:params) { { add_another_answer_input: { add_another_answer: "yes" } } } |
97 | 104 |
|
98 | 105 | it "renders the show template with an error" do |
99 | | - post "/preview-draft/#{form.id}/#{form.form_slug}/#{first_step_in_form.id}/add-another-answer", params: { add_another_answer_input: { add_another_answer: "yes" } } |
| 106 | + post add_another_answer_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: first_step_in_form.id), params: { add_another_answer_input: { add_another_answer: "yes" } } |
100 | 107 | expect(response).to render_template(:show) |
101 | 108 | expect(response.body).to include("You cannot add another answer") |
102 | 109 | end |
|
106 | 113 | describe "redirect_if_not_repeating" do |
107 | 114 | context "when step is not RepeatableStep" do |
108 | 115 | it "redirects to form_page when not changing existing answer" do |
109 | | - get "/preview-draft/#{form.id}/#{form.form_slug}/#{second_step_in_form.id}/add-another-answer" |
110 | | - expect(response).to redirect_to("/preview-draft/#{form.id}/#{form.form_slug}/#{second_step_in_form.id}") |
| 116 | + get add_another_answer_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: second_step_in_form.id) |
| 117 | + expect(response).to redirect_to(form_page_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: second_step_in_form.id)) |
111 | 118 | end |
112 | 119 |
|
113 | 120 | it "redirects to form_change_answer_path when changing existing answer" do |
114 | | - get "/preview-draft/#{form.id}/#{form.form_slug}/#{second_step_in_form.id}/add-another-answer/change" |
115 | | - expect(response).to redirect_to("/preview-draft/#{form.id}/#{form.form_slug}/#{second_step_in_form.id}/change") |
| 121 | + get change_add_another_answer_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: second_step_in_form.id) |
| 122 | + expect(response).to redirect_to(form_change_answer_path(mode: "preview-draft", form_id: form.id, form_slug: form.form_slug, page_slug: second_step_in_form.id)) |
116 | 123 | end |
117 | 124 | end |
118 | 125 | end |
|
0 commit comments