Skip to content

Commit 650a96b

Browse files
authored
Merge pull request #6022 from nhsuk/fix-redirect-after-resolve-duplicate-to-import
Fix: return to relevant import after resolving an issue
2 parents ab91473 + 2c5ec95 commit 650a96b

7 files changed

Lines changed: 67 additions & 24 deletions

app/components/app_import_review_issues_summary_component.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def review_link(record, type)
132132
full_name =
133133
record.is_a?(Patient) ? record.full_name : record.patient&.full_name
134134

135-
helpers.link_to(imports_issue_path(record, type:)) do
135+
helpers.link_to(
136+
imports_issue_path(record, type:, return_to: url_for(import))
137+
) do
136138
helpers.safe_join(
137139
["Review ", tag.span(full_name, class: "nhsuk-u-visually-hidden")]
138140
)

app/controllers/imports/issues_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ def show
1919

2020
def update
2121
if @form.save
22-
redirect_to imports_issues_path, flash: { success: "Record updated" }
22+
redirect_target = params[:return_to].presence || imports_issues_path
23+
24+
redirect_to redirect_target, flash: { success: "Record updated" }
2325
else
24-
render :show, status: :unprocessable_content and return
26+
render :show, status: :unprocessable_content
2527
end
2628
end
2729

app/views/imports/issues/show.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242

4343
<%= form_with(
4444
model: @form,
45-
url: imports_issue_path(@record, type: params[:type]),
45+
url: imports_issue_path(
46+
@record,
47+
type: params[:type],
48+
return_to: params[:return_to],
49+
),
4650
method: :patch,
4751
class: "nhsuk-u-full-width",
4852
) do |f| %>

spec/components/app_import_review_issues_summary_component_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
describe AppImportReviewIssuesSummaryComponent do
44
subject(:rendered) { render_inline(component) }
55

6+
let(:url_helpers) { Rails.application.routes.url_helpers }
7+
68
let(:component) { described_class.new(import:, records:, review_screen:) }
79

810
let(:team) { create(:team) }
@@ -165,9 +167,10 @@
165167
expect(rendered).to have_link(
166168
"Review",
167169
href:
168-
Rails.application.routes.url_helpers.imports_issue_path(
170+
url_helpers.imports_issue_path(
169171
patient,
170-
type: "patient"
172+
type: "patient",
173+
return_to: url_helpers.cohort_import_path(import)
171174
)
172175
)
173176
end
@@ -204,9 +207,10 @@
204207
expect(rendered).to have_link(
205208
"Review",
206209
href:
207-
Rails.application.routes.url_helpers.imports_issue_path(
210+
url_helpers.imports_issue_path(
208211
vaccination_record,
209-
type: "vaccination-record"
212+
type: "vaccination-record",
213+
return_to: url_helpers.cohort_import_path(import)
210214
)
211215
)
212216
end

spec/features/import_child_records_with_duplicates_spec.rb

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@
2727
when_i_choose_to_keep_the_duplicate_record
2828
and_i_confirm_my_selection
2929
then_i_should_see_a_success_message
30+
and_i_should_return_to_the_import_page
3031
and_the_first_duplicate_record_should_be_persisted
3132

32-
when_i_review_the_second_duplicate_record
33+
when_i_visit_the_import_issues_page
34+
and_i_review_the_second_duplicate_record
3335
then_i_should_see_the_second_duplicate_record
3436

3537
when_i_choose_to_keep_the_previously_uploaded_record
3638
and_i_confirm_my_selection
3739
then_i_should_see_a_success_message
3840
and_the_second_record_should_not_be_updated
3941

40-
when_i_review_the_third_duplicate_record
42+
when_i_visit_the_import_issues_page
43+
and_i_review_the_third_duplicate_record
4144
then_i_should_see_the_third_duplicate_record
4245

4346
when_i_choose_to_keep_both_records
@@ -75,17 +78,20 @@
7578
when_i_choose_to_keep_the_duplicate_record
7679
and_i_confirm_my_selection
7780
then_i_should_see_a_success_message
81+
and_i_should_return_to_the_import_page
7882
and_the_first_duplicate_record_should_be_persisted
7983

80-
when_i_review_the_second_duplicate_record
84+
when_i_visit_the_import_issues_page
85+
and_i_review_the_second_duplicate_record
8186
then_i_should_see_the_second_duplicate_record
8287

8388
when_i_choose_to_keep_the_previously_uploaded_record
8489
and_i_confirm_my_selection
8590
then_i_should_see_a_success_message
8691
and_the_second_record_should_not_be_updated
8792

88-
when_i_review_the_third_duplicate_record
93+
when_i_visit_the_import_issues_page
94+
and_i_review_the_third_duplicate_record
8995
then_i_should_see_the_third_duplicate_record
9096

9197
when_i_choose_to_keep_both_records
@@ -132,8 +138,10 @@
132138
and_i_choose_to_keep_the_duplicate_record
133139
and_i_confirm_my_selection
134140
then_search_vaccination_records_in_nhs_job_should_be_enqueued
141+
and_i_should_return_to_the_import_page
135142

136-
when_i_review_the_second_duplicate_record_jimmy
143+
when_i_visit_the_import_issues_page
144+
and_i_review_the_second_duplicate_record_jimmy
137145
and_i_choose_to_keep_the_previously_uploaded_record
138146
and_i_confirm_my_selection
139147
then_search_vaccination_records_in_nhs_job_should_be_enqueued_for_second_patient
@@ -272,6 +280,10 @@ def when_i_visit_the_import_page
272280
click_link "Import", match: :first
273281
end
274282

283+
def when_i_visit_the_import_issues_page
284+
visit imports_issues_path
285+
end
286+
275287
def and_i_start_adding_children_to_the_cohort
276288
click_button "Upload records"
277289
choose "Child records"
@@ -325,6 +337,7 @@ def when_i_choose_to_keep_both_records
325337
def when_i_choose_to_keep_the_previously_uploaded_record
326338
choose "Keep existing child"
327339
end
340+
328341
alias_method :and_i_choose_to_keep_the_previously_uploaded_record,
329342
:when_i_choose_to_keep_the_previously_uploaded_record
330343

@@ -341,6 +354,11 @@ def then_i_should_see_a_success_message
341354
expect(page).to have_content("Record updated")
342355
end
343356

357+
def and_i_should_return_to_the_import_page
358+
cohort_import = CohortImport.order(:created_at).last
359+
expect(page).to have_current_path(cohort_import_path(cohort_import))
360+
end
361+
344362
def when_i_review_the_first_duplicate_record
345363
find(".nhsuk-details__summary", text: "3 upload issues").click
346364
click_on "Review CLARKE, Jennifer"
@@ -363,11 +381,11 @@ def then_i_should_see_a_validation_error
363381
expect(page).to have_content("There is a problem")
364382
end
365383

366-
def when_i_review_the_second_duplicate_record
384+
def and_i_review_the_second_duplicate_record
367385
click_on "Review SMITH, James"
368386
end
369387

370-
def when_i_review_the_second_duplicate_record_jimmy
388+
def and_i_review_the_second_duplicate_record_jimmy
371389
click_on "Review SMITH, Jimmy"
372390
end
373391

@@ -410,7 +428,7 @@ def and_a_new_patient_record_should_be_created
410428
expect(session).to eq(@session)
411429
end
412430

413-
def when_i_review_the_third_duplicate_record
431+
def and_i_review_the_third_duplicate_record
414432
click_on "Review DOE, Mark"
415433
end
416434

spec/features/import_class_lists_with_duplicates_spec.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626
then_i_should_see_a_success_message
2727
and_the_first_record_should_be_updated
2828

29-
when_i_review_the_second_duplicate_record
29+
when_i_visit_the_import_issues_page
30+
and_i_review_the_second_duplicate_record
3031
then_i_should_see_the_second_duplicate_record
3132

3233
when_i_choose_to_keep_the_existing_record
3334
and_i_confirm_my_selection
3435
then_i_should_see_a_success_message
3536
and_the_second_record_should_not_be_updated
3637

37-
when_i_review_the_third_duplicate_record
38+
when_i_visit_the_import_issues_page
39+
and_i_review_the_third_duplicate_record
3840
then_i_should_see_the_third_duplicate_record
3941

4042
when_i_choose_to_keep_both_records
@@ -69,15 +71,17 @@
6971
then_i_should_see_a_success_message
7072
and_the_first_record_should_be_updated
7173

72-
when_i_review_the_second_duplicate_record
74+
when_i_visit_the_import_issues_page
75+
and_i_review_the_second_duplicate_record
7376
then_i_should_see_the_second_duplicate_record
7477

7578
when_i_choose_to_keep_the_existing_record
7679
and_i_confirm_my_selection
7780
then_i_should_see_a_success_message
7881
and_the_second_record_should_not_be_updated
7982

80-
when_i_review_the_third_duplicate_record
83+
when_i_visit_the_import_issues_page
84+
and_i_review_the_third_duplicate_record
8185
then_i_should_see_the_third_duplicate_record
8286

8387
when_i_choose_to_keep_both_records
@@ -191,6 +195,10 @@ def when_i_visit_a_school_page_for_the_hpv_programme
191195
click_on "Waterloo Road"
192196
end
193197

198+
def when_i_visit_the_import_issues_page
199+
visit imports_issues_path
200+
end
201+
194202
def and_i_start_adding_children_to_the_school
195203
click_on "Import class lists"
196204
end
@@ -262,7 +270,7 @@ def and_the_first_record_should_be_updated
262270
expect(@existing_patient.pending_changes).to eq({})
263271
end
264272

265-
def when_i_review_the_second_duplicate_record
273+
def and_i_review_the_second_duplicate_record
266274
click_on "Review JONES, Sarah"
267275
end
268276

@@ -277,7 +285,7 @@ def and_the_second_record_should_not_be_updated
277285
expect(@second_patient.pending_changes).to eq({})
278286
end
279287

280-
def when_i_review_the_third_duplicate_record
288+
def and_i_review_the_third_duplicate_record
281289
click_on "Review SALLES, Jenny"
282290
end
283291

spec/features/import_vaccination_records_with_duplicates_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
then_i_should_see_a_success_message
2424
and_the_duplicate_record_should_be_persisted
2525

26-
when_i_review_the_second_duplicate_record
26+
when_i_visit_the_import_issues_page
27+
and_i_review_the_second_duplicate_record
2728
then_i_should_see_the_second_duplicate_record
2829

2930
when_i_choose_to_keep_the_previously_uploaded_record
@@ -137,6 +138,10 @@ def and_i_am_signed_in
137138
visit dashboard_path
138139
end
139140

141+
def when_i_visit_the_import_issues_page
142+
visit imports_issues_path
143+
end
144+
140145
def and_i_click_on_the_upload_link
141146
click_on "Upload records"
142147
choose "Vaccination records"
@@ -212,7 +217,7 @@ def then_i_should_see_a_validation_error
212217
expect(page).to have_content("There is a problem")
213218
end
214219

215-
def when_i_review_the_second_duplicate_record
220+
def and_i_review_the_second_duplicate_record
216221
click_on "Review HAMILTON, Joanna"
217222
end
218223

0 commit comments

Comments
 (0)