|
100 | 100 | end |
101 | 101 |
|
102 | 102 | it "preserves previously uploaded documents when adding new attachments" do |
103 | | - # Upload the first document |
| 103 | + # Open attached documents section |
104 | 104 | find("button[data-bs-target='#attached_documents']").click |
105 | 105 | expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true) |
106 | 106 |
|
| 107 | + # Upload the first document |
107 | 108 | within "#attached_documents" do |
108 | 109 | attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document1.md"), make_visible: true) |
109 | 110 | end |
|
137 | 138 | end |
138 | 139 | end |
139 | 140 |
|
140 | | - it "persists file upload when there are validation errors" do |
| 141 | + it "allows removal of attached documents" do |
| 142 | + # Open attached documents section |
| 143 | + find("button[data-bs-target='#attached_documents']").click |
| 144 | + expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true) |
| 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 |
| 148 | + within "#attached_documents" do |
| 149 | + attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document1.md"), make_visible: true) |
| 150 | + end |
| 151 | + all("input[type='submit'][value='Save Progress']").last.click |
| 152 | + visit edit_partners_profile_path |
| 153 | + find("button[data-bs-target='#attached_documents']").click |
| 154 | + within "#attached_documents" do |
| 155 | + attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document2.md"), make_visible: true) |
| 156 | + end |
| 157 | + all("input[type='submit'][value='Save Progress']").last.click |
| 158 | + |
| 159 | + # Remove the first document |
| 160 | + visit edit_partners_profile_path |
| 161 | + find("button[data-bs-target='#attached_documents']").click |
| 162 | + within "#attached_documents" do |
| 163 | + document_name = "document1.md" |
| 164 | + document_li = find("li.attached-document", text: document_name) |
| 165 | + document_li.find("a.btn-danger", text: "Remove").click |
| 166 | + expect(page).not_to have_selector("li.attached-document", text: document_name) |
| 167 | + end |
| 168 | + |
| 169 | + # Save Progress |
| 170 | + all("input[type='submit'][value='Save Progress']").last.click |
| 171 | + expect(page).to have_css(".alert-success", text: "Details were successfully updated.") |
| 172 | + |
| 173 | + # Verify only one document is listed |
| 174 | + visit edit_partners_profile_path |
| 175 | + find("button[data-bs-target='#attached_documents']").click |
| 176 | + within "#attached_documents" do |
| 177 | + expect(page).to have_link("document2.md") |
| 178 | + end |
| 179 | + end |
| 180 | + |
| 181 | + it "persists individual file upload when there are validation errors" do |
141 | 182 | # Open up Agency Information section and upload proof-of-status letter |
142 | 183 | find("button[data-bs-target='#agency_information']").click |
143 | 184 | within "#agency_information" do |
|
0 commit comments