|
22 | 22 | get welsh_translation_path(id) |
23 | 23 | end |
24 | 24 |
|
25 | | - it "returns 200" do |
26 | | - expect(response).to have_http_status(:ok) |
27 | | - end |
28 | | - |
29 | 25 | it "renders the template" do |
| 26 | + expect(response).to have_http_status(:ok) |
30 | 27 | expect(response).to render_template(:new) |
31 | 28 | end |
32 | 29 |
|
|
54 | 51 | let(:params) { { forms_welsh_translation_input: { form:, mark_complete:, name_cy: "Gwneud cais am drwydded jyglo", privacy_policy_url_cy: "https://juggling.gov.uk/privacy_policy/cy", page_translations_attributes: } } } |
55 | 52 |
|
56 | 53 | context "when 'Yes' is selected" do |
57 | | - it "updates the form" do |
| 54 | + it "updates the form, pages and conditions" do |
58 | 55 | expect { |
59 | 56 | post(welsh_translation_create_path(id), params:) |
60 | 57 | }.to change { form.reload.welsh_completed }.to(true) |
| 58 | + .and change { form.pages.first.reload.question_text_cy }.to("Ydych chi'n adnewyddu trwydded?") |
| 59 | + .and change { condition.reload.exit_page_heading_cy }.to("Nid ydych yn gymwys") |
61 | 60 | end |
62 | 61 |
|
63 | | - it "updates the form's pages" do |
64 | | - expect { |
65 | | - post(welsh_translation_create_path(id), params:) |
66 | | - }.to change { form.pages.first.reload.question_text_cy }.to("Ydych chi'n adnewyddu trwydded?") |
67 | | - end |
68 | | - |
69 | | - it "updates the form's conditions" do |
70 | | - expect { |
71 | | - post(welsh_translation_create_path(id), params:) |
72 | | - }.to change { condition.reload.exit_page_heading_cy }.to("Nid ydych yn gymwys") |
73 | | - end |
74 | | - |
75 | | - it "redirects to the form" do |
| 62 | + it "redirects to the form task list and displays a success banner including text about being marked complete" do |
76 | 63 | post(welsh_translation_create_path(id), params:) |
77 | 64 | expect(response).to redirect_to(form_path(id)) |
78 | | - end |
79 | | - |
80 | | - it "displays a success banner including text about being marked complete" do |
81 | | - post(welsh_translation_create_path(id), params:) |
82 | 65 | expect(flash[:success]).to eq(I18n.t("banner.success.form.welsh_translation_saved_and_completed")) |
83 | 66 | end |
84 | 67 | end |
|
87 | 70 | let(:mark_complete) { "false" } |
88 | 71 | let(:form) { create(:form, :ready_for_routing, welsh_completed: true) } |
89 | 72 |
|
90 | | - it "updates the form" do |
| 73 | + it "updates the form and redirects to the form task list" do |
91 | 74 | expect { |
92 | 75 | post(welsh_translation_create_path(id), params:) |
93 | 76 | }.to change { form.reload.welsh_completed }.to(false) |
94 | 77 | end |
95 | 78 |
|
96 | | - it "redirects to the form" do |
| 79 | + it "redirects to the form and displays a success banner without text about being marked complete" do |
97 | 80 | post(welsh_translation_create_path(id), params:) |
98 | 81 | expect(response).to redirect_to(form_path(id)) |
99 | | - end |
100 | | - |
101 | | - it "displays a success banner without text about being marked complete" do |
102 | | - post(welsh_translation_create_path(id), params:) |
103 | 82 | expect(flash[:success]).to eq(I18n.t("banner.success.form.welsh_translation_saved")) |
104 | 83 | end |
105 | 84 | end |
106 | 85 |
|
107 | 86 | context "when no value is selected" do |
108 | 87 | let(:mark_complete) { "" } |
109 | 88 |
|
110 | | - it "does not update the form" do |
111 | | - expect { |
112 | | - post(welsh_translation_create_path(id), params:) |
113 | | - }.not_to(change { form.reload.welsh_completed }) |
114 | | - end |
115 | | - |
116 | | - it "does not update the form's pages" do |
| 89 | + it "does not update the form, pages or conditions" do |
117 | 90 | expect { |
118 | 91 | post(welsh_translation_create_path(id), params:) |
119 | | - }.not_to(change { form.pages.first.reload.question_text_cy }) |
| 92 | + }.to not_change { form.reload.welsh_completed } |
| 93 | + .and not_change { form.pages.first.reload.question_text_cy } |
| 94 | + .and(not_change { condition.reload.exit_page_markdown_cy }) |
120 | 95 | end |
121 | 96 |
|
122 | | - it "does not update the form's conditions" do |
123 | | - expect { |
124 | | - post(welsh_translation_create_path(id), params:) |
125 | | - }.not_to(change { condition.reload.exit_page_markdown_cy }) |
126 | | - end |
127 | | - |
128 | | - it "returns a 422" do |
| 97 | + it "returns a 422, re-renders the page with an error, and does not display a success banner" do |
129 | 98 | post(welsh_translation_create_path(id), params:) |
130 | | - expect(response).to have_http_status(:unprocessable_content) |
131 | | - end |
132 | 99 |
|
133 | | - it "re-renders the page with an error" do |
134 | | - post(welsh_translation_create_path(id), params:) |
| 100 | + expect(response).to have_http_status(:unprocessable_content) |
135 | 101 | expect(response).to render_template(:new) |
136 | 102 | expect(response.body).to include(I18n.t("activemodel.errors.models.forms/welsh_translation_input.attributes.mark_complete.blank")) |
137 | | - end |
138 | | - |
139 | | - it "does not display a success banner" do |
140 | | - post(welsh_translation_create_path(id), params:) |
141 | 103 | expect(flash).to be_empty |
142 | 104 | end |
143 | 105 | end |
144 | 106 |
|
145 | 107 | context "when the user is not authorized" do |
146 | 108 | let(:current_user) { build :user } |
147 | 109 |
|
148 | | - it "does not update the form" do |
149 | | - expect { |
150 | | - post(welsh_translation_create_path(id), params:) |
151 | | - }.not_to(change { form.reload.welsh_completed }) |
152 | | - end |
153 | | - |
154 | | - it "does not update the form's pages" do |
155 | | - expect { |
156 | | - post(welsh_translation_create_path(id), params:) |
157 | | - }.not_to(change { form.pages.first.reload.question_text_cy }) |
158 | | - end |
159 | | - |
160 | | - it "does not update the form's conditions" do |
| 110 | + it "does not update the form, pages or conditions" do |
161 | 111 | expect { |
162 | 112 | post(welsh_translation_create_path(id), params:) |
163 | | - }.not_to(change { condition.reload.exit_page_heading_cy }) |
| 113 | + }.to not_change { form.reload.welsh_completed } |
| 114 | + .and not_change { form.pages.first.reload.question_text_cy } |
| 115 | + .and(not_change { condition.reload.exit_page_markdown_cy }) |
164 | 116 | end |
165 | 117 |
|
166 | 118 | it "returns 403" do |
|
172 | 124 | context "when the welsh feature is not enabled for the group" do |
173 | 125 | let(:welsh_enabled) { false } |
174 | 126 |
|
175 | | - it "does not update the form" do |
176 | | - expect { |
177 | | - post(welsh_translation_create_path(id), params:) |
178 | | - }.not_to(change { form.reload.welsh_completed }) |
179 | | - end |
180 | | - |
181 | | - it "does not update the form's pages" do |
| 127 | + it "does not update the form, pages or conditions" do |
182 | 128 | expect { |
183 | 129 | post(welsh_translation_create_path(id), params:) |
184 | | - }.not_to(change { form.pages.first.reload.question_text_cy }) |
185 | | - end |
186 | | - |
187 | | - it "does not update the form's conditions" do |
188 | | - expect { |
189 | | - post(welsh_translation_create_path(id), params:) |
190 | | - }.not_to(change { condition.reload.exit_page_heading_cy }) |
| 130 | + }.to not_change { form.reload.welsh_completed } |
| 131 | + .and not_change { form.pages.first.reload.question_text_cy } |
| 132 | + .and(not_change { condition.reload.exit_page_markdown_cy }) |
191 | 133 | end |
192 | 134 |
|
193 | 135 | it "redirects to the form" do |
|
306 | 248 | end |
307 | 249 | end |
308 | 250 | end |
| 251 | + |
| 252 | + describe "#render_preview" do |
| 253 | + let(:markdown) { "[Markdown](https://example.com)" } |
| 254 | + |
| 255 | + before do |
| 256 | + post welsh_translation_render_preview_path(form_id: form.id), params: { markdown: } |
| 257 | + end |
| 258 | + |
| 259 | + it "returns a JSON object containing the converted HTML" do |
| 260 | + expect(response).to have_http_status(:ok) |
| 261 | + expect(response.body).to eq({ |
| 262 | + preview_html: "<p class=\"govuk-body\"><a href=\"https://example.com\" class=\"govuk-link\" rel=\"noreferrer noopener\" target=\"_blank\">Markdown (agor mewn tab newydd)</a></p>", |
| 263 | + errors: [], |
| 264 | + }.to_json) |
| 265 | + end |
| 266 | + |
| 267 | + context "when markdown is blank" do |
| 268 | + let(:markdown) { "" } |
| 269 | + |
| 270 | + it "returns a JSON object containing the converted HTML" do |
| 271 | + expect(response).to have_http_status(:ok) |
| 272 | + expect(response.body).to eq({ preview_html: I18n.t("guidance.no_guidance_added_html"), errors: [] }.to_json) |
| 273 | + end |
| 274 | + end |
| 275 | + end |
309 | 276 | end |
0 commit comments