Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
TT-246: Use flash to preserve the feedback-source
Browse files Browse the repository at this point in the history
  • Loading branch information
oswaldquek committed Mar 29, 2017
1 parent a5ecdfe commit 93bcdce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
3 changes: 2 additions & 1 deletion app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class FeedbackController < ApplicationController
def index
@form = FeedbackForm.new({})
flash['feedback_referer'] = request.referer
feedback_source = params['feedback-source']
feedback_source = params['feedback-source'].nil? ? flash['feedback_source'] : params['feedback-source']
flash['feedback_source'] = feedback_source
if feedback_source.nil?
render
elsif FEEDBACK_SOURCE_MAPPER.is_feedback_source_valid(feedback_source)
Expand Down
4 changes: 0 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def hide_from_search_engine?
!content_for(:show_to_search_engine)
end

def feedback_source_query_param
Rack::Utils.parse_nested_query(request.query_string)['feedback-source']
end

def feedback_source
content_for(:feedback_source) || ""
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_available_languages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<% if params[:locale] == 'en' %>
<span>English</span>
<% else %>
<%= link_to 'English', url_for(locale: 'en', :'feedback-source' => feedback_source_query_param), lang: 'en', hreflang: 'en' %>
<%= link_to 'English', url_for(locale: 'en'), lang: 'en', hreflang: 'en' %>
<% end %>
</li>
<li class="translation last">
<% if params[:locale] == 'cy' %>
<span>Cymraeg</span>
<% else %>
<%= link_to 'Cymraeg', url_for(locale: 'cy', :'feedback-source' => feedback_source_query_param), lang: 'cy', hreflang: 'cy' %>
<%= link_to 'Cymraeg', url_for(locale: 'cy'), lang: 'cy', hreflang: 'cy' %>
<% end %>
</li>
</ul>
Expand Down
45 changes: 30 additions & 15 deletions spec/features/user_submits_feedback_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@
end
end

it 'should be able to direct user back to the Verify product page if email could not be sent on first attempt' do
visit '/feedback?feedback-source=PRODUCT_PAGE'

fill_in 'feedback_form_what', with: 'Verify my identity'
fill_in 'feedback_form_details', with: 'Some details'
choose 'feedback_form_reply_false', allow_label_click: true

allow_any_instance_of(FeedbackService).to receive(:submit!).and_return(false)

click_button I18n.t('hub.feedback.send_message')

expect(page).to have_current_path(feedback_path)
expect(page).to have_content 'Verify my identity'
expect(page).to have_content 'Some details'

allow_any_instance_of(FeedbackService).to receive(:submit!).and_return(true)

click_button I18n.t('hub.feedback.send_message')
expect(page).to have_title(I18n.t('hub.feedback_sent.title'))
expect(page).to have_link 'Return to the GOV.UK Verify product page', href: 'https://govuk-verify.cloudapps.digital/'
end

context 'user session valid' do
it 'should show user link back to start page' do
set_session_and_session_cookies!
Expand Down Expand Up @@ -134,26 +156,19 @@
expect(page).to have_link I18n.t('hub.feedback_sent.session_valid_link', locale: :cy), href: select_documents_cy_path
end

it 'should be able to direct user back to the Verify product page if email could not be sent on first attempt' do
visit '/feedback?feedback-source=PRODUCT_PAGE'
it 'should be able to direct user back to the relevant page if user switches to Welsh on the feedback page' do
set_session_and_session_cookies!
visit '/feedback?feedback-source=START_PAGE'

click_link 'Cymraeg'
expect(page).to have_current_path('/adborth')

fill_in 'feedback_form_what', with: 'Verify my identity'
fill_in 'feedback_form_details', with: 'Some details'
choose 'feedback_form_reply_false', allow_label_click: true

allow_any_instance_of(FeedbackService).to receive(:submit!).and_return(false)

click_button I18n.t('hub.feedback.send_message')

expect(page).to have_current_path(feedback_path)
expect(page).to have_content 'Verify my identity'
expect(page).to have_content 'Some details'

allow_any_instance_of(FeedbackService).to receive(:submit!).and_return(true)

click_button I18n.t('hub.feedback.send_message')
expect(page).to have_title(I18n.t('hub.feedback_sent.title'))
expect(page).to have_link 'Return to the GOV.UK Verify product page', href: 'https://govuk-verify.cloudapps.digital/'
click_button I18n.t('hub.feedback.send_message', locale: :cy)
expect(page).to have_link I18n.t('hub.feedback_sent.session_valid_link', locale: :cy), href: '/dechrau'
end
end
end

0 comments on commit 93bcdce

Please sign in to comment.