diff --git a/app/views/logs/edit.html.erb b/app/views/logs/edit.html.erb index 1be928656..2737fc50b 100644 --- a/app/views/logs/edit.html.erb +++ b/app/views/logs/edit.html.erb @@ -11,7 +11,7 @@ <% if @log.status == "in_progress" %> -
<%= get_subsections_count(@log, :completed) %> of <%= get_subsections_count(@log, :all) %> subsections completed.
+<%= get_subsections_count(@log, :completed) %> of <%= get_subsections_count(@log) %> subsections completed.
<% next_incomplete_section = get_next_incomplete_section(@log) %>
diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index bd1bdb61f..e67c34650 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -27,26 +27,30 @@ RSpec.describe TasklistHelper do end describe "get sections count" do - let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } + let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json") } before do - allow(FormHandler.instance).to receive(:get_form).and_return(fake_2021_2022_form) + allow(FormHandler.instance).to receive(:get_form).and_return(real_2021_2022_form) end - it "returns the total of sections if no status is given" do - expect(get_subsections_count(empty_lettings_log)).to eq(8) - end + context "with an empty lettings log" do + it "returns the total displayed subsections count if no status is given" do + expect(get_subsections_count(empty_lettings_log)).to eq(7) + end - it "returns 0 sections for completed sections if no sections are completed" do - expect(get_subsections_count(empty_lettings_log, :completed)).to eq(0) + it "returns 0 sections for completed sections if no sections are completed" do + expect(get_subsections_count(empty_lettings_log, :completed)).to eq(0) + end end - it "returns the number of not started sections" do - expect(get_subsections_count(empty_lettings_log, :not_started)).to eq(8) - end + context "with a partially complete lettings log" do + it "returns the total displayed subsections count if no status is given" do + expect(get_subsections_count(lettings_log)).to eq(7) + end - it "returns the number of sections in progress" do - expect(get_subsections_count(lettings_log, :in_progress)).to eq(2) + it "returns the completed sections count" do + expect(get_subsections_count(lettings_log, :completed)).to eq(1) + end end it "returns 0 for invalid state" do @@ -77,6 +81,37 @@ RSpec.describe TasklistHelper do end end + describe "with sales" do + let(:empty_sales_log) { create(:sales_log, owning_organisation: nil) } + let(:completed_sales_log) { build(:sales_log, :completed) } + + describe "get sections count" do + context "with an empty sales log" do + it "returns the total displayed subsections count if no status is given (includes all 3 sale information subsections)" do + expect(get_subsections_count(empty_sales_log)).to eq(9) + end + + it "returns 0 sections for completed sections if no sections are completed" do + expect(get_subsections_count(empty_sales_log, :completed)).to eq(0) + end + end + + context "with a completed sales log" do + it "returns the total displayed subsections count if no status is given (includes only the 1 relevant sale information subsection)" do + expect(get_subsections_count(completed_sales_log)).to eq(7) + end + + it "returns the completed sections count" do + expect(get_subsections_count(completed_sales_log, :completed)).to eq(7) + end + end + + it "returns 0 for invalid state" do + expect(get_subsections_count(completed_sales_log, :fake)).to eq(0) + end + end + + end describe "#review_log_text" do context "with sales log" do context "when collection_period_open? == true" do