|  |  | @ -1,12 +1,15 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | require "rails_helper" |  |  |  | require "rails_helper" | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | RSpec.describe TasklistHelper do |  |  |  | RSpec.describe TasklistHelper do | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   let!(:empty_case_log) { FactoryBot.create(:case_log) } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   let!(:case_log) { FactoryBot.create(:case_log, :in_progress) } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   let(:form) { Form.new(2021, 2022) } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   describe "get subsection status" do |  |  |  |   describe "get subsection status" do | 
			
		
	
		
		
			
				
					
					|  |  |  |     @form = Form.new(2021, 2022) |  |  |  |     let(:section) { "income_and_benefits" } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     income_and_benefits_questions = @form.questions_for_subsection("income_and_benefits").keys |  |  |  |     let(:income_and_benefits_questions) { form.questions_for_subsection("income_and_benefits").keys } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     declaration_questions = @form.questions_for_subsection("declaration").keys |  |  |  |     let(:declaration_questions) { form.questions_for_subsection("declaration").keys } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     local_authority_questions = @form.questions_for_subsection("local_authority").keys |  |  |  |     let(:local_authority_questions) { form.questions_for_subsection("local_authority").keys } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     let!(:case_log) { FactoryBot.create(:case_log) } |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns not started if none of the questions in the subsection are answered" do |  |  |  |     it "returns not started if none of the questions in the subsection are answered" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions) |  |  |  |       status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions) | 
			
		
	
	
		
		
			
				
					|  |  | @ -38,47 +41,47 @@ RSpec.describe TasklistHelper do | 
			
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   describe "get next incomplete section" do |  |  |  |   describe "get next incomplete section" do | 
			
		
	
		
		
			
				
					
					|  |  |  |     let!(:case_log) { FactoryBot.create(:case_log) } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns the first subsection name if it is not completed" do |  |  |  |     it "returns the first subsection name if it is not completed" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |       expect(get_next_incomplete_section(form, case_log)).to eq("household_characteristics") | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics") |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns the first subsection name if it is partially completed" do |  |  |  |     it "returns the first subsection name if it is partially completed" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       case_log["tenant_code"] = 123 |  |  |  |       case_log["tenant_code"] = 123 | 
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_next_incomplete_section(@form, case_log)).to eq("household_characteristics") |  |  |  |       expect(get_next_incomplete_section(form, case_log)).to eq("household_characteristics") | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   describe "get sections count" do |  |  |  |   describe "get sections count" do | 
			
		
	
		
		
			
				
					
					|  |  |  |     let!(:empty_case_log) { FactoryBot.create(:case_log) } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     let!(:case_log) { FactoryBot.create(:case_log, :in_progress) } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns the total of sections if no status is given" do |  |  |  |     it "returns the total of sections if no status is given" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |       expect(get_sections_count(form, empty_case_log)).to eq(9) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_sections_count(@form, empty_case_log)).to eq(9) |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns 0 sections for completed sections if no sections are completed" do |  |  |  |     it "returns 0 sections for completed sections if no sections are completed" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |       expect(get_sections_count(form, empty_case_log, :completed)).to eq(0) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_sections_count(@form, empty_case_log, :completed)).to eq(0) |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns the number of not started sections" do |  |  |  |     it "returns the number of not started sections" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |       expect(get_sections_count(form, empty_case_log, :not_started)).to eq(8) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_sections_count(@form, empty_case_log, :not_started)).to eq(8) |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns the number of sections in progress" do |  |  |  |     it "returns the number of sections in progress" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |       expect(get_sections_count(form, case_log, :in_progress)).to eq(3) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_sections_count(@form, case_log, :in_progress)).to eq(3) |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     it "returns 0 for invalid state" do |  |  |  |     it "returns 0 for invalid state" do | 
			
		
	
		
		
			
				
					
					|  |  |  |       @form = Form.new(2021, 2022) |  |  |  |       expect(get_sections_count(form, case_log, :fake)).to eq(0) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       expect(get_sections_count(@form, case_log, :fake)).to eq(0) |  |  |  |     end | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   describe "get_first_page_or_check_answers" do | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     let(:household_characteristics_questions) { form.questions_for_subsection("household_characteristics").keys } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     it "returns the check answers page path if the section has been started already" do | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       expect(get_first_page_or_check_answers("household_characteristics", case_log, form, household_characteristics_questions)).to match(/check_answers/) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     it "returns the first question page path for the section if it has not been started yet" do | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       expect(get_first_page_or_check_answers("household_characteristics", empty_case_log, form, household_characteristics_questions)).to match(/tenant_code/) | 
			
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  |     end | 
			
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | end |  |  |  | end | 
			
		
	
	
		
		
			
				
					|  |  | 
 |