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. 33
      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"
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) %>
</span>
<strong class="govuk-tag app-task-list__tag <%= TasklistHelper::STYLES[subsection_status] %>"
id=<%= subsection.id.dasherize %>>
id="<%= subsection.id.dasherize %>">
<%= TasklistHelper::STATUSES[subsection_status] %>
</strong>
</li>

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

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

13
spec/features/form/tasklist_page_spec.rb

@ -26,19 +26,20 @@ RSpec.describe "Task List" do
sign_in user
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}")
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
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}")
expect(page).to have_content("You have completed 0 of 9 sections.")
expect(page).to have_content("1 of 9 sections completed.")
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)
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

Loading…
Cancel
Save