Commit 1c08281cf046bc42f48f9d92d2d4fc4d33d52d4a

Authored by Diego Camarinha
Committed by Diego Camarinha
1 parent 761f8ad3

[Mezuro] Content helper tests.

plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
@@ -7,7 +7,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper @@ -7,7 +7,7 @@ class MezuroPlugin::Helpers::ContentViewerHelper
7 end 7 end
8 8
9 def self.periodicity_options 9 def self.periodicity_options
10 - [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] 10 + [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweekly", 15], ["Monthly", 30]]
11 end 11 end
12 12
13 def self.periodicity_option(periodicity) 13 def self.periodicity_option(periodicity)
@@ -47,9 +47,9 @@ class MezuroPlugin::Helpers::ContentViewerHelper @@ -47,9 +47,9 @@ class MezuroPlugin::Helpers::ContentViewerHelper
47 metric_configuration_snapshot.metric.name.delete("() ") 47 metric_configuration_snapshot.metric.name.delete("() ")
48 end 48 end
49 49
50 - def self.format_time(time)  
51 - time /= 1000 # transform miliseconds to seconds  
52 - MezuroPluginModuleResultController.helpers.distance_of_time_in_words(0, time, include_seconds = true) 50 + def self.format_time(miliseconds)
  51 + seconds = miliseconds/1000
  52 + MezuroPluginModuleResultController.helpers.distance_of_time_in_words(0, seconds, include_seconds = true)
53 end 53 end
54 54
55 private 55 private
plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb
@@ -21,4 +21,13 @@ class DateMetricResultFixtures @@ -21,4 +21,13 @@ class DateMetricResultFixtures
21 } 21 }
22 end 22 end
23 23
  24 + def self.score_history
  25 + result = []
  26 + result << date_metric_result
  27 + newer_date_metric_result = date_metric_result
  28 + newer_date_metric_result.date = '2011-10-25T18:26:43.151+00:00'
  29 + newer_date_metric_result.metric_result.value = 5.0
  30 + result << newer_date_metric_result
  31 + end
  32 +
24 end 33 end
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
1 require "test_helper" 1 require "test_helper"
2 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures" 2 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures"
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
3 4
4 class ContentViewerHelperTest < ActiveSupport::TestCase 5 class ContentViewerHelperTest < ActiveSupport::TestCase
5 6
  7 + def setup
  8 + @helper = MezuroPlugin::Helpers::ContentViewerHelper
  9 + end
  10 +
6 should 'get the number rounded by two decimal points' do 11 should 'get the number rounded by two decimal points' do
7 - assert_equal '4.22', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.22344')  
8 - assert_equal '4.10', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.1')  
9 - assert_equal '4.00', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4') 12 + assert_equal '4.22', @helper.format_grade('4.22344')
  13 + assert_equal '4.10', @helper.format_grade('4.1')
  14 + assert_equal '4.00', @helper.format_grade('4')
10 end 15 end
11 16
12 should 'create the periodicity options array' do 17 should 'create the periodicity options array' do
13 - assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.periodicity_options 18 + assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweekly", 15], ["Monthly", 30]], @helper.periodicity_options
  19 + end
  20 +
  21 + should 'return the correct string for a given periodicity' do
  22 + assert_equal "Not Periodically", @helper.periodicity_option(0)
  23 + assert_equal "1 day", @helper.periodicity_option(1)
  24 + assert_equal "2 days", @helper.periodicity_option(2)
  25 + assert_equal "Weekly", @helper.periodicity_option(7)
  26 + assert_equal "Biweekly", @helper.periodicity_option(15)
  27 + assert_equal "Monthly", @helper.periodicity_option(30)
  28 + end
  29 +
  30 + should 'create the license options array' do
  31 + options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yml")
  32 + options = options.split(";")
  33 + formated_options = []
  34 + options.each { |option| formated_options << [option, option] }
  35 + assert_equal formated_options, @helper.license_options
14 end 36 end
15 37
  38 + should 'generate chart from metric result history' do
  39 + chart = "http://chart.apis.google.com/chart?chxt=y,x&chco=c4a000&chf=bg,ls,90,efefef,0.2,ffffff,0.2&chd=s:A9&chl=2011-10-20T18%3A26%3A43%2B00%3A00|2011-10-25T18%3A26%3A43%2B00%3A00&cht=lc&chs=600x180&chxr=0,0.0,5.0"
  40 + metric_history = DateMetricResultFixtures.score_history
  41 +
  42 + assert_equal chart, @helper.generate_chart(metric_history)
  43 + end
  44 +
  45 + should 'format time to show a sentence' do
  46 + assert_equal 'less than 5 seconds', @helper.format_time(0)
  47 + assert_equal 'less than 5 seconds', @helper.format_time(4999)
  48 + assert_equal 'less than 10 seconds', @helper.format_time(5000)
  49 + assert_equal '1 minute', @helper.format_time(70000)
  50 + assert_equal 'about 2 hours', @helper.format_time(7000000)
  51 + end
  52 +
16 should 'format metric name for metric configuration snapshot' do 53 should 'format metric name for metric configuration snapshot' do
17 metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot 54 metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot
18 - assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_configuration_snapshot) 55 + assert_equal 'AverageMethodLOC', @helper.format_name(metric_configuration_snapshot)
19 end 56 end
20 57
21 end 58 end