diff --git a/spec/helpers/all_casa_admins/casa_orgs_helper_spec.rb b/spec/helpers/all_casa_admins/casa_orgs_helper_spec.rb index a3994d1b54..ea3fc23f39 100644 --- a/spec/helpers/all_casa_admins/casa_orgs_helper_spec.rb +++ b/spec/helpers/all_casa_admins/casa_orgs_helper_spec.rb @@ -1,7 +1,16 @@ require "rails_helper" RSpec.describe AllCasaAdmins::CasaOrgsHelper, type: :helper do - # TODO: Add tests for AllCasaAdmins::CasaOrgsHelper + describe "#selected_organization" do + it "returns the assigned @casa_org" do + casa_org = build(:casa_org) + assign(:casa_org, casa_org) - pending "add some tests for AllCasaAdmins::CasaOrgsHelper" + expect(helper.selected_organization).to eq(casa_org) + end + + it "returns nil when no @casa_org is assigned" do + expect(helper.selected_organization).to be_nil + end + end end diff --git a/spec/helpers/api_base_helper_spec.rb b/spec/helpers/api_base_helper_spec.rb index 6c0d2ec280..df1340f612 100644 --- a/spec/helpers/api_base_helper_spec.rb +++ b/spec/helpers/api_base_helper_spec.rb @@ -1,7 +1,9 @@ require "rails_helper" RSpec.describe ApiBaseHelper, type: :helper do - # TODO: Add tests for ApiBaseHelper - - pending "add some tests for ApiBaseHelper" + describe "SHORT_IO" do + it "is the short.io API base URL" do + expect(ApiBaseHelper::SHORT_IO).to eq("https://api.short.io/") + end + end end diff --git a/spec/helpers/date_helper_spec.rb b/spec/helpers/date_helper_spec.rb index e076a46eff..1962949b5b 100644 --- a/spec/helpers/date_helper_spec.rb +++ b/spec/helpers/date_helper_spec.rb @@ -1,7 +1,78 @@ require "rails_helper" RSpec.describe DateHelper, type: :helper do - # TODO: Add tests for DateHelper + describe "JQUERY_MONTH_DAY_YEAR_FORMAT" do + it "is the jQuery datepicker month/day/year format" do + expect(DateHelper::JQUERY_MONTH_DAY_YEAR_FORMAT).to eq("MM d, yyyy") + end + end - pending "add some tests for DateHelper" + describe "RUBY_MONTH_DAY_YEAR_FORMAT" do + it "is the Ruby strftime month/day/year format" do + expect(DateHelper::RUBY_MONTH_DAY_YEAR_FORMAT).to eq("%B %d, %Y") + end + end + + describe "#validate_date" do + it "parses a valid day, month, and year" do + expect(helper.validate_date("15", "6", "2021")).to eq(Date.new(2021, 6, 15)) + end + + it "raises Date::Error when the day is blank" do + expect { helper.validate_date("", "6", "2021") }.to raise_error(Date::Error) + end + + it "raises Date::Error when the month is blank" do + expect { helper.validate_date("15", "", "2021") }.to raise_error(Date::Error) + end + + it "raises Date::Error when the year is blank" do + expect { helper.validate_date("15", "6", "") }.to raise_error(Date::Error) + end + end + + describe "#parse_date" do + let(:errors) { ActiveModel::Errors.new(double("record")) } + + it "sets the parsed date under the field name when all parts are present" do + args = { + "court_report_due_date(1i)" => "2021", + "court_report_due_date(2i)" => "6", + "court_report_due_date(3i)" => "15" + } + + result = helper.parse_date(errors, "court_report_due_date", args) + + expect(result[:court_report_due_date]).to eq(Date.new(2021, 6, 15)) + expect(result).not_to have_key("court_report_due_date(1i)") + expect(errors).to be_empty + end + + it "adds an error and leaves the date field unset when the date is invalid" do + args = { + "court_report_due_date(1i)" => "2021", + "court_report_due_date(2i)" => "2", + "court_report_due_date(3i)" => "31" + } + + result = helper.parse_date(errors, "court_report_due_date", args) + + expect(result).not_to have_key(:court_report_due_date) + expect(errors[:court_report_due_date]).to include("was not a valid date.") + end + + it "strips the date part keys and adds no date when all parts are blank" do + args = { + "court_report_due_date(1i)" => "", + "court_report_due_date(2i)" => "", + "court_report_due_date(3i)" => "", + "other_field" => "unchanged" + } + + result = helper.parse_date(errors, "court_report_due_date", args) + + expect(result).to eq({"other_field" => "unchanged"}) + expect(errors).to be_empty + end + end end diff --git a/spec/helpers/request_header_helper_spec.rb b/spec/helpers/request_header_helper_spec.rb index 2174fe35da..6f1e9e5d23 100644 --- a/spec/helpers/request_header_helper_spec.rb +++ b/spec/helpers/request_header_helper_spec.rb @@ -1,7 +1,15 @@ require "rails_helper" RSpec.describe RequestHeaderHelper, type: :helper do - # TODO: Add tests for RequestHeaderHelper + describe "ACCEPT_JSON" do + it "is the JSON accept header" do + expect(RequestHeaderHelper::ACCEPT_JSON).to eq({"Accept" => "application/json"}) + end + end - pending "add some tests for RequestHeaderHelper" + describe "CONTENT_TYPE_JSON" do + it "is the JSON content type header" do + expect(RequestHeaderHelper::CONTENT_TYPE_JSON).to eq({"Content-Type" => "application/json"}) + end + end end diff --git a/spec/helpers/template_helper_spec.rb b/spec/helpers/template_helper_spec.rb index 8f08dd6a52..8e08522396 100644 --- a/spec/helpers/template_helper_spec.rb +++ b/spec/helpers/template_helper_spec.rb @@ -1,7 +1,67 @@ require "rails_helper" RSpec.describe TemplateHelper, type: :helper do - # TODO: Add tests for TemplateHelper + describe "#sanitize_opening_tags" do + it "strips attributes down to the tag name" do + expect(helper.sanitize_opening_tags(["