Browse Source

Log status on log (#410)

* Fix link to next incomplete section

* Update status of log on log page

* Remove TasklistController as no longer required

* Add missing quotes around HTML attribute

* Add additional spec for tasklist page

* Capybara does not enjoy setting focus

Co-authored-by: Paul Robert Lloyd <me+git@paulrobertlloyd.com>
pull/414/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
79e6fd42c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/frontend/controllers/index.js
  2. 8
      app/frontend/controllers/tasklist_controller.js
  3. 2
      app/views/case_logs/_tasklist.html.erb
  4. 17
      app/views/case_logs/edit.html.erb
  5. 13
      spec/features/form/tasklist_page_spec.rb

3
app/frontend/controllers/index.js

@ -14,6 +14,3 @@ application.register("govukfrontend", GovukfrontendController)
import NumericQuestionController from "./numeric_question_controller.js" import NumericQuestionController from "./numeric_question_controller.js"
application.register("numeric-question", NumericQuestionController) application.register("numeric-question", NumericQuestionController)
import TasklistController from "./tasklist_controller.js"
application.register("tasklist", TasklistController)

8
app/frontend/controllers/tasklist_controller.js

@ -1,8 +0,0 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
addHighlight() {
let section_to_highlight = this.element.dataset.info;
document.getElementById(section_to_highlight).classList.add('tasklist_item_highlight');
}
}

2
app/views/case_logs/_tasklist.html.erb

@ -15,7 +15,7 @@
<%= subsection_link(subsection, @case_log) %> <%= subsection_link(subsection, @case_log) %>
</span> </span>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>" <strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>"
id=<%= subsection.id.dasherize %>> id="<%= subsection.id.dasherize %>">
<%= TasklistHelper::STATUSES[subsection_status] %> <%= TasklistHelper::STATUSES[subsection_status] %>
</strong> </strong>
</li> </li>

17
app/views/case_logs/edit.html.erb

@ -11,25 +11,22 @@
<%= content_for(:title) %> <%= content_for(:title) %>
</h1> </h1>
<h2 class="govuk-heading-s govuk-!-margin-bottom-2"> <% if @case_log.status == "in_progress" %>
This log is <p class="govuk-body govuk-!-margin-bottom-7"><%= get_subsections_count(@case_log, :completed) %> of <%= get_subsections_count(@case_log, :all) %> sections completed.</p>
<%= @case_log.status.to_s.humanize.downcase %>
</h2>
<p class="govuk-body govuk-!-margin-bottom-7">You have completed <%= get_subsections_count(@case_log, :completed) %> of <%= get_subsections_count(@case_log, :all) %> sections.</p>
<p class="govuk-body govuk-!-margin-bottom-2"> <p class="govuk-body govuk-!-margin-bottom-2">
<% next_incomplete_section = get_next_incomplete_section(@case_log) %> <% next_incomplete_section = get_next_incomplete_section(@case_log) %>
</p> </p>
<p> <p>
<% if next_incomplete_section.present? %> <% if next_incomplete_section.present? %>
<a class="app-section-skip-link" href="#<%= next_incomplete_section.id %>" <a class="app-section-skip-link" href="#<%= next_incomplete_section.id.dasherize %>">
data-controller="tasklist"
data-action="tasklist#addHighlight"
data-info=<%= next_incomplete_section.id %>>
Skip to next incomplete section: <%= next_incomplete_section.label %> Skip to next incomplete section: <%= next_incomplete_section.label %>
</a> </a>
<% end %> <% end %>
</p> </p>
<% elsif @case_log.status == "not_started" %>
<p class="govuk-body">This log has not been started.</p>
<% end %>
<%= render "tasklist" %> <%= render "tasklist" %>
</div> </div>
</div> </div>

13
spec/features/form/tasklist_page_spec.rb

@ -26,19 +26,20 @@ RSpec.describe "Task List" do
sign_in user sign_in user
end end
it "skips to the first section if no answers are completed" do it "shows if the section has not been started" do
visit("/logs/#{empty_case_log.id}") visit("/logs/#{empty_case_log.id}")
expect(page).to have_link("Skip to next incomplete section", href: /#household_characteristics/) expect(page).to have_content("This log has not been started.")
end end
it "shows the number of completed sections if no sections are completed" do it "shows number of completed sections if one section is completed" do
answer_all_questions_in_income_subsection(empty_case_log)
visit("/logs/#{empty_case_log.id}") visit("/logs/#{empty_case_log.id}")
expect(page).to have_content("You have completed 0 of 9 sections.") expect(page).to have_content("1 of 9 sections completed.")
end end
it "shows the number of completed sections if one section is completed" do it "show skip link for next incomplete section" do
answer_all_questions_in_income_subsection(empty_case_log) answer_all_questions_in_income_subsection(empty_case_log)
visit("/logs/#{empty_case_log.id}") visit("/logs/#{empty_case_log.id}")
expect(page).to have_content("You have completed 1 of 9 sections.") expect(page).to have_link("Skip to next incomplete section", href: /#household-characteristics/)
end end
end end

Loading…
Cancel
Save