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

Commit

Permalink
Merge pull request #268 from alphagov/TT-246-fix-welsh-feedback-route
Browse files Browse the repository at this point in the history
TT-246: Fix feedback page routing when switching to welsh
  • Loading branch information
tunylund authored Mar 31, 2017
2 parents 97d0c6b + 1545641 commit 94f2b7c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ class FeedbackController < ApplicationController
def index
@form = FeedbackForm.new({})
flash['feedback_referer'] = request.referer
flash['feedback_source'] = params['feedback-source']
feedback_source = params['feedback-source'].nil? ? flash['feedback_source'] : params['feedback-source']
if feedback_source.nil?
render
elsif FEEDBACK_SOURCE_MAPPER.is_feedback_source_valid(feedback_source)
flash['feedback_source'] = feedback_source
else
render 'errors/404', status: 400
end
end

def submit
Expand Down
5 changes: 5 additions & 0 deletions app/models/feedback_source_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(product_page_url)
'CERTIFIED_COMPANY_UNAVAILABLE_PAGE' => 'choose_a_certified_company',
'CONFIRM_YOUR_IDENTITY' => 'confirm_your_identity',
'CONFIRMATION_PAGE' => 'confirmation',
'ERROR_PAGE' => 'start',
'FAILED_REGISTRATION_PAGE' => 'failed_registration',
'FAILED_SIGN_IN_PAGE' => 'failed_sign_in',
'CYCLE_3_PAGE' => 'further_information',
Expand All @@ -34,6 +35,10 @@ def initialize(product_page_url)
}.freeze
end

def is_feedback_source_valid(feedback_source)
@page_to_source_mappings.has_key?(feedback_source)
end

def page_from_source(feedback_source, locale)
route_name = route_name_from(feedback_source)
if route_name =~ /https?:.*/
Expand Down
2 changes: 1 addition & 1 deletion app/views/feedback_sent/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p>
<%if @from_product_page%>
<%= link_to 'Return to the GOV.UK Verify product page', @link_back %>
<%= link_to t('hub.feedback_sent.product_page'), @link_back %>
<% elsif @session_valid %>
<%= link_to t('hub.feedback_sent.session_valid_link'), @link_back %>
<% else %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ cy:
session_valid_link: Dychwelyd i GOV.UK Verify
session_not_valid: Mae eich sesiwn wedi’i amseru allan.
session_not_valid_link: ddechrau eto
product_page: Dychwelyd i dudalen GOV.UK Verify
certified_company_unavailable:
title: Nid yw'r cwmni ardystiedig hwn ar gael
sorry: Mae'n ddrwg gennym, nid yw %{display_name} ar gael.
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ en:
session_valid_link: Return to GOV.UK Verify
session_not_valid: Your session has timed out.
session_not_valid_link: start again
product_page: Return to the GOV.UK Verify product page
certified_company_unavailable:
title: This certified company is unavailable
sorry: Sorry, %{display_name} is not available.
Expand Down
37 changes: 37 additions & 0 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 @@ -133,5 +155,20 @@
expect(page).to have_css 'html[lang=cy]'
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 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

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
6 changes: 6 additions & 0 deletions spec/features/user_visits_feedback_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
expect(page).to have_link 'Return to the GOV.UK Verify product page', href: 'https://govuk-verify.cloudapps.digital/'
end

it 'should display and something went wrong if the feedback source is not valid' do
visit '/feedback?feedback-source=something_not_valid'

expect(page).to have_content('This page can’t be found')
end

it 'should show errors for all input fields when missing input', js: true do
visit feedback_path
expect(page).to have_title(I18n.t('hub.feedback.title'))
Expand Down

0 comments on commit 94f2b7c

Please sign in to comment.