Skip to content

Commit

Permalink
Merge pull request #230 from DFE-Digital/feature/403-users-return-to-…
Browse files Browse the repository at this point in the history
…the-same-place-in-the-task-list-after-answering-a-question

Users return to same place in task list after answering a question
  • Loading branch information
beeLorna committed Mar 16, 2021
2 parents 12a93a5 + eb32abe commit 9bc8235
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The format is based on [Keep a Changelog 1.0.0].
- fix checkbox questions where further information couldn't be saved for an option that included a special character
- further information for options that include special characters is now available to the specification
- incomplete specification documents include a warning within the document as well as the file name
- users return to the same place in the task list after answering a question

## [release-005] - 2021-1-19

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
@answer = result.object

if result.success?
redirect_to journey_path(@journey)
redirect_to journey_path(@journey, anchor: @step.id)
else
render "steps/#{@step.contentful_type}", locals: {layout: "steps/new_form_wrapper"}
end
Expand All @@ -33,7 +33,7 @@ def update
@answer = result.object

if result.success?
redirect_to journey_path(@journey)
redirect_to journey_path(@journey, anchor: @step.id)
else
render "steps/#{@step.contentful_type}", locals: {layout: "steps/edit_form_wrapper"}
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/journeys/_step_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul class="app-task-list__items">
<% steps.each do |step| %>
<% if step.question? %>
<li class="app-task-list__item">
<li class="app-task-list__item", id="<%= step.id %>">
<% if step.answer %>
<span class="app-task-list__task-name">
<%= link_to step.title, edit_journey_step_path(journey, step), class: "govuk-link", 'aria-describedby': step.id + "-status"%>
Expand Down
15 changes: 15 additions & 0 deletions spec/features/visitors/anyone_can_complete_a_journey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,19 @@
expect(page).to have_content(I18n.t("errors.specification_template_invalid.page_body"))
end
end

context "when a user answers a question" do
scenario "the user is returned to the same place in the task list " do
start_journey_from_category_and_go_to_question(category: "long-text-question.json")
journey = Journey.last

fill_in "answer[response]", with: "This is my long answer"

click_on(I18n.t("generic.button.next"))

answer = LongTextAnswer.last

expect(page).to have_current_path(journey_url(journey, anchor: answer.step.id), url: true)
end
end
end
13 changes: 13 additions & 0 deletions spec/features/visitors/anyone_can_edit_their_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,17 @@
expect(page).to have_content("You should NOT be able to see this question?")
end
end
context "when a user edits an answer" do
scenario "the user is returned to the same place in the task list " do
visit journey_path(answer.step.journey)

click_on(answer.step.title)

fill_in "answer[response]", with: "email@example.com"

click_on(I18n.t("generic.button.update"))

expect(page).to have_current_path(journey_url(answer.step.journey, anchor: answer.step.id), url: true)
end
end
end

0 comments on commit 9bc8235

Please sign in to comment.