mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 07:48:50 +01:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
59989d3127
9 changed files with 211 additions and 200 deletions
|
|
@ -3,152 +3,32 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
|||
class ContextActionsDataTest < ActionController::TestCase
|
||||
tests StatsController
|
||||
|
||||
def test_total_with_0_items
|
||||
login_as(:admin_user)
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns []
|
||||
|
||||
get :context_total_actions_data
|
||||
|
||||
assert_equal [], assigns[:actions_per_context]
|
||||
end
|
||||
|
||||
def test_total_with_less_than_10_items
|
||||
login_as(:admin_user)
|
||||
contexts = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6}
|
||||
]
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns contexts
|
||||
|
||||
get :context_total_actions_data
|
||||
|
||||
assert_equal contexts, assigns[:actions_per_context]
|
||||
end
|
||||
|
||||
def test_total_with_exactly_10_items
|
||||
login_as(:admin_user)
|
||||
contexts = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6},
|
||||
{'id' => 10, 'name' => 'ten', 'total' => 19}
|
||||
]
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns contexts
|
||||
|
||||
get :context_total_actions_data
|
||||
|
||||
assert_equal contexts, assigns[:actions_per_context]
|
||||
end
|
||||
|
||||
def test_total_with_more_than_10_items
|
||||
login_as(:admin_user)
|
||||
contexts = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6},
|
||||
{'id' => 10, 'name' => 'ten', 'total' => 19},
|
||||
{'id' => 11, 'name' => 'eleven', 'total' => 14}
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8}
|
||||
]
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns contexts
|
||||
|
||||
get :context_total_actions_data
|
||||
|
||||
contexts.pop
|
||||
contexts[-1] = {'id' => -1, 'name' => '(others)', 'total' => 33}
|
||||
assert_equal contexts, assigns[:actions_per_context]
|
||||
assert_equal [47, 17, 34], assigns[:data].values
|
||||
end
|
||||
|
||||
def test_running_with_0_items
|
||||
login_as(:admin_user)
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns []
|
||||
|
||||
get :context_running_actions_data
|
||||
|
||||
assert_equal [], assigns[:actions_per_context]
|
||||
end
|
||||
|
||||
def test_running_with_less_than_10_items
|
||||
def test_running_actions
|
||||
login_as(:admin_user)
|
||||
contexts = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6}
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8}
|
||||
]
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns contexts
|
||||
|
||||
get :context_running_actions_data
|
||||
|
||||
assert_equal contexts, assigns[:actions_per_context]
|
||||
end
|
||||
|
||||
def test_running_with_exactly_10_items
|
||||
login_as(:admin_user)
|
||||
contexts = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6},
|
||||
{'id' => 10, 'name' => 'ten', 'total' => 19}
|
||||
]
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns contexts
|
||||
|
||||
get :context_running_actions_data
|
||||
|
||||
assert_equal contexts, assigns[:actions_per_context]
|
||||
end
|
||||
|
||||
def test_running_with_more_than_10_items
|
||||
login_as(:admin_user)
|
||||
contexts = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6},
|
||||
{'id' => 10, 'name' => 'ten', 'total' => 19},
|
||||
{'id' => 11, 'name' => 'eleven', 'total' => 14}
|
||||
]
|
||||
Stats::TopContextsQuery.any_instance.stubs(:result).returns contexts
|
||||
|
||||
get :context_running_actions_data
|
||||
|
||||
contexts.pop
|
||||
contexts[-1] = {'id' => -1, 'name' => '(others)', 'total' => 33}
|
||||
assert_equal contexts, assigns[:actions_per_context]
|
||||
assert_equal [47, 17, 34], assigns[:data].values
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,12 +26,19 @@ class StatsControllerTest < ActionController::TestCase
|
|||
actions_day_of_week_30days_data
|
||||
actions_time_of_day_all_data
|
||||
actions_time_of_day_30days_data
|
||||
}.each do |action|
|
||||
get action
|
||||
assert_response :success
|
||||
assert_template "stats/"+action
|
||||
end
|
||||
|
||||
%w{
|
||||
context_total_actions_data
|
||||
context_running_actions_data
|
||||
}.each do |action|
|
||||
get action
|
||||
assert_response :success
|
||||
assert_template "stats/"+action
|
||||
assert_template "stats/pie_chart_data"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -262,8 +269,8 @@ class StatsControllerTest < ActionController::TestCase
|
|||
get :context_total_actions_data
|
||||
assert_response :success
|
||||
|
||||
assert_equal 9, assigns['sum'], "Nine todos in 1 context"
|
||||
assert_equal 1, assigns['actions_per_context'].size
|
||||
assert_equal 9, assigns['data'].sum, "Nine todos in 1 context"
|
||||
assert_equal 1, assigns['data'].values.size
|
||||
|
||||
# Given 10 more todos in 10 different contexts
|
||||
1.upto(10) do |i|
|
||||
|
|
@ -275,10 +282,10 @@ class StatsControllerTest < ActionController::TestCase
|
|||
get :context_total_actions_data
|
||||
assert_response :success
|
||||
|
||||
assert_equal 19, assigns['sum'], "added 10 todos"
|
||||
assert_equal 10, assigns['actions_per_context'].size, "pie slices limited to max 10"
|
||||
assert_equal 2, assigns['actions_per_context'][9]['total'], "pie slices limited to max 10; last pie contains sum of rest"
|
||||
assert_equal "(others)", assigns['actions_per_context'][9]['name'], "pie slices limited to max 10; last slice contains label for others"
|
||||
assert_equal 19, assigns['data'].sum, "added 10 todos"
|
||||
assert_equal 10, assigns['data'].values.size, "pie slices limited to max 10"
|
||||
assert_equal 10, assigns['data'].values[9], "pie slices limited to max 10; last pie contains sum of rest (in percentage)"
|
||||
assert_equal "(others)", assigns['data'].labels[9], "pie slices limited to max 10; last slice contains label for others"
|
||||
end
|
||||
|
||||
def test_context_running_actions_data
|
||||
|
|
@ -292,8 +299,8 @@ class StatsControllerTest < ActionController::TestCase
|
|||
get :context_running_actions_data
|
||||
assert_response :success
|
||||
|
||||
assert_equal 4, assigns['sum'], "Four running todos in 1 context"
|
||||
assert_equal 1, assigns['actions_per_context'].size
|
||||
assert_equal 4, assigns['data'].sum, "Four todos in 1 context"
|
||||
assert_equal 1, assigns['data'].values.size
|
||||
|
||||
# Given 10 more todos in 10 different contexts
|
||||
1.upto(10) do |i|
|
||||
|
|
@ -305,10 +312,9 @@ class StatsControllerTest < ActionController::TestCase
|
|||
get :context_running_actions_data
|
||||
assert_response :success
|
||||
|
||||
assert_equal 14, assigns['sum'], "added 10 todos"
|
||||
assert_equal 10, assigns['actions_per_context'].size, "pie slices limited to max 10"
|
||||
assert_equal 2, assigns['actions_per_context'][9]['total'], "pie slices limited to max 10; last pie contains sum of rest"
|
||||
assert_equal "(others)", assigns['actions_per_context'][9]['name'], "pie slices limited to max 10; last slice contains label for others"
|
||||
assert_equal 10, assigns['data'].values.size, "pie slices limited to max 10"
|
||||
assert_equal 14, assigns['data'].values[9], "pie slices limited to max 10; last pie contains sum of rest (in percentage)"
|
||||
assert_equal "(others)", assigns['data'].labels[9], "pie slices limited to max 10; last slice contains label for others"
|
||||
end
|
||||
|
||||
def test_actions_day_of_week_all_data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue