Skip to content

Commit 6a8a5f9

Browse files
feat: adding specs and improving ux
1 parent 3025376 commit 6a8a5f9

File tree

2 files changed

+126
-9
lines changed

2 files changed

+126
-9
lines changed

app/helpers/mission_control/jobs/interface_helper.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ def blank_status_emoji(status)
1212

1313
def jobs_count_for(status)
1414
count = ActiveJob.jobs.with_status(status).count
15+
value = count.infinite? ? MissionControl::Jobs.count_limit : count
16+
suffix = count.infinite? ? "+" : ""
1517

16-
number_to_human(count,
17-
format: "%n%u",
18-
units: {
19-
thousand: "K",
20-
million: "M",
21-
billion: "B",
22-
trillion: "T",
23-
quadrillion: "Q"
24-
})
18+
units = { thousand: "K", million: "M", billion: "B", trillion: "T", quadrillion: "Q" }
19+
20+
number_to_human(value, format: "%n%u", units: units) + suffix
2521
end
2622

2723
def modifier_for_status(status)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
require "test_helper"
2+
3+
class MissionControl::Jobs::InterfaceHelperTest < ActionView::TestCase
4+
include MissionControl::Jobs::InterfaceHelper
5+
6+
test "jobs_count_for returns formatted count for finite numbers" do
7+
# Mock the ActiveJob.jobs chain
8+
mock_with_status = Minitest::Mock.new
9+
mock_count = Minitest::Mock.new
10+
11+
ActiveJob.stub :jobs, mock_with_status do
12+
mock_with_status.expect :with_status, mock_count, [ :failed ]
13+
mock_count.expect :count, 1000
14+
15+
result = jobs_count_for(:failed)
16+
assert_equal "1K", result
17+
18+
mock_with_status.verify
19+
mock_count.verify
20+
end
21+
end
22+
23+
test "jobs_count_for returns formatted count with plus suffix for infinite count" do
24+
# Mock the ActiveJob.jobs chain for infinite count
25+
mock_with_status = Minitest::Mock.new
26+
mock_count = Minitest::Mock.new
27+
28+
ActiveJob.stub :jobs, mock_with_status do
29+
mock_with_status.expect :with_status, mock_count, [ :failed ]
30+
mock_count.expect :count, Float::INFINITY
31+
32+
result = jobs_count_for(:failed)
33+
expected = number_to_human(MissionControl::Jobs.count_limit,
34+
format: "%n%u",
35+
units: { thousand: "K", million: "M", billion: "B", trillion: "T", quadrillion: "Q" }) + "+"
36+
37+
assert_equal expected, result
38+
39+
mock_with_status.verify
40+
mock_count.verify
41+
end
42+
end
43+
44+
test "jobs_count_for works with different statuses" do
45+
statuses = [ :pending, :finished, :failed, :blocked, :scheduled, :in_progress ]
46+
47+
statuses.each do |status|
48+
mock_with_status = Minitest::Mock.new
49+
mock_count = Minitest::Mock.new
50+
51+
ActiveJob.stub :jobs, mock_with_status do
52+
mock_with_status.expect :with_status, mock_count, [ status ]
53+
mock_count.expect :count, 1000
54+
55+
result = jobs_count_for(status)
56+
assert_equal "1K", result
57+
58+
mock_with_status.verify
59+
mock_count.verify
60+
end
61+
end
62+
end
63+
64+
test "jobs_count_for handles zero count" do
65+
mock_with_status = Minitest::Mock.new
66+
mock_count = Minitest::Mock.new
67+
68+
ActiveJob.stub :jobs, mock_with_status do
69+
mock_with_status.expect :with_status, mock_count, [ :pending ]
70+
mock_count.expect :count, 0
71+
72+
result = jobs_count_for(:pending)
73+
assert_equal "0", result
74+
75+
mock_with_status.verify
76+
mock_count.verify
77+
end
78+
end
79+
80+
test "jobs_count_for handles small numbers without abbreviation" do
81+
mock_with_status = Minitest::Mock.new
82+
mock_count = Minitest::Mock.new
83+
84+
ActiveJob.stub :jobs, mock_with_status do
85+
mock_with_status.expect :with_status, mock_count, [ :pending ]
86+
mock_count.expect :count, 500
87+
88+
result = jobs_count_for(:pending)
89+
assert_equal "500", result
90+
91+
mock_with_status.verify
92+
mock_count.verify
93+
end
94+
end
95+
96+
test "jobs_count_for handles large numbers with proper formatting" do
97+
test_cases = [
98+
[ 1500, "1.5K" ],
99+
[ 2500000, "2.5M" ],
100+
[ 1000000000, "1B" ],
101+
[ 1000000000000, "1T" ],
102+
[ 1000000000000000, "1Q" ]
103+
]
104+
105+
test_cases.each do |count, expected|
106+
mock_with_status = Minitest::Mock.new
107+
mock_count = Minitest::Mock.new
108+
109+
ActiveJob.stub :jobs, mock_with_status do
110+
mock_with_status.expect :with_status, mock_count, [ :finished ]
111+
mock_count.expect :count, count
112+
113+
result = jobs_count_for(:finished)
114+
assert_equal expected, result
115+
116+
mock_with_status.verify
117+
mock_count.verify
118+
end
119+
end
120+
end
121+
end

0 commit comments

Comments
 (0)