Browse Source

Add tests

pull/2836/head
Manny Dinssa 2 months ago
parent
commit
13c751bd04
  1. 21
      spec/helpers/details_table_helper_spec.rb
  2. 22
      spec/helpers/merge_requests_helper_spec.rb
  3. 25
      spec/models/form/question_spec.rb

21
spec/helpers/details_table_helper_spec.rb

@ -3,6 +3,7 @@ require "rails_helper"
RSpec.describe DetailsTableHelper do
describe "details html" do
let(:details) { details_html(attribute) }
let(:current_user) { FactoryBot.build(:user) }
context "when given a simple attribute" do
let(:attribute) { { name: "name", value: "Dummy org", editable: true } }
@ -12,7 +13,7 @@ RSpec.describe DetailsTableHelper do
end
end
context "when given a bullet point list of attibutes" do
context "when given a bullet point list of attributes" do
let(:list) { %w[Camden Westminster Bristol] }
let(:attribute) do
{
@ -28,7 +29,7 @@ RSpec.describe DetailsTableHelper do
end
end
context "when given a bullet point list with one attibute" do
context "when given a bullet point list with one attribute" do
let(:list) { %w[Camden] }
let(:attribute) do
{
@ -43,5 +44,21 @@ RSpec.describe DetailsTableHelper do
expect(details).to eq("<p class=\"govuk-body\">Camden</p>")
end
end
context "when given an attribute value is empty" do
let(:attribute) { { value: "" } }
it "displays the default message" do
expect(details_html(attribute)).to include("No answer provided")
end
end
context "when given an attribute value is not empty" do
let(:attribute) { { value: "Dummy text" } }
it "displays the default message" do
expect(details_html(attribute)).to include("Dummy text")
end
end
end
end

22
spec/helpers/merge_requests_helper_spec.rb

@ -269,4 +269,26 @@ RSpec.describe MergeRequestsHelper do
end
end
end
describe "#merge_request_details_prompt" do
it "returns the correct message for existing_absorbing_organisation" do
expect(helper.merge_request_details_prompt("existing_absorbing_organisation")).to eq("Answer if absorbing organisation is already active")
end
it "returns the correct message for helpdesk_ticket" do
expect(helper.merge_request_details_prompt("helpdesk_ticket")).to eq("Enter helpdesk ticket number")
end
it "returns the correct message for merging_organisations" do
expect(helper.merge_request_details_prompt("merging_organisations")).to eq("Add merging organisations")
end
it "returns the correct message for merge_date" do
expect(helper.merge_request_details_prompt("merge_date")).to eq("Set merge date")
end
it "returns a default message for an unknown page" do
expect(helper.merge_request_details_prompt("unknown_page")).to eq("Enter unknown page")
end
end
end

25
spec/models/form/question_spec.rb

@ -129,6 +129,11 @@ RSpec.describe Form::Question, type: :model do
expect(question).not_to be_value_is_yes("random")
end
it "has a check answer prompt" do
question_definition["check_answer_prompt"] = "Enter total income"
expect(question.check_answer_prompt).to eq("Enter total income")
end
context "when type is numeric" do
it "has a min value" do
expect(question.min).to eq(0)
@ -141,6 +146,10 @@ RSpec.describe Form::Question, type: :model do
it "does not map value from label" do
expect(question.value_from_label("5")).to eq("5")
end
it "has generates a default check answer prompt" do
expect(question.check_answer_prompt).to eq("Enter income")
end
end
context "when type is radio" do
@ -159,6 +168,10 @@ RSpec.describe Form::Question, type: :model do
expect(question.label_from_value(1)).to eq("Weekly")
end
it "has generates a default check answer prompt" do
expect(question.check_answer_prompt).to eq("Select income")
end
context "when answer options include yes, no, prefer not to say" do
let(:question_id) { "illness" }
@ -222,6 +235,10 @@ RSpec.describe Form::Question, type: :model do
expect(question.label_from_value("E09000033")).to eq("Westminster")
end
it "has generates a default check answer prompt" do
expect(question.check_answer_prompt).to eq("Select income")
end
context "when the saved answer is not in the value map" do
it "displays the saved answer umapped" do
expect(question.label_from_value(9999)).to eq("9999")
@ -234,6 +251,10 @@ RSpec.describe Form::Question, type: :model do
let(:page_id) { "illness" }
let(:answer_options) { { "illness_type_1" => { "value" => "Vision - such as blindness or partial sight" }, "illness_type_2" => { "value" => "Hearing - such as deafness or partial hearing" } } }
it "has generates a default check answer prompt" do
expect(question.check_answer_prompt).to eq("Select income")
end
it "has answer options" do
expected_answer_options = {
"illness_type_1" => { "value" => "Vision - such as blindness or partial sight" },
@ -317,6 +338,10 @@ RSpec.describe Form::Question, type: :model do
lettings_log.mrcdate = nil
expect(question.answer_label(lettings_log)).to eq("")
end
it "has generates a default check answer prompt" do
expect(question.check_answer_prompt).to eq("Set income")
end
end
context "when type is checkbox" do

Loading…
Cancel
Save