diff --git a/app/helpers/maintenance_tasks/tasks_helper.rb b/app/helpers/maintenance_tasks/tasks_helper.rb index a0c8307d..c408b6df 100644 --- a/app/helpers/maintenance_tasks/tasks_helper.rb +++ b/app/helpers/maintenance_tasks/tasks_helper.rb @@ -44,12 +44,13 @@ def progress(run) progress = Progress.new(run) - tag.progress( + progress_bar = tag.progress( value: progress.value, max: progress.max, - title: progress.title, class: ["progress"] + STATUS_COLOURS.fetch(run.status) ) + progress_text = tag.p(tag.i(progress.text)) + tag.div(progress_bar + progress_text, class: "block") end # Renders a span with a Run's status, with the corresponding tag class diff --git a/app/models/maintenance_tasks/progress.rb b/app/models/maintenance_tasks/progress.rb index 0b312bb2..11d7c6d1 100644 --- a/app/models/maintenance_tasks/progress.rb +++ b/app/models/maintenance_tasks/progress.rb @@ -4,6 +4,7 @@ module MaintenanceTasks # This class generates progress information about a Run. class Progress include ActiveSupport::NumberHelper + include ActionView::Helpers::TextHelper # Sets the Progress initial state with a Run. # @@ -41,22 +42,23 @@ def max estimatable? ? @run.tick_total : @run.tick_count end - # The title for the progress information. This is a text that describes the - # progress of the Run so far. It includes the percentage that is done out of - # the maximum, if an estimate is possible. + # The text containing progress information. This describes the progress of + # the Run so far. It includes the percentage done out of the maximum, if an + # estimate is possible. # - # @return [String] the title for the Run progress. - def title + # @return [String] the text for the Run progress. + def text + count = @run.tick_count + total = @run.tick_total if !total? - "Processed #{@run.tick_count} #{'item'.pluralize(@run.tick_count)}." + "Processed #{pluralize(count, 'item')}." elsif over_total? - "Processed #{@run.tick_count} #{'item'.pluralize(@run.tick_count)} " \ - "(expected #{@run.tick_total})." + "Processed #{pluralize(count, 'item')} (expected #{total})." else - percentage = 100.0 * @run.tick_count / @run.tick_total + percentage = 100.0 * count / total - "Processed #{@run.tick_count} out of #{@run.tick_total} "\ - "(#{number_to_percentage(percentage, precision: 0)})" + "Processed #{count} out of #{pluralize(total, 'item')} "\ + "(#{number_to_percentage(percentage, precision: 0)})." end end diff --git a/app/views/maintenance_tasks/runs/info/_running.html.erb b/app/views/maintenance_tasks/runs/info/_running.html.erb index 81776c4d..5de17136 100644 --- a/app/views/maintenance_tasks/runs/info/_running.html.erb +++ b/app/views/maintenance_tasks/runs/info/_running.html.erb @@ -1,7 +1,5 @@

<% if run.estimated_completion_time %> <%= estimated_time_to_completion(run).capitalize %> remaining. - <% else %> - Processed <%= pluralize run.tick_count, 'item' %> so far. <% end %>

diff --git a/test/helpers/maintenance_tasks/tasks_helper_test.rb b/test/helpers/maintenance_tasks/tasks_helper_test.rb index 1899d010..bdf983b6 100644 --- a/test/helpers/maintenance_tasks/tasks_helper_test.rb +++ b/test/helpers/maintenance_tasks/tasks_helper_test.rb @@ -20,15 +20,16 @@ class TasksHelperTest < ActionView::TestCase assert_equal expected_trace, format_backtrace(backtrace) end - test "#progress renders a when Run has started" do + test "#progress returns a
with a and progress text when Run has started" do @run.started_at = Time.now Progress.expects(:new).with(@run).returns( - mock(value: 42, max: 84, title: "Almost there!") + mock(value: 42, max: 84, text: "Almost there!") ) - expected = '' + expected = '
'\ + "

Almost there!

" assert_equal expected, progress(@run) end @@ -36,13 +37,15 @@ class TasksHelperTest < ActionView::TestCase assert_nil progress(@run) end - test "#progress returns a with no value when the Progress value is nil" do + test "#progress returns a a
with a with no value when the Progress value is nil" do @run.started_at = Time.now Progress.expects(:new).with(@run).returns( - mock(value: nil, max: 84, title: "Almost there!") + mock(value: nil, max: 84, text: "Almost there!") ) - expected = '' + + expected = '
'\ + "

Almost there!

" assert_equal expected, progress(@run) end diff --git a/test/models/maintenance_tasks/progress_test.rb b/test/models/maintenance_tasks/progress_test.rb index d9fcc870..130559fa 100644 --- a/test/models/maintenance_tasks/progress_test.rb +++ b/test/models/maintenance_tasks/progress_test.rb @@ -47,24 +47,24 @@ class ProgressTest < ActiveSupport::TestCase assert_equal 8, @progress.max end - test "#title returns a description with tick count, tick total, and percentage" do - assert_equal "Processed 4 out of 7 (57%)", @progress.title + test "#text returns a description with tick count, tick total, and percentage" do + assert_equal "Processed 4 out of 7 items (57%).", @progress.text end - test "#title returns a description with tick count when tick total is not present" do + test "#text returns a description with tick count when tick total is not present" do @run.tick_total = nil - assert_equal "Processed 4 items.", @progress.title + assert_equal "Processed 4 items.", @progress.text end - test "#title returns a description with tick count and tick total when tick count is greater than its tick total" do + test "#text returns a description with tick count and tick total when tick count is greater than its tick total" do @run.tick_count = 8 - assert_equal "Processed 8 items (expected 7).", @progress.title + assert_equal "Processed 8 items (expected 7).", @progress.text end - test "#title pluralizes the description according to the tick count" do + test "#text pluralizes the description according to the tick count" do @run.tick_count = 1 @run.tick_total = nil - assert_equal "Processed 1 item.", @progress.title + assert_equal "Processed 1 item.", @progress.text end end end