Skip to content

Commit 2b0579a

Browse files
committed
Add branching_enabled to summary_card_data_presenter
This commit changes the way the summary_card_data_presenter checks if the branching feature flag is enabled. The flag can now be set on a group. The value is passed down from the controller into the views. The tests are updated where needed.
1 parent 36811ea commit 2b0579a

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

app/controllers/pages/routes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Pages::RoutesController < PagesController
22
def show
33
back_link_url = form_pages_path(current_form.id)
4-
render locals: { current_form:, page:, pages: FormRepository.pages(current_form), back_link_url: }
4+
render locals: { current_form:, page:, pages: FormRepository.pages(current_form), back_link_url:, branching_enabled: }
55
end
66

77
def delete

app/presenters/route_summary_card_data_presenter.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ class RouteSummaryCardDataPresenter
33
include ActionView::Helpers::UrlHelper
44
include GovukRailsCompatibleLinkHelper
55

6-
attr_reader :form, :page, :pages
6+
attr_reader :form, :page, :pages, :branching_enabled
77

88
class << self
99
def call(**args)
1010
new(**args)
1111
end
1212
end
1313

14-
def initialize(form:, page:, pages:)
14+
def initialize(form:, page:, pages:, branching_enabled:)
1515
@page = page
1616
@pages = pages
1717
@form = form
18+
@branching_enabled = branching_enabled
1819
end
1920

2021
def summary_card_data
@@ -64,7 +65,7 @@ def conditional_route_card(routing_condition, index)
6465
def default_route_card(index)
6566
continue_to_name = page.has_next_page? ? page_name(page.next_page) : end_page_name
6667

67-
actions = if FeatureService.enabled?(:branch_routing) && all_routes.find(&:secondary_skip?).present?
68+
actions = if branching_enabled && all_routes.find(&:secondary_skip?).present?
6869
[
6970
edit_secondary_skip_link,
7071
delete_secondary_skip_link,
@@ -101,7 +102,7 @@ def secondary_skip_rows
101102
secondary_skip = all_routes.find(&:secondary_skip?)
102103

103104
if secondary_skip.blank?
104-
if FeatureService.enabled?(:branch_routing)
105+
if branching_enabled
105106
return [
106107
{
107108
key: { text: I18n.t("page_route_card.then") },

app/views/pages/routes/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
end;
1717
end %>
1818

19-
<% RouteSummaryCardDataPresenter.call(form: current_form, page:, pages:).summary_card_data.each do |card| %>
19+
<% RouteSummaryCardDataPresenter.call(form: current_form, page:, pages:, branching_enabled: ).summary_card_data.each do |card| %>
2020
<%= govuk_summary_list(**card) %>
2121
<% end %>
2222

spec/presenters/route_summary_card_data_presenter_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe RouteSummaryCardDataPresenter do
44
include Capybara::RSpecMatchers
55

6-
subject(:service) { described_class.new(form:, page: current_page, pages:) }
6+
subject(:service) { described_class.new(form:, page: current_page, pages:, branching_enabled:) }
77

88
let(:form) { build :form, id: 99, pages: }
99

@@ -25,9 +25,11 @@
2525

2626
let(:next_page_routing_conditions) { [] }
2727

28+
let(:branching_enabled) { false }
29+
2830
describe ".call" do
2931
it "instantiates and returns a new instance" do
30-
service = described_class.call(form:, page: current_page, pages:)
32+
service = described_class.call(form:, page: current_page, pages:, branching_enabled:)
3133
expect(service).to be_an_instance_of(described_class)
3234
end
3335
end
@@ -50,7 +52,9 @@
5052
expect(result[1][:rows][0][:value][:text]).to eq("2. Next Question")
5153
end
5254

53-
context "with branch_routing enabled", :feature_branch_routing do
55+
context "with branch_routing enabled" do
56+
let(:branching_enabled) { true }
57+
5458
it "has the link to create a secondary skip" do
5559
result = service.summary_card_data
5660
expect(result[1][:rows][1][:value][:text]).to have_link("Set one or more questions to skip later in the form (optional)", href: "/forms/99/pages/1/routes/any-other-answer/questions-to-skip/new")
@@ -106,6 +110,8 @@
106110
end
107111

108112
context "with branch_routing enabled", :feature_branch_routing do
113+
let(:branching_enabled) { true }
114+
109115
it "shows the edit secondary skip link" do
110116
result = service.summary_card_data
111117
expect(result[1][:card][:actions].first).to have_link("Edit", href: "/forms/99/pages/1/routes/any-other-answer/questions-to-skip")

spec/views/pages/routes/show.html.erb_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
before do
2121
allow(RouteSummaryCardDataPresenter).to receive(:call).and_return(route_summary_card_data_service)
22-
render template: "pages/routes/show", locals: { current_form: form, page:, pages: form.pages, back_link_url: "/back" }
22+
render template: "pages/routes/show", locals: { current_form: form, page:, pages: form.pages, back_link_url: "/back", branching_enabled: true }
2323
end
2424

2525
it "has the correct title" do

0 commit comments

Comments
 (0)