Skip to content

Commit

Permalink
Combine step_nav and related_step_navs list to search both lists
Browse files Browse the repository at this point in the history
This is needed so that when the active step by step is searched for
it searches related_to_step_navs and step_navs list to make sure the
active step by step is shown correctly
  • Loading branch information
Dilwoar Hussain committed Sep 25, 2018
1 parent 90cf839 commit 39d42c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def active_step_by_step?
end

def active_step_by_step
@active_step_navs ||= step_navs.select { |step_nav| step_nav.content_id == active_step_nav_content_id }
step_navs_list = step_navs_combined_list
@active_step_navs ||= step_navs_list.select { |step_nav| step_nav.content_id == active_step_nav_content_id }
@active_step_navs.first
end

Expand All @@ -94,6 +95,13 @@ def steps
@steps ||= step_nav[:steps]
end

def step_navs_combined_list
step_nav_list = []
step_nav_list += step_navs if step_navs.any?
step_nav_list += related_to_step_navs if related_to_step_navs.any?
step_nav_list
end

def parsed_step_navs
content_item.dig("links", "part_of_step_navs").to_a
end
Expand Down
36 changes: 36 additions & 0 deletions spec/lib/presenters/page_with_step_by_step_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,42 @@
expect(step_nav_helper.also_part_of_step_nav.first[:tracking_id]).to eq('aaaa-bbbb')
expect(step_nav_helper.show_also_part_of_step_nav?).to be true
end

it "shows related to step nav when a step by step is active" do
step_nav = {
"content_id" => "cccc-dddd",
"title" => "Learn to spacewalk: small step by giant leap",
"base_path" => "/learn-to-spacewalk"
}
content_item = {
"title" => "Book a session in the vomit comet",
"document_type" => "transaction",
"links" => {
"related_to_step_navs" => [step_nav],
}
}
step_nav_helper = described_class.new(content_item, "/driving-lessons-learning-to-drive", "step-by-step-nav" => "cccc-dddd")
expect(step_nav_helper.active_step_by_step?).to eq(true)
expect(step_nav_helper.also_part_of_step_nav.count).to eq(0)
end

it "does not shows related to step nav when a step by step is not active" do
step_nav = {
"content_id" => "cccc-dddd",
"title" => "Learn to spacewalk: small step by giant leap",
"base_path" => "/learn-to-spacewalk"
}
content_item = {
"title" => "Book a session in the vomit comet",
"document_type" => "transaction",
"links" => {
"related_to_step_navs" => [step_nav],
}
}
step_nav_helper = described_class.new(content_item, "/driving-lessons-learning-to-drive")
expect(step_nav_helper.active_step_by_step?).to eq(false)
expect(step_nav_helper.show_also_part_of_step_nav?).to be false
end
end

def payload_for(schema, content_item)
Expand Down

0 comments on commit 39d42c0

Please sign in to comment.