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
16 changes: 15 additions & 1 deletion app/services/welsh_csv_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def add_page_content(csv)
add_question_content(csv, page)
add_selection_options(csv, page) if page.answer_type == "selection"
add_none_of_above_question(csv, page) if has_none_of_the_above?(page)
add_routing_conditions(csv, page)

if FeatureService.new(group: form.group).enabled?(:multiple_branches)
add_exit_pages(csv, page)
else
add_routing_conditions(csv, page)
end
end
end

Expand Down Expand Up @@ -86,6 +91,15 @@ def add_routing_conditions(csv, page)
end
end

def add_exit_pages(csv, page)
exit_page_positions = ExitPage.positions_for_page(page)
page.exit_pages.each do |exit_page|
exit_page_position = exit_page_positions[exit_page.id]
csv << ["#{question_name(page)} - exit page #{exit_page_position} heading", exit_page.heading, exit_page.heading_cy]
csv << ["#{question_name(page)} - exit page #{exit_page_position} content", exit_page.markdown, exit_page.markdown_cy]
end
end

def add_page_heading(csv, page)
if page.page_heading.present?
csv << ["#{question_name(page)} - page heading", page.page_heading, page.page_heading_cy]
Expand Down
108 changes: 97 additions & 11 deletions spec/services/welsh_csv_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "rails_helper"

RSpec.describe "WelshCsvService" do
RSpec.describe "WelshCsvService", feature_multiple_branches: false do
describe "#as_csv" do
let(:form) { build :form }

Expand Down Expand Up @@ -208,17 +208,103 @@
end
end

context "when the page has an exit condition" do
let(:form) { build :form, :with_pages, pages: [page] }
let(:page) { create :page, position: 1, routing_conditions: [condition] }
let(:condition) { create :condition, :with_exit_page, exit_page_heading: "Exit page heading", exit_page_markdown: "Exit page markdown", exit_page_heading_cy: "Welsh exit page heading", exit_page_markdown_cy: "Welsh exit page markdown" }
context "when the page has an exit page" do
context "when the multiple branches feature is enabled", :feature_multiple_branches do
let(:form) do
create(
:form,
:with_pages,
pages: [
build(
:page,
position: 1,
exit_pages: [
build(
:exit_page,
heading: "Exit page 1 for question 1 heading",
markdown: "Exit page 1 for question 1 markdown.",
heading_cy: "Welsh exit page 1 for question 1 heading",
markdown_cy: "Welsh exit page 1 for question 1 markdown.",
),
],
),
build(
:page,
position: 2,
exit_pages: [
build(
:exit_page,
heading: "Exit page 1 for question 2 heading",
markdown: "Exit page 1 for question 2 markdown.",
heading_cy: "Welsh exit page 1 for question 2 heading",
markdown_cy: "Welsh exit page 1 for question 2 markdown.",
),
build(
:exit_page,
heading: "Exit page 2 for question 2 heading",
markdown: "Exit page 2 for question 2 markdown.",
heading_cy: "Welsh exit page 2 for question 2 heading",
markdown_cy: "Welsh exit page 2 for question 2 markdown.",
),
],
),
],
)
end

it "contains the exit page heading" do
expect(csv_rows(form)).to include([
"Question 1 - exit page heading",
"Exit page heading",
"Welsh exit page heading",
])
it "contains the exit page headings" do
expect(csv_rows(form)).to include(
[
"Question 1 - exit page 1 heading",
"Exit page 1 for question 1 heading",
"Welsh exit page 1 for question 1 heading",
],
[
"Question 2 - exit page 1 heading",
"Exit page 1 for question 2 heading",
"Welsh exit page 1 for question 2 heading",
],
[
"Question 2 - exit page 2 heading",
"Exit page 2 for question 2 heading",
"Welsh exit page 2 for question 2 heading",
],
)
end

it "contains the exit page markdown" do
expect(csv_rows(form)).to include(
[
"Question 1 - exit page 1 content",
"Exit page 1 for question 1 markdown.",
"Welsh exit page 1 for question 1 markdown.",
],
[
"Question 2 - exit page 1 content",
"Exit page 1 for question 2 markdown.",
"Welsh exit page 1 for question 2 markdown.",
],
[
"Question 2 - exit page 2 content",
"Exit page 2 for question 2 markdown.",
"Welsh exit page 2 for question 2 markdown.",
],
)
end
end

context "when the multiple branches feature is not enabled", feature_multiple_branches: false do
let(:form) { build :form, :with_pages, pages: [page] }
let(:page) { create :page, position: 1, routing_conditions: [condition] }
let(:condition) { create :condition, :with_exit_page, exit_page_heading: "Exit page heading", exit_page_markdown: "Exit page markdown", exit_page_heading_cy: "Welsh exit page heading", exit_page_markdown_cy: "Welsh exit page markdown" }

it "contains the exit page heading" do
expect(csv_rows(form)).to include([
"Question 1 - exit page heading",
"Exit page heading",
"Welsh exit page heading",
])
end
end
end

Expand Down