From 578f582fc0a797a8c31cdc99b25e78be35df9169 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Tue, 31 May 2016 18:07:26 +0100 Subject: [PATCH 01/22] Allow users to select a child benefit stop date in years up to 2013 The child benefit start and stop dates are dynamically created lists. Changed the child benefit stop date to populate years upto four years in the past. --- app/views/child_benefit_tax/_starting_child.html.erb | 2 +- spec/features/child_benefit_tax_calculator_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/views/child_benefit_tax/_starting_child.html.erb b/app/views/child_benefit_tax/_starting_child.html.erb index f9c7680d..7b118fb7 100644 --- a/app/views/child_benefit_tax/_starting_child.html.erb +++ b/app/views/child_benefit_tax/_starting_child.html.erb @@ -15,5 +15,5 @@ <% end %> <%= select_date (child ? child.end_date : nil), :prefix => "starting_children[#{index}][stop]", :prompt => {:day => "Day", :month => "Month", :year => "Year" }, :order => [:day, :month, :year], - :start_year => 2.years.ago(Date.today).year, :end_year => 10.years.since(Date.today).year %> + :start_year => 3.years.ago(Date.today).year, :end_year => 10.years.since(Date.today).year %> diff --git a/spec/features/child_benefit_tax_calculator_spec.rb b/spec/features/child_benefit_tax_calculator_spec.rb index ccc6417b..75541949 100644 --- a/spec/features/child_benefit_tax_calculator_spec.rb +++ b/spec/features/child_benefit_tax_calculator_spec.rb @@ -85,6 +85,15 @@ ) end + it "should allow stop date to be three years in the past" do + Timecop.freeze('2014-04-04') + visit "/child-benefit-tax-calculator" + click_on "Start now" + + expected_year_list = ("2011".."2024").to_a + expect(page).to have_select("starting_children_0_stop_year", options: expected_year_list.unshift("Year")) + end + it "should show error if no children are present in the selected tax year" do Timecop.travel "2014-09-01" visit "/child-benefit-tax-calculator" From 529ba73760c53fda0dc80fe8a811e8aa1e630022 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Wed, 1 Jun 2016 11:44:52 +0100 Subject: [PATCH 02/22] Update README with a note about HICBC and the tax commencement date --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 08ac2361..8f9b606a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,15 @@ Calculators This is an application to contain custom-built calculators. These will initially replace some smart-answers that have outgrown the framework. +## Child benefit tax calculator +Currently the only calculator in this application is the Child benefit tax calculator. + +This calculator reports how much child benefit tax you are entitled during a tax year. + +There is a cut-off date of 7 January 2013. This is the date [High Income Child Benefit Tax Charge](https://www.gov.uk/child-benefit-tax-charge/overview) came in effect. +This means that if the 2012 tax year is selected the calculator will only calculate the child benefit you are entitled to from 7 Jan 2013 to 5 Apr 2013, not for the entire tax year. + + ## Running the app ``` From 68dad6140f55ae3e794cc43f3bd3a476bd5ee9c2 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Thu, 2 Jun 2016 11:52:25 +0100 Subject: [PATCH 03/22] Reorder questions two and three In preparation for the new Part year question, reorder questions two and three so that the users is asked to select the tax year they want to check before entering the child benefit start and end dates for their children. --- app/views/child_benefit_tax/main.html.erb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/child_benefit_tax/main.html.erb b/app/views/child_benefit_tax/main.html.erb index 8c93f801..c2a832a0 100644 --- a/app/views/child_benefit_tax/main.html.erb +++ b/app/views/child_benefit_tax/main.html.erb @@ -35,17 +35,8 @@ <%= submit_tag "Update", :name => "children", :class => "button update-button" %> -
- <%= step(2, "Enter the Child Benefit start and stop dates:") %> -
    -
  • the start date is usually when you have a baby, adopt or move in with a new partner and their children
  • -
  • the stop date is usually when a child turns 16 or leaves full-time education
  • -
- <%= render "starting_children" %> -
-
- <%= step(3, "Choose a tax year:") %> + <%= step(2, "Choose a tax year:") %>

Tax years run from 6 April to 5 April the following year.

<% @calculator.errors[:tax_year].each do |message| %> @@ -60,6 +51,15 @@
+
+ <%= step(3, "Enter the Child Benefit start and stop dates:") %> +
    +
  • the start date is usually when you have a baby, adopt or move in with a new partner and their children
  • +
  • the stop date is usually when a child turns 16 or leaves full-time education
  • +
+ <%= render "starting_children" %> +
+
<%= step(4, "Enter income details for the tax year (optional):") %>
    From 27b5de0cf5539cf7d2bf5e0e439671a62ef7a38a Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Thu, 16 Jun 2016 11:51:46 +0100 Subject: [PATCH 04/22] Change which Mondays are included in the calculation. The start date was considered the birth date/adoption date of the child. If the child was born on a Monday, the child benefit started from the following Monday. Under the new rules, we are going to assume the start date is the effective date of the child benefit, i.e. the date the child benefit starts. If the effective start date is a Monday, we also need to include that Monday in the calculation. Updated the tests to account for the new "Monday" rules. --- app/models/starting_child.rb | 13 +++++++++++-- .../child_benefit_tax_calculator_spec.rb | 18 +++++++++--------- spec/models/starting_child_spec.rb | 7 ++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/models/starting_child.rb b/app/models/starting_child.rb index dda40449..ef2bfabf 100644 --- a/app/models/starting_child.rb +++ b/app/models/starting_child.rb @@ -20,10 +20,19 @@ def benefits_end @end_date ? @end_date : tax_years[tax_years.keys.sort.last].last end - # Return the next Monday if start_date is not nil. + # Return the date of the Monday in the future that is closest to the start_date. + # If the start_date is a Monday, use the start_date. def adjusted_start_date return nil if start_date.nil? - start_date + (start_date.wday < 1 ? 1 : (1 - start_date.wday) + 7) + + if start_date.wday < 1 + start_date + 1.day + elsif start_date.wday > 1 + number_of_days_til_next_monday = ((1 - start_date.wday) + 7) + start_date + number_of_days_til_next_monday + else + start_date + end end private diff --git a/spec/models/child_benefit_tax_calculator_spec.rb b/spec/models/child_benefit_tax_calculator_spec.rb index cd442a55..2c7591dd 100644 --- a/spec/models/child_benefit_tax_calculator_spec.rb +++ b/spec/models/child_benefit_tax_calculator_spec.rb @@ -488,10 +488,10 @@ }, }, ) - expect(calc.benefits_claimed_amount.round(2)).to eq(598.90) - expect(calc.tax_estimate).to eq(359) + expect(calc.benefits_claimed_amount.round(2)).to eq(612.30) + expect(calc.tax_estimate).to eq(367) end - it "should calculate one week for one child observing the 'next Monday' rule." do + it "should calculate two weeks for one child observing the 'Monday' rules." do expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: 1, @@ -501,7 +501,7 @@ stop: { day: "21", month: "01", year: "2013" }, }, }, - ).benefits_claimed_amount.round(2)).to eq(20.30) + ).benefits_claimed_amount.round(2)).to eq(40.60) end it "should calculate 3 children already in the household for 2013/2014" do calc = ChildBenefitTaxCalculator.new( @@ -556,7 +556,7 @@ children_count: 1, starting_children: { "0" => { - start: { day: "24", month: "06", year: "2013" }, + start: { day: "01", month: "07", year: "2013" }, stop: { day: "", month: "", year: "" }, }, }, @@ -651,7 +651,7 @@ stop: { day: "", month: "", year: "" }, }, }, - ).benefits_claimed_amount.round(2)).to eq(2501.2) + ).benefits_claimed_amount.round(2)).to eq(2549.3) end it "should give the total amount of benefits received for a full tax year 2015" do @@ -664,7 +664,7 @@ stop: { year: "2016", month: "04", day: "05" }, }, }, - ).benefits_claimed_amount.round(2)).to eq(1076.4) + ).benefits_claimed_amount.round(2)).to eq(1097.1) end it "should give total amount of benefits one child full year one child half a year" do @@ -681,7 +681,7 @@ stop: { day: "06", month: "11", year: "2016" }, }, }, - ).benefits_claimed_amount.round(2)).to eq(1788.8) + ).benefits_claimed_amount.round(2)).to eq(1823.2) end it "should give total amount of benefits for one child for half a year" do @@ -695,7 +695,7 @@ }, }, ) - expect(calc.benefits_claimed_amount.round(2)).to eq(621.0) + expect(calc.benefits_claimed_amount.round(2)).to eq(641.7) end end diff --git a/spec/models/starting_child_spec.rb b/spec/models/starting_child_spec.rb index d5aaf37d..fe199974 100644 --- a/spec/models/starting_child_spec.rb +++ b/spec/models/starting_child_spec.rb @@ -47,9 +47,9 @@ end describe "adjusted_start_date" do - it "should return the next Monday if start date is 7th January 2013" do + it "should not adjust the start date if start date is a Monday" do child = StartingChild.new(start: { year: "2013", month: "01", day: "07" }) - expect(child.adjusted_start_date).to eq(Date.parse("14 January 2013")) + expect(child.adjusted_start_date).to eq(Date.parse("07 January 2013")) end it "should return the next Monday for the provided start date" do @@ -64,9 +64,6 @@ child = StartingChild.new(start: { year: "2013", month: "01", day: "06" }) expect(child.adjusted_start_date).to eq(Date.parse("7 January 2013")) - - child = StartingChild.new(start: { year: "2013", month: "01", day: "14" }) - expect(child.adjusted_start_date).to eq(Date.parse("21 January 2013")) end it "should not blow up with a nil start date" do From 825dbefec68a84cfc827f7b60adde4f9efeb617f Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Thu, 16 Jun 2016 12:05:23 +0100 Subject: [PATCH 05/22] Change the copy for the start date to ask for the effective date --- app/views/child_benefit_tax/main.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/child_benefit_tax/main.html.erb b/app/views/child_benefit_tax/main.html.erb index c2a832a0..b8adeef3 100644 --- a/app/views/child_benefit_tax/main.html.erb +++ b/app/views/child_benefit_tax/main.html.erb @@ -54,7 +54,7 @@
    <%= step(3, "Enter the Child Benefit start and stop dates:") %>
      -
    • the start date is usually when you have a baby, adopt or move in with a new partner and their children
    • +
    • the start date is called an ‘effective date’ - you can find it on your Child Benefit award notice
    • the stop date is usually when a child turns 16 or leaves full-time education
    <%= render "starting_children" %> From 74abec573f247941f5da90f29685517bd2e81646 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Fri, 17 Jun 2016 14:35:54 +0100 Subject: [PATCH 06/22] Refactor how the next Monday is calculated The next monday is calculated in two places. Before the changes in commit 994d1db, these calculations produced different result: 1. The adjusted_start_date attribute on the child is set only once and was set to the Monday after the start date. This has since been changed to also include the start date, if the start date is a Monday. 2. The code that determines how many weeks to calculate child benefit for counts the number of Mondays in the tax year, including the first day of the tax year if that happened to be a Monday. Now both return the same date, so the next Monday calculation function (monday_on_or_after) is being used in both instances. The adjusted start date on the Starting Child is a property that changes the child's start date to the next valid monday to comply with the rules. Models shouldn't be aware of the rules of a calculator so this property has been removed. The next Monday calculation function is instead being called on the Starting Child start date to extrapolate what the benefit start date would be. The tests that previously tested the adjusted start date property have been removed and new tests have been added to the child benefit tax calculator model. monday_on_or_after uses the Rails DateAndTime helper functions to calculate the next Monday See API documentation: http://api.rubyonrails.org/classes/DateAndTime/Calculations.html#method-i-next_week --- app/models/child_benefit_tax_calculator.rb | 8 ++++-- app/models/starting_child.rb | 15 ----------- .../child_benefit_tax_calculator_spec.rb | 26 +++++++++++++++++++ spec/models/starting_child_spec.rb | 25 ------------------ 4 files changed, 32 insertions(+), 42 deletions(-) diff --git a/app/models/child_benefit_tax_calculator.rb b/app/models/child_benefit_tax_calculator.rb index 552fb7e2..153da8e0 100644 --- a/app/models/child_benefit_tax_calculator.rb +++ b/app/models/child_benefit_tax_calculator.rb @@ -37,8 +37,10 @@ def valid_date_params?(params) self.class.valid_date_params?(params) end + # Return the date of the Monday in the future that is closest to the date supplied. + # If the date supplied is a Monday, do not adjust it. def monday_on_or_after(date) - date + ((1 - date.wday) % 7) + date.monday? ? date : date.next_week(:monday) end def nothing_owed? @@ -114,8 +116,10 @@ def process_starting_children(children) end def eligible?(child, tax_year, week_start_date) + adjusted_start_date = monday_on_or_after(child.start_date) + eligible_for_tax_year?(child, tax_year) && - days_include_week?(child.adjusted_start_date, child.benefits_end, week_start_date) + days_include_week?(adjusted_start_date, child.benefits_end, week_start_date) end def eligible_for_tax_year?(child, tax_year) diff --git a/app/models/starting_child.rb b/app/models/starting_child.rb index ef2bfabf..82ade811 100644 --- a/app/models/starting_child.rb +++ b/app/models/starting_child.rb @@ -20,21 +20,6 @@ def benefits_end @end_date ? @end_date : tax_years[tax_years.keys.sort.last].last end - # Return the date of the Monday in the future that is closest to the start_date. - # If the start_date is a Monday, use the start_date. - def adjusted_start_date - return nil if start_date.nil? - - if start_date.wday < 1 - start_date + 1.day - elsif start_date.wday > 1 - number_of_days_til_next_monday = ((1 - start_date.wday) + 7) - start_date + number_of_days_til_next_monday - else - start_date - end - end - private def valid_dates diff --git a/spec/models/child_benefit_tax_calculator_spec.rb b/spec/models/child_benefit_tax_calculator_spec.rb index 2c7591dd..773f59ff 100644 --- a/spec/models/child_benefit_tax_calculator_spec.rb +++ b/spec/models/child_benefit_tax_calculator_spec.rb @@ -24,6 +24,32 @@ expect(calc.adjusted_net_income).to eq(100900) end + describe "#monday_on_or_after" do + subject { ChildBenefitTaxCalculator.new } + + it "should return the tomorrow if the date is a Sunday" do + sunday = Date.parse("1 January 2012") + monday = Date.parse("2 January 2012") + + expect(subject.monday_on_or_after(sunday)).to eq(monday) + end + + it "should return today if today is a Monday" do + monday = Date.parse("2 January 2012") + + expect(subject.monday_on_or_after(monday)).to eq(monday) + end + + it "should return the following Monday for days between Tueday and Saturday" do + tuesday = Date.parse("3 January 2012") + saturday = Date.parse("7 January 2012") + next_monday = Date.parse("9 January 2012") + + expect(subject.monday_on_or_after(tuesday)).to eq(next_monday) + expect(subject.monday_on_or_after(saturday)).to eq(next_monday) + end + end + describe "input validation" do before(:each) do @calc = ChildBenefitTaxCalculator.new(children_count: "1") diff --git a/spec/models/starting_child_spec.rb b/spec/models/starting_child_spec.rb index fe199974..0a2ea535 100644 --- a/spec/models/starting_child_spec.rb +++ b/spec/models/starting_child_spec.rb @@ -45,29 +45,4 @@ ) expect(child).to be_valid end - - describe "adjusted_start_date" do - it "should not adjust the start date if start date is a Monday" do - child = StartingChild.new(start: { year: "2013", month: "01", day: "07" }) - expect(child.adjusted_start_date).to eq(Date.parse("07 January 2013")) - end - - it "should return the next Monday for the provided start date" do - child = StartingChild.new(start: { year: "2012", month: "01", day: "01" }) - expect(child.adjusted_start_date).to eq(Date.parse("2 January 2012")) - - child = StartingChild.new(start: { year: "2013", month: "05", day: "08" }) - expect(child.adjusted_start_date).to eq(Date.parse("13 May 2013")) - - child = StartingChild.new(start: { year: "2013", month: "08", day: "13" }) - expect(child.adjusted_start_date).to eq(Date.parse("19 August 2013")) - - child = StartingChild.new(start: { year: "2013", month: "01", day: "06" }) - expect(child.adjusted_start_date).to eq(Date.parse("7 January 2013")) - end - - it "should not blow up with a nil start date" do - expect(StartingChild.new(start: {}).adjusted_start_date).to be_nil - end - end end From 5e9a6856a3a5df946dc2bd766670fb6e0b6797b2 Mon Sep 17 00:00:00 2001 From: Ikenna Okpala Date: Thu, 16 Jun 2016 14:00:52 +0100 Subject: [PATCH 07/22] Define is_part_year_claim to hold the user entry --- app/models/adjusted_net_income_calculator.rb | 2 +- app/models/child_benefit_tax_calculator.rb | 10 +++- .../child_benefit_tax_calculator_spec.rb | 46 +++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/app/models/adjusted_net_income_calculator.rb b/app/models/adjusted_net_income_calculator.rb index af205113..5d37ad8d 100644 --- a/app/models/adjusted_net_income_calculator.rb +++ b/app/models/adjusted_net_income_calculator.rb @@ -2,7 +2,7 @@ class AdjustedNetIncomeCalculator PARAM_KEYS = [:gross_income, :other_income, :pension_contributions_from_pay, :retirement_annuities, :cycle_scheme, :childcare, :pensions, :property, - :non_employment_income, :gift_aid_donations, :outgoing_pension_contributions] + :non_employment_income, :gift_aid_donations, :outgoing_pension_contributions, :is_part_year_claim] def initialize(params) PARAM_KEYS.each do |key| diff --git a/app/models/child_benefit_tax_calculator.rb b/app/models/child_benefit_tax_calculator.rb index 153da8e0..1b074a21 100644 --- a/app/models/child_benefit_tax_calculator.rb +++ b/app/models/child_benefit_tax_calculator.rb @@ -4,7 +4,7 @@ class ChildBenefitTaxCalculator include ActiveModel::Validations attr_reader :adjusted_net_income_calculator, :adjusted_net_income, :children_count, - :starting_children, :tax_year + :starting_children, :tax_year, :is_part_year_claim NET_INCOME_THRESHOLD = 50000 TAX_COMMENCEMENT_DATE = Date.parse('7 Jan 2013') @@ -18,6 +18,7 @@ class ChildBenefitTaxCalculator } validate :valid_child_dates + validates_presence_of :is_part_year_claim, message: "select part year tax claim" validates_inclusion_of :tax_year, in: TAX_YEARS.keys.map(&:to_i), message: "select a tax year" validate :tax_year_contains_at_least_one_child @@ -25,6 +26,7 @@ def initialize(params = {}) @adjusted_net_income_calculator = AdjustedNetIncomeCalculator.new(params) @adjusted_net_income = calculate_adjusted_net_income(params[:adjusted_net_income]) @children_count = params[:children_count] ? params[:children_count].to_i : 1 + @is_part_year_claim = params[:is_part_year_claim] @starting_children = process_starting_children(params[:starting_children]) @tax_year = params[:year].to_i end @@ -48,7 +50,11 @@ def nothing_owed? end def has_errors? - errors.any? || starting_children.select { |c| c.errors.any? }.any? + errors.any? || starting_children_errors? + end + + def starting_children_errors? + is_part_year_claim == 'yes' && starting_children.select { |c| c.errors.any? }.any? end def percent_tax_charge diff --git a/spec/models/child_benefit_tax_calculator_spec.rb b/spec/models/child_benefit_tax_calculator_spec.rb index 773f59ff..836d27f0 100644 --- a/spec/models/child_benefit_tax_calculator_spec.rb +++ b/spec/models/child_benefit_tax_calculator_spec.rb @@ -147,6 +147,25 @@ ).has_errors?).to eq(false) end end + + describe "#is_part_year_claim" do + it "should contain errors if tax claim duration is not provided" do + calc = ChildBenefitTaxCalculator.new(children_count: "1", year: 2012) + calc.valid? + expect(calc.errors).to have_key(:is_part_year_claim) + expect(calc.errors.size).to eq(1) + end + it "should not contain errors if tax claim duration is set to no" do + calc = ChildBenefitTaxCalculator.new(children_count: "1", year: 2012, is_part_year_claim: "no") + calc.valid? + expect(calc.errors).to be_empty + end + it "should not contain errors if tax claim duration is set to yes" do + calc = ChildBenefitTaxCalculator.new(children_count: "1", year: 2012, is_part_year_claim: "yes") + calc.valid? + expect(calc.errors).to be_empty + end + end end describe "calculating benefits received" do @@ -790,6 +809,33 @@ ) expect(calc.benefits_claimed_amount.round(2)).to eq(621.0) end + + it "should set the start date to start of the selected tax year" do + calc = ChildBenefitTaxCalculator.new( + year: "2015", + children_count: 1, + is_part_year_claim: "no" + ) + + expect(calc.child_benefit_start_date).to eq(Date.parse("06 April 2015")) + expect(calc.child_benefit_end_date).to eq(Date.parse("05 April 2016")) + end + + it "should set the stop date to end of the selected tax year" do + calc = ChildBenefitTaxCalculator.new( + year: "2015", + children_count: 1, + is_part_year_claim: "yes", + starting_children: { + "0" => { + start: { day: "06", month: "04", year: "2015" }, + stop: { day: "", month: "", year: "" }, + }, + }, + ) + + expect(calc.child_benefit_end_date).to eq(Date.parse("05 April 2016")) + end end end end From ae73ce404e8b6226afd9c0305a964eae22680ed0 Mon Sep 17 00:00:00 2001 From: Ikenna Okpala Date: Thu, 16 Jun 2016 14:03:36 +0100 Subject: [PATCH 08/22] Add new question 3 with the start date entry hidden. --- .../calculators/child_benefit.scss | 1 + app/views/child_benefit_tax/main.html.erb | 31 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/calculators/child_benefit.scss b/app/assets/stylesheets/calculators/child_benefit.scss index 4524de86..60948029 100644 --- a/app/assets/stylesheets/calculators/child_benefit.scss +++ b/app/assets/stylesheets/calculators/child_benefit.scss @@ -104,6 +104,7 @@ li { // scss-lint:disable IdSelector #children { margin-bottom: 0; + float: left; h3 { @include bold-19; diff --git a/app/views/child_benefit_tax/main.html.erb b/app/views/child_benefit_tax/main.html.erb index b8adeef3..cb7c642c 100644 --- a/app/views/child_benefit_tax/main.html.erb +++ b/app/views/child_benefit_tax/main.html.erb @@ -50,14 +50,21 @@ <% end -%>
    - -
    - <%= step(3, "Enter the Child Benefit start and stop dates:") %> -
      -
    • the start date is called an ‘effective date’ - you can find it on your Child Benefit award notice
    • -
    • the stop date is usually when a child turns 16 or leaves full-time education
    • -
    - <%= render "starting_children" %> + +
    + <%= step(3, "Choose a tax claim duration:") %> +

    Are you claiming for a part of the tax year for any of your children?

    +
    + <% @calculator.errors[:is_part_year_claim].each do |message| %> +

    <%= message %>

    + <% end -%> + <% ["yes", "no"].each do |option| -%> + + <% end -%> +
    @@ -93,6 +100,14 @@ <%= submit_tag "Calculate", :name => "results", :class => "button" %> <% end %> + <% if can_haz_results? -%>
    From a48376b14373a9ca468c0e21cce6374f9fd17ee1 Mon Sep 17 00:00:00 2001 From: Ikenna Okpala Date: Thu, 16 Jun 2016 14:04:20 +0100 Subject: [PATCH 09/22] Add toggle function to show and hides the starting children sub question Also ensuring that on refresh render the right layout --- .../child-benefit-tax-calculator.js | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/child-benefit-tax-calculator.js b/app/assets/javascripts/child-benefit-tax-calculator.js index 2a183077..e9a93ff9 100644 --- a/app/assets/javascripts/child-benefit-tax-calculator.js +++ b/app/assets/javascripts/child-benefit-tax-calculator.js @@ -1,4 +1,4 @@ -(function () { +(function() { "use strict"; var root = this, @@ -7,17 +7,41 @@ var calculator = { childrenCountInput: $("#children_count"), - childrenContainer: $("fieldset#children"), - - setEventHandlers: function () { + childrenContainerTemplate: $("div#children-template"), + taxClaimContainer: $("fieldset#is-part-year-claim"), + taxClaimDurationInputs: $("input[id^='is_part_year_claim_']"), + childrenContainer: function() { + return $("div#children"); + }, + setEventHandlers: function() { calculator.childrenCountInput.on('change', calculator.updateChildrenFields); + calculator.taxClaimDurationInputs.on('change', calculator.triggerChildrenFieldsEvent); + calculator.setUpForm(); + }, + setUpForm: function(){ + var choosenTaxClaim = calculator.taxClaimDurationInputs.filter(":checked").val(); + calculator.toggleChildrenFields(choosenTaxClaim); + }, + triggerChildrenFieldsEvent: function(event){ + calculator.toggleChildrenFields($(event.currentTarget).val()); }, - updateChildrenFields: function () { + toggleChildrenFields: function(choosen){ + if (choosen == "yes") { + if (calculator.childrenContainer().length == 0) { + var childrenTag = calculator.childrenContainerTemplate.clone(); + calculator.taxClaimContainer.append(childrenTag); + childrenTag.attr("id", "children").show(); + calculator.updateChildrenFields(); + } + } else { + calculator.childrenContainer().remove(); + } + }, + updateChildrenFields: function() { var numStartingChildren = calculator.childrenCountInput.val(), - childFields = calculator.childrenContainer.find('> div.child'), + childFields = calculator.childrenContainer().find("> div.child"), numChildFields = childFields.size(), numNewFields = numStartingChildren - numChildFields; - if (numStartingChildren < 1 || numStartingChildren > 10) { return false; } @@ -31,7 +55,7 @@ } } }, - appendChildField: function (index) { + appendChildField: function(index) { var newChild = calculator.childFieldToClone().clone(); newChild.find('.child-number').text(index+1); @@ -44,14 +68,14 @@ $(this).attr('for', calculator.replaceIndex(index, $(this).attr('for'))); }); - newChild.appendTo(calculator.childrenContainer); + newChild.appendTo(calculator.childrenContainer()); }, - childFieldToClone: function () { + childFieldToClone: function() { // Always clone the first field so that we don't have to guess // the index (it will always be zero) - return calculator.childrenContainer.find("> div.child").first(); + return calculator.childrenContainer().find("> div.child").first(); }, - replaceIndex: function (index, str) { + replaceIndex: function(index, str) { return str.replace("0", index); } }; From 4dc20a26bb2444814bdc4114ac7cb0662866e146 Mon Sep 17 00:00:00 2001 From: Ikenna Okpala Date: Thu, 16 Jun 2016 14:04:32 +0100 Subject: [PATCH 10/22] Update ChildBenefitTaxCalculator tests --- .../child_benefit_tax_calculator_spec.rb | 133 +++++++++++++----- .../child_benefit_tax_calculator_spec.rb | 65 ++++++++- 2 files changed, 156 insertions(+), 42 deletions(-) diff --git a/spec/features/child_benefit_tax_calculator_spec.rb b/spec/features/child_benefit_tax_calculator_spec.rb index 75541949..3230abf6 100644 --- a/spec/features/child_benefit_tax_calculator_spec.rb +++ b/spec/features/child_benefit_tax_calculator_spec.rb @@ -1,7 +1,7 @@ # encoding: utf-8 require "spec_helper" -feature "Child Benefit Tax Calculator" do +feature "Child Benefit Tax Calculator", js: true do specify "inspecting the landing page" do visit "/child-benefit-tax-calculator" @@ -35,30 +35,87 @@ expect(page).to have_no_css(".results") end - it "should display validation errors" do - visit "/child-benefit-tax-calculator" - click_on "Start now" - click_on "Calculate" + context "page errors" do + before :each do + visit "/child-benefit-tax-calculator" + click_on "Start now" + end - within ".validation-summary" do - expect(page).to have_content("select a tax year") - expect(page).to have_content("enter the date Child Benefit started") + context "when tax claim duration isn't selected" do + it "should display validation errors" do + click_on "Calculate" + within ".validation-summary" do + expect(page).to have_content("select a tax year") + expect(page).to have_content("enter the date Child Benefit started") + end + + within "#tax-year" do + expect(page).to have_css(".validation-error") + expect(page).to have_content("select a tax year") + end + + within "#is-part-year-claim" do + expect(page).to have_css(".validation-error") + expect(page).to have_no_css("#children") + expect(page).to have_content("select part year tax claim") + end + end end - within "#tax-year" do - expect(page).to have_css(".validation-error") - expect(page).to have_content("select a tax year") + context "when NO is selected for tax claim duration" do + it "should display validation errors" do + choose "No" + click_on "Calculate" + within ".validation-summary" do + expect(page).to have_content("select a tax year") + expect(page).to have_content("enter the date Child Benefit started") + end + + within "#tax-year" do + expect(page).to have_css(".validation-error") + expect(page).to have_content("select a tax year") + end + + within "#is-part-year-claim" do + expect(page).to have_no_css(".validation-error") + expect(page).to have_no_css("#children") + expect(page).to have_no_content("select part year tax claim") + end + end end - within "#children" do - expect(page).to have_css(".validation-error") - expect(page).to have_content("enter the date Child Benefit started") + + context "when YES is selected for tax claim duration" do + it "should display validation errors" do + choose "Yes" + click_on "Calculate" + within ".validation-summary" do + expect(page).to have_content("select a tax year") + expect(page).to have_content("enter the date Child Benefit started") + end + + within "#tax-year" do + expect(page).to have_css(".validation-error") + expect(page).to have_content("select a tax year") + end + + within "#is-part-year-claim" do + expect(page).to have_css(".validation-error") + expect(page).to have_no_content("select part year tax claim") + + within "#children" do + expect(page).to have_css(".validation-error") + expect(page).to have_content("enter the date Child Benefit started") + end + end + end end end - it "should disallow dates with too many days for the selected month", js: true do + it "should disallow dates with too many days for the selected month" do Timecop.travel "2014-09-01" visit "/child-benefit-tax-calculator" click_on "Start now" + choose "Yes" select "2", from: "children_count" @@ -89,6 +146,7 @@ Timecop.freeze('2014-04-04') visit "/child-benefit-tax-calculator" click_on "Start now" + choose "Yes" expected_year_list = ("2011".."2024").to_a expect(page).to have_select("starting_children_0_stop_year", options: expected_year_list.unshift("Year")) @@ -98,6 +156,7 @@ Timecop.travel "2014-09-01" visit "/child-benefit-tax-calculator" click_on "Start now" + choose "Yes" select "1", from: "children_count" click_button "Update" @@ -127,6 +186,7 @@ before(:each) do visit "/child-benefit-tax-calculator" click_on "Start now" + choose "Yes" select "2", from: "children_count" click_button "Update" end @@ -172,7 +232,7 @@ expect(page).to have_no_css("#starting_children_1_start_day") end - it "should show the required number of date inputs without reloading the page", js: true do + it "should show the required number of date inputs without reloading the page" do expect(page).to have_select("children_count", selected: "2") expect(page).to have_css("#starting_children_0_start_year") @@ -236,10 +296,12 @@ allow_any_instance_of(ChildBenefitTaxCalculator).to receive(:benefits_claimed_amount).and_return(500000) visit "/child-benefit-tax-calculator" click_on "Start now" + choose "Yes" end it "should give an estimated total of tax due related to income" do allow_any_instance_of(ChildBenefitTaxCalculator).to receive(:tax_estimate).and_return(500000) + select "2011", from: "starting_children[0][start][year]" select "January", from: "starting_children[0][start][month]" select "1", from: "starting_children[0][start][day]" @@ -271,9 +333,12 @@ end describe "calculating adjusted net income" do + before(:each) do + visit "/child-benefit-tax-calculator" + click_on "Start now" + choose "Yes" + end it "should use the adjusted net income calculator inputs" do - visit "/child-benefit-tax-calculator/main" - select "2011", from: "starting_children[0][start][year]" select "January", from: "starting_children[0][start][month]" select "1", from: "starting_children[0][start][day]" @@ -303,8 +368,6 @@ end it "should update the adjusted_net_income when the calculator values are updated." do - visit "/child-benefit-tax-calculator/main" - select "2011", from: "starting_children[0][start][year]" select "January", from: "starting_children[0][start][month]" select "1", from: "starting_children[0][start][day]" @@ -341,10 +404,14 @@ end describe "displaying the results" do + before(:each) do + visit "/child-benefit-tax-calculator" + click_on "Start now" + choose "Yes" + end + context "without the tax estimate" do before :each do - visit "/child-benefit-tax-calculator/main" - select "2011", from: "starting_children_0_start_year" select "January", from: "starting_children_0_start_month" select "1", from: "starting_children_0_start_day" @@ -385,8 +452,6 @@ context "with the tax estimate" do before :each do - visit "/child-benefit-tax-calculator/main" - select "2011", from: "starting_children_0_start_year" select "January", from: "starting_children_0_start_month" select "1", from: "starting_children_0_start_day" @@ -460,8 +525,6 @@ context "with an Adjusted Net Income below the threshold" do it "should say there's nothing to pay" do - visit "/child-benefit-tax-calculator/main" - select "2011", from: "starting_children_0_start_year" select "January", from: "starting_children_0_start_month" select "1", from: "starting_children_0_start_day" @@ -489,10 +552,14 @@ end describe "child benefit week runs Monday to Sunday" do + before(:each) do + visit "/child-benefit-tax-calculator" + click_on "Start now" + choose "Yes" + end + context "tax year is 2012/2013" do specify "should have no child benefit when start date is 07/01/2013" do - visit "/child-benefit-tax-calculator/main" - select "2013", from: "starting_children_0_start_year" select "January", from: "starting_children_0_start_month" select "7", from: "starting_children_0_start_day" @@ -503,8 +570,6 @@ end specify "should have no child benefit when start date is 01/04/2013" do - visit "/child-benefit-tax-calculator/main" - select "2013", from: "starting_children_0_start_year" select "April", from: "starting_children_0_start_month" select "1", from: "starting_children_0_start_day" @@ -516,8 +581,6 @@ end specify "should have no child benefit when start date is 05/04/2013" do - visit "/child-benefit-tax-calculator/main" - select "2013", from: "starting_children_0_start_year" select "April", from: "starting_children_0_start_month" select "5", from: "starting_children_0_start_day" @@ -531,8 +594,6 @@ context "tax year is 2013/2014" do specify "should have no child benefit when start date is 31/03/2014" do - visit "/child-benefit-tax-calculator/main" - select "2014", from: "starting_children_0_start_year" select "March", from: "starting_children_0_start_month" select "31", from: "starting_children_0_start_day" @@ -544,8 +605,6 @@ end specify "should have no child benefit when start date is 01/04/2014" do - visit "/child-benefit-tax-calculator/main" - select "2014", from: "starting_children_0_start_year" select "April", from: "starting_children_0_start_month" select "1", from: "starting_children_0_start_day" @@ -557,8 +616,6 @@ end specify "should have no child benefit when start date is 05/04/2014" do - visit "/child-benefit-tax-calculator/main" - select "2014", from: "starting_children_0_start_year" select "April", from: "starting_children_0_start_month" select "5", from: "starting_children_0_start_day" diff --git a/spec/models/child_benefit_tax_calculator_spec.rb b/spec/models/child_benefit_tax_calculator_spec.rb index 836d27f0..7bae6c3b 100644 --- a/spec/models/child_benefit_tax_calculator_spec.rb +++ b/spec/models/child_benefit_tax_calculator_spec.rb @@ -15,6 +15,7 @@ it "is valid if given enough detail" do expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" } } }, ).can_calculate?).to eq(true) end @@ -52,7 +53,7 @@ describe "input validation" do before(:each) do - @calc = ChildBenefitTaxCalculator.new(children_count: "1") + @calc = ChildBenefitTaxCalculator.new(children_count: "1", is_part_year_claim: "no") @calc.valid? end it "should contain errors for year if none is given" do @@ -76,6 +77,7 @@ @calc = ChildBenefitTaxCalculator.new( year: "2013", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" }, @@ -91,6 +93,7 @@ @calc = ChildBenefitTaxCalculator.new( year: "2013", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" }, @@ -106,6 +109,7 @@ @calc = ChildBenefitTaxCalculator.new( year: "2013", children_count: "3", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" }, @@ -131,7 +135,7 @@ expect(@calc.errors.size).to eq(1) end it "should be true if any starting children have errors" do - calc = ChildBenefitTaxCalculator.new(year: "2012", children_count: "1") + calc = ChildBenefitTaxCalculator.new(year: "2012", children_count: "1", is_part_year_claim: "yes") calc.valid? expect(calc.errors).to be_empty #puts calc.starting_children.first.errors.full_messages @@ -141,6 +145,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2012", month: "01", day: "07" } }, }, @@ -161,7 +166,13 @@ expect(calc.errors).to be_empty end it "should not contain errors if tax claim duration is set to yes" do - calc = ChildBenefitTaxCalculator.new(children_count: "1", year: 2012, is_part_year_claim: "yes") + calc = ChildBenefitTaxCalculator.new(children_count: "1", + year: 2012, + is_part_year_claim: "yes", + starting_children: { + "0" => { start: { year: "2012", month: "01", day: "07" } }, + } + ) calc.valid? expect(calc.errors).to be_empty end @@ -173,6 +184,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "02", day: "01" }, @@ -185,6 +197,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2013", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2013", month: "04", day: "06" }, @@ -197,6 +210,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2012", month: "06", day: "01" }, @@ -209,6 +223,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: "2", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2012", month: "06", day: "01" }, @@ -230,6 +245,7 @@ other_income: "0", year: "2012", children_count: 2, + is_part_year_claim: "no", ).adjusted_net_income).to eq(50099) end @@ -247,6 +263,7 @@ childcare: "£1500", year: "2012", children_count: 2, + is_part_year_claim: "no", ).adjusted_net_income).to eq(66950) end @@ -265,6 +282,7 @@ childcare: "£1500", year: "2012", children_count: 2, + is_part_year_claim: "no", ).adjusted_net_income).to eq(66950) end end @@ -275,6 +293,7 @@ adjusted_net_income: "50099", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(0.0) end it "should be 1.0 for an income of 50199" do @@ -282,6 +301,7 @@ adjusted_net_income: "50199", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(1.0) end it "should be 2.0 for an income of 50200" do @@ -289,6 +309,7 @@ adjusted_net_income: "50200", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(2.0) end it "should be 40.0 for an income of 54013" do @@ -296,6 +317,7 @@ adjusted_net_income: "54013", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(40.0) end it "should be 40.0 for an income of 54089" do @@ -303,12 +325,14 @@ adjusted_net_income: "54089", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(40.0) end it "should be 99.0 for an income of 59999" do expect(ChildBenefitTaxCalculator.new( adjusted_net_income: "59999", year: "2012", + is_part_year_claim: "no", children_count: 2, ).percent_tax_charge).to eq(99.0) end @@ -317,6 +341,7 @@ adjusted_net_income: "60000", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(100.0) end it "should be 100.0 for an income of 60001" do @@ -324,6 +349,7 @@ adjusted_net_income: "60001", year: "2012", children_count: 2, + is_part_year_claim: "no", ).percent_tax_charge).to eq(100.0) end end @@ -333,6 +359,7 @@ it "should be true for incomes under the threshold" do expect(ChildBenefitTaxCalculator.new( adjusted_net_income: "49999", + is_part_year_claim: "yes", children_count: 1, starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" } }, @@ -343,6 +370,7 @@ it "should be true for incomes over the threshold" do expect(ChildBenefitTaxCalculator.new( adjusted_net_income: "50100", + is_part_year_claim: "yes", children_count: 1, starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" } }, @@ -356,6 +384,7 @@ it "calculates the correct amount owed for % charge of 100" do expect(ChildBenefitTaxCalculator.new( adjusted_net_income: "60001", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" } }, }, @@ -367,6 +396,7 @@ expect(ChildBenefitTaxCalculator.new( adjusted_net_income: "59900", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" } }, }, @@ -378,6 +408,7 @@ expect(ChildBenefitTaxCalculator.new( adjusted_net_income: "54000", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" } }, }, @@ -391,6 +422,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "60001", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2013", month: "01", day: "01" } }, }, @@ -402,6 +434,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "59900", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2013", month: "01", day: "01" } }, }, @@ -413,6 +446,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "54000", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2011", month: "01", day: "01" }, @@ -432,6 +466,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "61000", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2013", month: "03", day: "01" }, @@ -447,6 +482,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "61000", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2012", month: "05", day: "01" }, @@ -462,6 +498,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "61000", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2013", month: "02", day: "01" }, @@ -480,6 +517,7 @@ calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "61000", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2014", month: "02", day: "22" }, @@ -499,6 +537,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: 3, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "01", year: "2013" }, @@ -518,7 +557,9 @@ it "should calculate 3 children for 2012/2013 one child starting on 7 Jan 2013" do calc = ChildBenefitTaxCalculator.new( adjusted_net_income: "56000", - year: "2012", children_count: 3, starting_children: { + year: "2012", children_count: 3, + is_part_year_claim: "yes", + starting_children: { "0" => { start: { day: "06", month: "01", year: "2013" }, stop: { day: "05", month: "04", year: "2013" }, @@ -540,6 +581,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2012", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "14", month: "01", year: "2013" }, @@ -553,6 +595,7 @@ adjusted_net_income: "52000", year: "2013", children_count: 3, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2013" }, @@ -576,6 +619,7 @@ adjusted_net_income: "53000", year: "2013", children_count: 3, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2013" }, @@ -599,6 +643,7 @@ adjusted_net_income: "61000", year: "2013", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "01", month: "07", year: "2013" }, @@ -615,6 +660,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2014", children_count: 3, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2014" }, @@ -636,6 +682,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2014", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2014", month: "04", day: "06" }, @@ -649,6 +696,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2014", children_count: 2, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2014" }, @@ -666,6 +714,7 @@ calc = ChildBenefitTaxCalculator.new( year: "2014", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2014" }, @@ -682,6 +731,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2015", children_count: 3, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2015" }, @@ -703,6 +753,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2015", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2015", month: "04", day: "06" }, @@ -716,6 +767,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2015", children_count: 2, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2015" }, @@ -733,6 +785,7 @@ calc = ChildBenefitTaxCalculator.new( year: "2015", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2015" }, @@ -749,6 +802,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2016", children_count: 3, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2016" }, @@ -770,6 +824,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2016", children_count: "1", + is_part_year_claim: "yes", starting_children: { "0" => { start: { year: "2016", month: "04", day: "06" }, @@ -783,6 +838,7 @@ expect(ChildBenefitTaxCalculator.new( year: "2016", children_count: 2, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2016" }, @@ -800,6 +856,7 @@ calc = ChildBenefitTaxCalculator.new( year: "2016", children_count: 1, + is_part_year_claim: "yes", starting_children: { "0" => { start: { day: "06", month: "04", year: "2016" }, From a9e7e9a0fa88e525b040fd53d6d6fbebc2cb6bb1 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Mon, 20 Jun 2016 17:08:24 +0100 Subject: [PATCH 11/22] Add new field for number of part year children This field just displays a drop-down list of numbers. It doesn't do anything with them. --- app/views/child_benefit_tax/main.html.erb | 6 ++++++ spec/features/child_benefit_tax_calculator_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/app/views/child_benefit_tax/main.html.erb b/app/views/child_benefit_tax/main.html.erb index cb7c642c..3f9a5e13 100644 --- a/app/views/child_benefit_tax/main.html.erb +++ b/app/views/child_benefit_tax/main.html.erb @@ -101,6 +101,12 @@ <%= submit_tag "Calculate", :name => "results", :class => "button" %> <% end %>
    - +
    <%= step(3, "Choose a tax claim duration:") %>

    Are you claiming for a part of the tax year for any of your children?

    @@ -110,7 +110,7 @@

    Enter the Child Benefit start and stop dates:

      -
    • the start date is usually when you have a baby, adopt or move in with a new partner and their children
    • +
    • the start date is called an ‘effective date’ - you can find it on your Child Benefit award notice
    • the stop date is usually when a child turns 16 or leaves full-time education
    <%= render "starting_children" %> From fefcdfaf292211ae9be26f705cca1bb5a7b07494 Mon Sep 17 00:00:00 2001 From: Leena Gupte Date: Wed, 17 Aug 2016 14:30:42 +0100 Subject: [PATCH 22/22] Questions, examples and error message copy changes --- app/models/child_benefit_tax_calculator.rb | 2 +- app/views/child_benefit_tax/main.html.erb | 25 +++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/models/child_benefit_tax_calculator.rb b/app/models/child_benefit_tax_calculator.rb index c6ae123e..433f68b5 100644 --- a/app/models/child_benefit_tax_calculator.rb +++ b/app/models/child_benefit_tax_calculator.rb @@ -198,7 +198,7 @@ def valid_child_dates def valid_number_of_children if @is_part_year_claim == 'yes' && (@children_count < @part_year_children_count) - errors.add(:part_year_children_count, "The number of children being claimed cannot exceed the total number of children being claimed for.") + errors.add(:part_year_children_count, "the number of children you're claiming a part year for can't be more than the total number of children you're claiming for") end end diff --git a/app/views/child_benefit_tax/main.html.erb b/app/views/child_benefit_tax/main.html.erb index d5cbf90d..78e48d58 100644 --- a/app/views/child_benefit_tax/main.html.erb +++ b/app/views/child_benefit_tax/main.html.erb @@ -29,14 +29,14 @@ <% end -%>
    - <%= step(1, "Enter the number of children Child Benefit is claimed for:") %> + <%= step(1, "How many children do you want to claim Child Benefit for?") %> <%= select_tag "children_count", options_for_select((1..10).collect{|n| [n,n]}, @calculator.children_count) %> <%= submit_tag "Update", :name => "children", :class => "button update-button" %>
    - <%= step(2, "Choose a tax year:") %> + <%= step(2, "Which tax year are you claiming for?") %>

    Tax years run from 6 April to 5 April the following year.

    <% @calculator.errors[:tax_year].each do |message| %> @@ -52,8 +52,7 @@
    - <%= step(3, "Choose a tax claim duration:") %> -

    Are you claiming for a part of the tax year for any of your children?

    + <%= step(3, "Are you claiming for only a part of the tax year for any of your children?") %>
    <% @calculator.errors[:is_part_year_claim].each do |message| %>

    <%= message %>

    @@ -68,15 +67,15 @@
    - <%= step(4, "Enter income details for the tax year (optional):") %> + <%= step(4, "Enter your income details for the tax year (optional):") %>
    • don’t combine your household income
    • use your partner’s income if it’s higher than yours
    • -
    • you may get some of this information from your P60, P11D, employer or tax adviser
    • +
    • you can get some of this information from your P60, P11D, employer or tax adviser
    <%= label_tag "gross_income", "Salary before tax" %> <%= money_input "gross_income", @adjusted_net_income_calculator.gross_income, 'aria-describedby' => 'step-4-description' %> - <%= label_tag "other_income", "Other employment income - eg taxable benefits (like a company car or medical insurance), bonuses" %> + <%= label_tag "other_income", "Other employment income - for example taxable benefits (like a company car or medical insurance) or bonuses" %> <%= money_input "other_income", @adjusted_net_income_calculator.other_income, 'aria-describedby' => 'step-4-description' %> <%= label_tag "pension_contributions_from_pay", "Pension contributions deducted from your pay (don't include contributions deducted before tax)" %> <%= money_input "pension_contributions_from_pay", @adjusted_net_income_calculator.pension_contributions_from_pay, 'aria-describedby' => 'step-4-description' %> @@ -84,13 +83,13 @@ <%= money_input "retirement_annuities", @adjusted_net_income_calculator.retirement_annuities, 'aria-describedby' => 'step-4-description' %> <%= label_tag "cycle_scheme", "Cycle scheme" %> <%= money_input "cycle_scheme", @adjusted_net_income_calculator.cycle_scheme, 'aria-describedby' => 'step-4-description' %> - <%= label_tag "childcare", "Childcare paid directly by your employer - eg childcare vouchers (for the whole year but no more than £55 a week), the value of any workplace nursery places" %> + <%= label_tag "childcare", "Childcare paid directly by your employer - for example childcare vouchers (for the whole year but no more than £55 a week) or the value of any workplace nursery places" %> <%= money_input "childcare", @adjusted_net_income_calculator.childcare, 'aria-describedby' => 'step-4-description' %> - <%= label_tag "pensions", "Income from pension(s) - eg from a state pension" %> + <%= label_tag "pensions", "Income from pension(s) - for example from a state pension" %> <%= money_input "pensions", @adjusted_net_income_calculator.pensions, 'aria-describedby' => 'step-4-description' %> - <%= label_tag "property", "Income from property - eg rental income" %> + <%= label_tag "property", "Income from property - for example rental income" %> <%= money_input "property", @adjusted_net_income_calculator.property, 'aria-describedby' => 'step-4-description' %> - <%= label_tag "non_employment_income", "Other income before tax - eg profits from self-employment, taxable savings, dividends" %> + <%= label_tag "non_employment_income", "Other income before tax - for example profits from self-employment, taxable savings, dividends" %> <%= money_input "non_employment_income", @adjusted_net_income_calculator.non_employment_income, 'aria-describedby' => 'step-4-description' %> <%= label_tag "gift_aid_donations", "Gift Aid donations" %> <%= money_input "gift_aid_donations", @adjusted_net_income_calculator.gift_aid_donations, 'aria-describedby' => 'step-4-description' %> @@ -102,7 +101,7 @@ <% end %>