Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/controllers/routes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class RoutesController < FormsController
before_action :check_multiple_branches_enabled
before_action :check_user_has_permission

def show
authorize current_form, :can_view_form?
end

private

def check_user_has_permission
authorize current_form, :can_edit_form?
end

def check_multiple_branches_enabled
return if current_form.group.multiple_branches_enabled

render "errors/not_found", status: :not_found, formats: :html
end
end
6 changes: 5 additions & 1 deletion app/views/pages/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
<% end %>
<div class="govuk-button-group">
<%= govuk_button_link_to t("pages.index.add_question"), start_new_question_path(form_id: current_form.id), class:"govuk-!-margin-bottom-3 govuk-!-margin-top-3" %>
<%= govuk_button_link_to t("pages.index.add_a_question_route"), routing_page_path(current_form.id), secondary: true, class:"govuk-!-margin-bottom-3 govuk-!-margin-top-3" %>
<% if current_form.group&.multiple_branches_enabled %>
<%= govuk_button_link_to t("pages.index.routes"), routes_path(current_form.id), secondary: true, class:"govuk-!-margin-bottom-3 govuk-!-margin-top-3" %>
<% else %>
<%= govuk_button_link_to t("pages.index.add_a_question_route"), routing_page_path(current_form.id), secondary: true, class:"govuk-!-margin-bottom-3 govuk-!-margin-top-3" %>
<% end %>

<%= render PreviewLinkComponent::View.new(@pages, link_to_runner(Settings.forms_runner.url, current_form.id, current_form.form_slug)) %>
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/views/routes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% set_page_title(t("page_titles.routes")) %>
<% content_for :back_link, govuk_back_link_to(form_pages_path(@current_form.id), t("back_link.form_view")) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @current_form.name %></span>
<span class="govuk-visually-hidden"> - </span>
<%= t("page_titles.routes") %>
</h1>
</div>
</div>
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ en:
payment_link: Add a link to a payment page on GOV.UK Pay
privacy_policy: Provide a link to privacy information for this form
question_text: What’s your question?
routes: Edit question routes
routes_show: Question %{question_number}’s routes
routing_page: Add a route from a question
routing_page_caption: Question %{question_number}’s routes
Expand Down Expand Up @@ -1580,6 +1581,7 @@ en:
change_order: Change your question order
mark_complete:
legend: Have you finished editing your questions?
routes: Edit question routes
title: Add and edit your questions
optional: "%{question_text} (optional)"
question: Question
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
post "/batch-submissions" => "forms/batch_submissions#create", as: :batch_submissions_create
get "/metrics" => "forms/metrics#metrics_csv", as: :metrics_csv

resource :routes, only: %i[show]

scope "/pages-by-external-id/:page_external_id" do
get "/edit-question" => "forms/redirect_from_forms_runner#edit_question", as: :edit_question_by_external_id
get "/routes" => "forms/redirect_from_forms_runner#routes", as: :show_routes_by_external_id
Expand Down
42 changes: 42 additions & 0 deletions spec/requests/routes_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "rails_helper"

RSpec.describe RoutesController, type: :request do
let(:form) { create(:form, :with_group, group:) }
let(:membership) { create :membership, group:, user: standard_user }
let(:group) { create(:group, multiple_branches_enabled: true) }

before do
membership
login_as_standard_user
end

describe "#show" do
it "returns a 200 status code" do
get routes_path(form.id)
expect(response).to have_http_status(:ok)
end

it "renders the routes#show template" do
get routes_path(form.id)
expect(response).to render_template("routes/show")
end

context "when the user is not in the form's group" do
let(:membership) { nil }

it "returns a forbidden status code" do
get routes_path(form.id)
expect(response).to have_http_status :forbidden
end
end

context "when the multiple_branches feature is not enabled" do
let(:group) { create(:group, multiple_branches_enabled: false) }

it "returns a 404" do
get routes_path(form.id)
expect(response).to have_http_status(:not_found)
end
end
end
end
40 changes: 17 additions & 23 deletions spec/views/pages/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,24 @@
let(:mark_complete_input) { Forms::MarkPagesSectionCompleteInput.new(form:).assign_form_values }

before do
# mock the path helper
without_partial_double_verification do
allow(view).to receive_messages(
form_path: "/forms/1",
type_of_answer_new_path: "/forms/1/pages/new/type-of-answer",
edit_question_path: "/forms/1/pages/2/edit/question",
form_pages_path: "/forms/1/pages",
routing_page_path: "/forms/1/new-condition",
current_form: form,
)
end
assign(:pages, pages)
assign(:mark_complete_input, mark_complete_input)
render template: "pages/index"
render template: "pages/index", locals: { current_form: form }
end

it "has the correct title" do
expect(view.content_for(:title)).to eq I18n.t("pages.index.title")
end

describe "when there are no pages to display" do
it "allows the user to add a page" do
expect(rendered).to have_link(I18n.t("pages.index.add_question"), href: start_new_question_path(form.id))
end
it "allows the user to add a page" do
expect(rendered).to have_link(I18n.t("pages.index.add_question"), href: start_new_question_path(form.id))
end

it "does not contain a link to add page routing" do
expect(rendered).not_to have_link("Add a question route", href: routing_page_path(form.id))
end
it "has a link to branch routing page" do
expect(rendered).to have_link("Add a question route", href: routing_page_path(form.id))
end

describe "when there are no pages to display" do
it "does not contain a list of pages" do
expect(rendered).not_to have_text I18n.t("forms.form_overview.your_questions")
expect(rendered).not_to have_css ".govuk-summary-list"
Expand All @@ -44,10 +33,6 @@
describe "when there are more than one page to display" do
let(:pages) { [(build :page, id: 1, position: 1, form_id: 1), (build :page, id: 2, position: 2, form_id: 1), (build :page, id: 3, position: 3, form_id: 1)] }

it "allows the user to add a page" do
expect(rendered).to have_link(I18n.t("pages.index.add_question"), href: start_new_question_path(form.id))
end

it "does contain a summary list entry each page" do
expect(rendered).to have_text I18n.t("forms.form_overview.your_questions")
expect(rendered).to have_css ".govuk-summary-list__row", count: 3
Expand All @@ -57,4 +42,13 @@
expect(rendered).to have_link("Change your question order", href: change_order_new_path(form.id))
end
end

describe "when the group has multiple branches enabled" do
let(:group) { create(:group, multiple_branches_enabled: true) }
let(:form) { create(:form, :with_group, group:) }

it "has a link to add a page routing" do
expect(rendered).to have_link("Edit question routes", href: routes_path(form.id))
end
end
end
26 changes: 26 additions & 0 deletions spec/views/routes/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "rails_helper"

describe "routes/show.html.erb" do
let(:form) { build_stubbed :form }

def render_page
assign(:current_form, form)
render template: "routes/show", locals: { current_form: form }
end

it "has the correct title" do
render_page
expect(view.content_for(:title)).to have_content("Edit question routes")
end

it "has the correct back link" do
render_page
expect(view.content_for(:back_link)).to have_link("Back to your form", href: form_pages_path(form.id))
end

it "has the correct heading and caption" do
render_page
expect(rendered).to have_selector("h1", text: form.name)
expect(rendered).to have_selector("h1", text: "Edit question routes")
end
end