Browse Source
* Add custom guidance partials * Add a test for the partial being rendered * Add some unit tests for this * Rubocop * Don't introduce heisenspecs * Use component * Add comment * Update check values * Make net_income_known enumpull/197/head
baarkerlounger
3 years ago
committed by
GitHub
22 changed files with 166 additions and 24 deletions
@ -0,0 +1,16 @@ |
|||||||
|
<%= govuk_details(summary_text: 'What counts as income?') do %> |
||||||
|
<p class="govuk-body">You should include any income from:</p> |
||||||
|
<ul class="govuk-list govuk-list--bullet"> |
||||||
|
<li>employment</li> |
||||||
|
<li>pensions</li> |
||||||
|
<li>Universal Credit</li> |
||||||
|
</ul> |
||||||
|
|
||||||
|
<p class="govuk-body">Don’t include:</p> |
||||||
|
<ul class="govuk-list govuk-list--bullet"> |
||||||
|
<li>National Insurance (NI) contributions and tax</li> |
||||||
|
<li>housing benefit</li> |
||||||
|
<li>child benefit</li> |
||||||
|
<li>council tax support</li> |
||||||
|
</ul> |
||||||
|
<% end %> |
@ -0,0 +1 @@ |
|||||||
|
Rails.application.config.action_view.default_form_builder = GOVUKDesignSystemFormBuilder::FormBuilder |
@ -0,0 +1,15 @@ |
|||||||
|
class ConvertNetIncomeKnownToEnum < ActiveRecord::Migration[7.0] |
||||||
|
def up |
||||||
|
change_table :case_logs, bulk: true do |t| |
||||||
|
t.remove :net_income_known |
||||||
|
t.column :net_income_known, :integer |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def down |
||||||
|
change_table :case_logs, bulk: true do |t| |
||||||
|
t.remove :net_income_known |
||||||
|
t.column :net_income_known, :string |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,81 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require_relative "../../request_helper" |
||||||
|
|
||||||
|
RSpec.describe "form/page" do |
||||||
|
before do |
||||||
|
RequestHelper.stub_http_requests |
||||||
|
end |
||||||
|
|
||||||
|
let(:case_log) { FactoryBot.create(:case_log, :in_progress) } |
||||||
|
let(:form) { case_log.form } |
||||||
|
let(:subsection) { form.get_subsection("income_and_benefits") } |
||||||
|
let(:page) { form.get_page("net_income") } |
||||||
|
let(:question) { page.questions.find { |q| q.id == "earnings" } } |
||||||
|
let(:initial_attribs) { { type: "numeric", answer_options: nil } } |
||||||
|
|
||||||
|
def assign_attributes(object, attrs) |
||||||
|
attrs.each_pair do |attr, value| |
||||||
|
object.public_send("#{attr}=", value) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "given a question with extra guidance" do |
||||||
|
let(:expected_guidance) { /What counts as income?/ } |
||||||
|
|
||||||
|
before do |
||||||
|
assign(:case_log, case_log) |
||||||
|
assign(:page, page) |
||||||
|
assign(:subsection, subsection) |
||||||
|
assign_attributes(question, attribs) |
||||||
|
render |
||||||
|
end |
||||||
|
|
||||||
|
after do |
||||||
|
# Revert any changes we've made to avoid affecting other specs as the form, |
||||||
|
# subsection, page, question objects being acted on are in memory |
||||||
|
assign_attributes(question, initial_attribs) |
||||||
|
end |
||||||
|
|
||||||
|
context "with radio type" do |
||||||
|
let(:attribs) { { type: "radio", answer_options: { "1": "A", "2": "B" } } } |
||||||
|
it "renders the guidance partial for radio questions" do |
||||||
|
expect(rendered).to match(expected_guidance) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with text type" do |
||||||
|
let(:attribs) { { type: "text", answer_options: nil } } |
||||||
|
it "renders the guidance partial for text questions" do |
||||||
|
expect(rendered).to match(expected_guidance) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with numeric type" do |
||||||
|
let(:attribs) { { type: "numeric", answer_options: nil } } |
||||||
|
it "renders the guidance partial for numeric questions" do |
||||||
|
expect(rendered).to match(expected_guidance) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with select type" do |
||||||
|
let(:attribs) { { type: "select", answer_options: { "1": "A", "2": "B" } } } |
||||||
|
it "renders the guidance partial for select questions" do |
||||||
|
expect(rendered).to match(expected_guidance) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with checkbox type" do |
||||||
|
let(:attribs) { { type: "checkbox", answer_options: { "1": "A", "2": "B" } } } |
||||||
|
it "renders the guidance partial for checkbox questions" do |
||||||
|
expect(rendered).to match(expected_guidance) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with date type" do |
||||||
|
let(:attribs) { { type: "date", answer_options: nil } } |
||||||
|
it "renders the guidance partial for date questions" do |
||||||
|
expect(rendered).to match(expected_guidance) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue