@@ -121,5 +121,59 @@ class RedundancyCalculatorTest < ActiveSupport::TestCase
121
121
assert_equal 17.5 , @calculator . number_of_weeks_entitlement
122
122
end
123
123
end
124
+
125
+ context "Redundancy date selector" do
126
+ context "Earliest selectable date" do
127
+ context "Months January to August" do
128
+ should "return the start of the year, four years ago if date is January 1st" do
129
+ Timecop . freeze ( '2016-01-01' )
130
+ assert_equal Date . parse ( '2012-01-01' ) , RedundancyCalculator . first_selectable_date
131
+ end
132
+
133
+ should "return the start of the year, four years ago if date is August 31st" do
134
+ Timecop . freeze ( '2016-08-31' )
135
+ assert_equal Date . parse ( '2012-01-01' ) , RedundancyCalculator . first_selectable_date
136
+ end
137
+ end
138
+
139
+ context "Months September to December" do
140
+ should "return the start of the year, three years ago if date is September 1st" do
141
+ Timecop . freeze ( '2016-09-01' )
142
+ assert_equal Date . parse ( '2013-01-01' ) , RedundancyCalculator . first_selectable_date
143
+ end
144
+
145
+ should "return the start of the year, three years ago if date is December 31st" do
146
+ Timecop . freeze ( '2016-12-31' )
147
+ assert_equal Date . parse ( '2013-01-01' ) , RedundancyCalculator . first_selectable_date
148
+ end
149
+ end
150
+ end
151
+
152
+ context "Last selectable date" do
153
+ context "Months January to August" do
154
+ should "return the end of the current year if the date is January 1st" do
155
+ Timecop . freeze ( '2016-01-01' )
156
+ assert_equal Date . parse ( '2016-12-31' ) , RedundancyCalculator . last_selectable_date
157
+ end
158
+
159
+ should "return the end of the current year if the date is August 31st" do
160
+ Timecop . freeze ( '2016-08-31' )
161
+ assert_equal Date . parse ( '2016-12-31' ) , RedundancyCalculator . last_selectable_date
162
+ end
163
+ end
164
+
165
+ context "Months September to December" do
166
+ should "return end of the next year if the date is September 1st" do
167
+ Timecop . freeze ( '2016-09-01' )
168
+ assert_equal Date . parse ( '2017-12-31' ) , RedundancyCalculator . last_selectable_date
169
+ end
170
+
171
+ should "return end of the next year if the date is December 31st" do
172
+ Timecop . freeze ( '2016-12-31' )
173
+ assert_equal Date . parse ( '2017-12-31' ) , RedundancyCalculator . last_selectable_date
174
+ end
175
+ end
176
+ end
177
+ end
124
178
end
125
179
end
0 commit comments