|
143 | 143 | find("button[data-bs-target='#attached_documents']").click |
144 | 144 | expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true) |
145 | 145 |
|
146 | | - # Upload two documents - needs to be done individually because Capybara doesn't have attach_files multiple support |
147 | | - # https://github.com/teamcapybara/capybara/issues/37 |
| 146 | + # Upload multiple documents at once |
148 | 147 | within "#attached_documents" do |
149 | | - attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document1.md"), make_visible: true) |
| 148 | + attach_file("partner_profile_documents", [ |
| 149 | + Rails.root.join("spec/fixtures/files/document1.md"), |
| 150 | + Rails.root.join("spec/fixtures/files/document2.md") |
| 151 | + ], make_visible: true) |
| 152 | + |
| 153 | + # Verify both documents are displayed in custom selection list |
| 154 | + expect(page).to have_text("Selected files:") |
| 155 | + expect(page).to have_css("[data-file-input-target='list'] li", text: "document1.md") |
| 156 | + expect(page).to have_css("[data-file-input-target='list'] li", text: "document2.md") |
150 | 157 | end |
| 158 | + |
| 159 | + # Save Progress |
151 | 160 | all("input[type='submit'][value='Save Progress']").last.click |
| 161 | + expect(page).to have_css(".alert-success", text: "Details were successfully updated.") |
| 162 | + |
| 163 | + # Verify both documents persist after page reload |
152 | 164 | visit edit_partners_profile_path |
153 | 165 | find("button[data-bs-target='#attached_documents']").click |
154 | 166 | within "#attached_documents" do |
155 | | - attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document2.md"), make_visible: true) |
| 167 | + expect(page).to have_link("document1.md") |
| 168 | + expect(page).to have_link("document2.md") |
156 | 169 | end |
157 | | - all("input[type='submit'][value='Save Progress']").last.click |
158 | 170 |
|
159 | 171 | # Remove the first document |
160 | | - visit edit_partners_profile_path |
161 | | - find("button[data-bs-target='#attached_documents']").click |
162 | 172 | within "#attached_documents" do |
163 | 173 | document_name = "document1.md" |
164 | 174 | document_li = find("li.attached-document", text: document_name) |
|
170 | 180 | all("input[type='submit'][value='Save Progress']").last.click |
171 | 181 | expect(page).to have_css(".alert-success", text: "Details were successfully updated.") |
172 | 182 |
|
173 | | - # Verify only one document is listed |
| 183 | + # Verify only one document remains |
174 | 184 | visit edit_partners_profile_path |
175 | 185 | find("button[data-bs-target='#attached_documents']").click |
176 | 186 | within "#attached_documents" do |
177 | 187 | expect(page).to have_link("document2.md") |
| 188 | + expect(page).not_to have_link("document1.md") |
178 | 189 | end |
179 | 190 | end |
180 | 191 |
|
|
225 | 236 | expect(find("label[for='partner_profile_proof_of_partner_status']")).to have_content("irs_determination_letter.md") |
226 | 237 | end |
227 | 238 | end |
| 239 | + |
| 240 | + it "persists multiple file uploads when there are validation errors" do |
| 241 | + # Open Pick up person section and fill in 4 email addresses which will generate a validation error |
| 242 | + find("button[data-bs-target='#pick_up_person']").click |
| 243 | + within "#pick_up_person" do |
| 244 | + |
| 245 | + end |
| 246 | + |
| 247 | + # Open attached documents section |
| 248 | + find("button[data-bs-target='#attached_documents']").click |
| 249 | + expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true) |
| 250 | + |
| 251 | + # Upload multiple documents |
| 252 | + within "#attached_documents" do |
| 253 | + attach_file("partner_profile_documents", [ |
| 254 | + Rails.root.join("spec/fixtures/files/document1.md"), |
| 255 | + Rails.root.join("spec/fixtures/files/document2.md") |
| 256 | + ], make_visible: true) |
| 257 | + |
| 258 | + # Verify both documents are displayed in custom selection list |
| 259 | + expect(page).to have_css("[data-file-input-target='list'] li", text: "document1.md") |
| 260 | + expect(page).to have_css("[data-file-input-target='list'] li", text: "document2.md") |
| 261 | + end |
| 262 | + |
| 263 | + # Save Progress |
| 264 | + all("input[type='submit'][value='Save Progress']").last.click |
| 265 | + |
| 266 | + # Expect an alert-danger message containing validation errors |
| 267 | + expect(page).to have_css(".alert-danger", text: /There is a problem/) |
| 268 | + |
| 269 | + # Open attached documents section |
| 270 | + find("button[data-bs-target='#attached_documents']").click |
| 271 | + expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true) |
| 272 | + |
| 273 | + # Expect both documents are still displayed in custom list as selected, but nothing is actually attached |
| 274 | + within "#attached_documents" do |
| 275 | + expect(page).to have_text("Selected files:") |
| 276 | + expect(page).to have_css("[data-file-input-target='list'] li", text: "document1.md") |
| 277 | + expect(page).to have_css("[data-file-input-target='list'] li", text: "document2.md") |
| 278 | + |
| 279 | + expect(page).not_to have_text("Attached files:") |
| 280 | + expect(page).not_to have_link("document1.md") |
| 281 | + expect(page).not_to have_link("document2.md") |
| 282 | + end |
| 283 | + |
| 284 | + # Fix validation error in Pick up person section: It's already open due to having a validation error |
| 285 | + within "#pick_up_person" do |
| 286 | + |
| 287 | + end |
| 288 | + |
| 289 | + # Save Progress |
| 290 | + all("input[type='submit'][value='Save Progress']").last.click |
| 291 | + expect(page).to have_css(".alert-success", text: "Details were successfully updated.") |
| 292 | + |
| 293 | + # Open attached documents section |
| 294 | + find("button[data-bs-target='#attached_documents']").click |
| 295 | + expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true) |
| 296 | + |
| 297 | + # Expect both documents are now rendered as downloadable links |
| 298 | + # i.e. they've been saved, without user having had to select them again |
| 299 | + within "#attached_documents" do |
| 300 | + expect(page).to have_text("Attached files:") |
| 301 | + expect(page).to have_link("document1.md") |
| 302 | + expect(page).to have_link("document2.md") |
| 303 | + end |
| 304 | + end |
228 | 305 | end |
229 | 306 | end |
0 commit comments