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
4 changes: 2 additions & 2 deletions app/lib/flow/journey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def populate_file_suffixes

private

def step_is_completed?(question_page_step)
def step_is_completed?(step)
# A step has been completed if it is a question that has been answered.
question_page_step.question.answered?
step.question.answered?
end

def generate_completed_steps
Expand Down
6 changes: 3 additions & 3 deletions spec/components/check_your_answers_component/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
let(:optional_question) { build :text, question_text: "Optional question", is_optional: true, text: "" }
let(:steps) do
[
build(:step, question: question, form_document_step: build(:v2_question_page_step, :with_text_settings)),
build(:step, question: optional_question, form_document_step: build(:v2_question_page_step, :with_text_settings)),
build(:step, question: question, form_document_step: build(:v2_question_step, :with_text_settings)),
build(:step, question: optional_question, form_document_step: build(:v2_question_step, :with_text_settings)),
]
end
let(:mode) { Mode.new("form") }
Expand Down Expand Up @@ -48,7 +48,7 @@
end

context "when a step is repeatable and has an answer" do
let(:steps) { [build(:repeatable_step, question: question, form_document_step: build(:v2_question_page_step, :with_text_settings))] }
let(:steps) { [build(:repeatable_step, question: question, form_document_step: build(:v2_question_step, :with_text_settings))] }

it "uses the add another answer path for the change link" do
expect(page).to have_link("Change", href: change_add_another_answer_path(mode: mode, form_id: form.id, form_slug: form.form_slug, step_slug: steps[0].id))
Expand Down
16 changes: 8 additions & 8 deletions spec/components/question/date_component/view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::DateComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, :with_date_settings, input_type: }
let(:form_document_step) { build :v2_question_step, :with_date_settings, input_type: }
let(:input_type) { "other_date" }
let(:question_attributes) { { date_day: nil, date_month: nil, date_year: nil } }
let(:question) do
Expand Down Expand Up @@ -52,7 +52,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, :with_date_settings, input_type: }
let(:form_document_step) { build :v2_question_step, :with_hints, :with_date_settings, input_type: }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -68,7 +68,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, :with_date_settings, input_type:, question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, :with_date_settings, input_type:, question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -78,7 +78,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, :with_date_settings }
let(:form_document_step) { build :v2_question_step, :with_guidance, :with_date_settings }

it "renders the question text as a legend" do
expect(page.find("legend.govuk-fieldset__legend--m")).to have_text(form_document_step.question_text)
Expand Down Expand Up @@ -116,7 +116,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, :with_date_settings, input_type: }
let(:form_document_step) { build :v2_question_step, :with_hints, :with_date_settings, input_type: }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -132,7 +132,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, :with_date_settings, input_type:, question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, :with_date_settings, input_type:, question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -142,7 +142,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, :with_date_settings }
let(:form_document_step) { build :v2_question_step, :with_guidance, :with_date_settings }

it "renders the question text as a legend" do
expect(page.find("legend.govuk-fieldset__legend--m")).to have_text(form_document_step.question_text)
Expand Down Expand Up @@ -170,7 +170,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "date", answer_settings: }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "date", answer_settings: }

it "renders the question text as a legend" do
expect(page.find("legend.govuk-fieldset__legend--m")).to have_text(form_document_step.question_text)
Expand Down
8 changes: 4 additions & 4 deletions spec/components/question/email_component/view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::EmailComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "email" }
let(:form_document_step) { build :v2_question_step, answer_type: "email" }
let(:email) { nil }
let(:question) do
Question::Email.new({ email: email }, {
Expand Down Expand Up @@ -44,7 +44,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, answer_type: "email" }
let(:form_document_step) { build :v2_question_step, :with_hints, answer_type: "email" }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -60,7 +60,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, answer_type: "email", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, answer_type: "email", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -70,7 +70,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "email" }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "email" }

it "renders the question text as a label" do
expect(page.find("label.govuk-label--m")).to have_text(form_document_step.question_text)
Expand Down
8 changes: 4 additions & 4 deletions spec/components/question/file_component/view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::FileComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "file" }
let(:form_document_step) { build :v2_question_step, answer_type: "file" }
let(:question) do
build(:file,
:with_uploaded_file,
Expand Down Expand Up @@ -31,7 +31,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, answer_type: "file" }
let(:form_document_step) { build :v2_question_step, :with_hints, answer_type: "file" }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -47,7 +47,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, answer_type: "file", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, answer_type: "file", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -57,7 +57,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "file" }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "file" }

it "renders the question text as a label" do
expect(page.find("label.govuk-label--m")).to have_text(form_document_step.question_text)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::FileRemoveComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "file" }
let(:form_document_step) { build :v2_question_step, answer_type: "file" }
let(:is_optional) { false }
let(:question_text) { "Upload a file" }
let(:page_heading) { nil }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::FileReviewComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "file" }
let(:form_document_step) { build :v2_question_step, answer_type: "file" }
let(:is_optional) { false }
let(:question_text) { "Upload a file" }
let(:page_heading) { nil }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::NationalInsuranceNumberComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "national_insurance_number" }
let(:form_document_step) { build :v2_question_step, answer_type: "national_insurance_number" }
let(:national_insurance_number) { nil }
let(:question) do
Question::NationalInsuranceNumber.new({ national_insurance_number: national_insurance_number }, {
Expand Down Expand Up @@ -44,7 +44,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, answer_type: "national_insurance_number" }
let(:form_document_step) { build :v2_question_step, :with_hints, answer_type: "national_insurance_number" }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -60,7 +60,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, answer_type: "national_insurance_number", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, answer_type: "national_insurance_number", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -70,7 +70,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "national_insurance_number" }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "national_insurance_number" }

it "renders the question text as a label" do
expect(page.find("label.govuk-label--m")).to have_text(form_document_step.question_text)
Expand Down
8 changes: 4 additions & 4 deletions spec/components/question/number_component/view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::NumberComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "number" }
let(:form_document_step) { build :v2_question_step, answer_type: "number" }
let(:number) { nil }
let(:question) do
Question::Number.new({ number: number }, {
Expand Down Expand Up @@ -40,7 +40,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, answer_type: "number" }
let(:form_document_step) { build :v2_question_step, :with_hints, answer_type: "number" }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -56,7 +56,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, answer_type: "number", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, answer_type: "number", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -66,7 +66,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "number" }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "number" }

it "renders the question text as a label" do
expect(page.find("label.govuk-label--m")).to have_text(form_document_step.question_text)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::OrganisationNameComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "organisation_name" }
let(:form_document_step) { build :v2_question_step, answer_type: "organisation_name" }
let(:answer_text) { nil }
let(:question) do
Question::OrganisationName.new({ text: answer_text }, {
Expand Down Expand Up @@ -44,7 +44,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, answer_type: "organisation_name" }
let(:form_document_step) { build :v2_question_step, :with_hints, answer_type: "organisation_name" }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -60,7 +60,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, answer_type: "organisation_name", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, answer_type: "organisation_name", question_text: "What is your name? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -70,7 +70,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "organisation_name" }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "organisation_name" }

it "renders the question text as a label" do
expect(page.find("label.govuk-label--m")).to have_text(form_document_step.question_text)
Expand Down
8 changes: 4 additions & 4 deletions spec/components/question/phone_number_component/view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Question::PhoneNumberComponent::View, type: :component do
let(:form_document_step) { build :v2_question_page_step, answer_type: "phone_number" }
let(:form_document_step) { build :v2_question_step, answer_type: "phone_number" }
let(:phone_number) { nil }
let(:question) do
Question::PhoneNumber.new({ phone_number: phone_number }, {
Expand Down Expand Up @@ -48,7 +48,7 @@
end

context "when the question has hint text" do
let(:form_document_step) { build :v2_question_page_step, :with_hints, answer_type: "phone_number" }
let(:form_document_step) { build :v2_question_step, :with_hints, answer_type: "phone_number" }

it "outputs the hint text" do
expect(page.find(".govuk-hint")).to have_text(question.hint_text)
Expand All @@ -64,7 +64,7 @@
end

context "with unsafe question text" do
let(:form_document_step) { build :v2_question_page_step, answer_type: "phone_number", question_text: "What is your phone number? <script>alert(\"Hi\")</script>" }
let(:form_document_step) { build :v2_question_step, answer_type: "phone_number", question_text: "What is your phone number? <script>alert(\"Hi\")</script>" }
let(:mode) { Mode.new("preview-draft") }

it "returns the escaped title with the optional suffix" do
Expand All @@ -74,7 +74,7 @@
end

context "when question has guidance" do
let(:form_document_step) { build :v2_question_page_step, :with_guidance, answer_type: "phone_number" }
let(:form_document_step) { build :v2_question_step, :with_guidance, answer_type: "phone_number" }

it "renders the question text as a label" do
expect(page.find("label.govuk-label--m")).to have_text(form_document_step.question_text)
Expand Down
Loading
Loading