Skip to content

Commit 21e4de2

Browse files
committed
Brings coverage back to 100%
1 parent 462e4d8 commit 21e4de2

13 files changed

+438
-97
lines changed

app/controllers/initiatives_controller.rb

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ def update_params
269269
end
270270

271271
def populate_dashboard_data(initiative)
272-
return set_empty_dashboard_data unless initiative
273-
274272
health_update_repo = Rails.application.config.x.health_update_repository
275273

276274
dashboard = InitiativeDashboard.new(
@@ -377,51 +375,6 @@ def build_search_data
377375
end
378376
end
379377

380-
def set_empty_dashboard_data
381-
@health_summary = { on_track: 0, at_risk: 0, off_track: 0 }
382-
@total_active_projects = 0
383-
@attention_required = []
384-
@on_hold_projects = []
385-
@never_updated_projects = []
386-
@stale_projects_14 = []
387-
@stale_projects_7 = []
388-
@teams = []
389-
@initiatives = []
390-
@all_projects = []
391-
@trend_data = []
392-
@trend_direction = :stable
393-
@trend_delta = 0.0
394-
@weeks_of_data = 0
395-
@confidence_score = 0
396-
@confidence_level = :low
397-
@confidence_factors = { biggest_drag: :insufficient_data, details: {} }
398-
399-
# Build empty presenters to avoid nil errors
400-
@header_presenter = InitiativeHeaderPresenter.new(
401-
entity: nil,
402-
view_context: view_context
403-
)
404-
@health_presenter = HealthPresenter.new(
405-
health: :not_available,
406-
methodology: :initiative_rollup
407-
)
408-
@trend_presenter = TrendPresenter.new(
409-
trend_data: [],
410-
trend_direction: :stable,
411-
trend_delta: 0.0,
412-
weeks_of_data: 0
413-
)
414-
@confidence_presenter = ConfidencePresenter.new(
415-
score: 0,
416-
level: :low,
417-
factors: {}
418-
)
419-
@edit_modal_presenter = InitiativeEditModalPresenter.new(
420-
entity: nil,
421-
view_context: view_context
422-
)
423-
end
424-
425378
def team_repository
426379
Rails.application.config.x.team_repository
427380
end

app/controllers/projects_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def build_project_presenters(project)
398398

399399
@health_presenter = HealthPresenter.new(
400400
health: @project_health || project.health,
401-
raw_score: @health_summary&.dig(:raw_score),
401+
raw_score: @health_summary.dig(:raw_score),
402402
off_track_count: off_track_count,
403403
at_risk_count: at_risk_count,
404404
total_count: total_count,
@@ -473,8 +473,6 @@ def health_options
473473
end
474474

475475
def selected_health_for(project)
476-
return health_options.first unless project
477-
478476
health_options.include?(project.health) ? project.health : health_options.first
479477
end
480478
end

app/controllers/teams_controller.rb

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ def update_params
263263
end
264264

265265
def populate_team_dashboard_data(team)
266-
return set_empty_team_dashboard_data unless team
267-
268266
health_update_repo = Rails.application.config.x.health_update_repository
269267

270268
dashboard = TeamDashboard.new(
@@ -371,50 +369,6 @@ def build_search_data
371369
end
372370
end
373371

374-
def set_empty_team_dashboard_data
375-
@health_summary = { on_track: 0, at_risk: 0, off_track: 0 }
376-
@total_active_projects = 0
377-
@attention_required = []
378-
@on_hold_projects = []
379-
@never_updated_projects = []
380-
@stale_projects_14 = []
381-
@stale_projects_7 = []
382-
@teams = []
383-
@initiatives = []
384-
@all_projects = []
385-
@trend_data = []
386-
@trend_direction = :stable
387-
@trend_delta = 0.0
388-
@weeks_of_data = 0
389-
@confidence_score = 0
390-
@confidence_level = :low
391-
392-
# Build empty presenters to avoid nil errors
393-
@header_presenter = TeamHeaderPresenter.new(
394-
entity: nil,
395-
view_context: view_context
396-
)
397-
@health_presenter = HealthPresenter.new(
398-
health: :not_available,
399-
methodology: :team_rollup
400-
)
401-
@trend_presenter = TrendPresenter.new(
402-
trend_data: [],
403-
trend_direction: :stable,
404-
trend_delta: 0.0,
405-
weeks_of_data: 0
406-
)
407-
@confidence_presenter = ConfidencePresenter.new(
408-
score: 0,
409-
level: :low,
410-
factors: {}
411-
)
412-
@edit_modal_presenter = TeamEditModalPresenter.new(
413-
entity: nil,
414-
view_context: view_context
415-
)
416-
end
417-
418372
def team_repository
419373
Rails.application.config.x.team_repository
420374
end

spec/domain/teams/update_team_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@
146146
expect(repository.find('team-123').archived?).to be(true)
147147
end
148148

149+
it 'allows explicitly setting archived status' do
150+
repository = FakeTeamRepository.new
151+
repository.update(id: 'team-123', team: build_team(name: 'Platform', archived: false))
152+
action = described_class.new(team_repository: repository)
153+
154+
action.perform(id: 'team-123', archived: true)
155+
156+
expect(repository.find('team-123').archived?).to be(true)
157+
end
158+
149159
it 'allows setting description to empty string' do
150160
repository = FakeTeamRepository.new
151161
repository.update(id: 'team-123', team: build_team(name: 'Platform', description: 'Old desc'))

spec/helpers/application_helper_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,25 @@
153153
expect(result).to include('breadcrumb__link--home')
154154
expect(result).to include('ParentProject')
155155
end
156+
157+
it 'shows initials for middle crumbs in deep hierarchy' do
158+
great_grandparent_record = TeamRecord.create!(name: 'Engineering Division')
159+
grandparent_record = TeamRecord.create!(name: 'Platform Team')
160+
parent_record = TeamRecord.create!(name: 'Mobile Team')
161+
162+
great_grandparent = double('Team', name: 'Engineering Division', parent_team: nil, id: great_grandparent_record.id.to_s)
163+
grandparent = double('Team', name: 'Platform Team', parent_team: great_grandparent, id: grandparent_record.id.to_s)
164+
parent = double('Team', name: 'Mobile Team', parent_team: grandparent, id: parent_record.id.to_s)
165+
child = double('Team', name: 'iOS Team', parent_team: parent)
166+
167+
result = helper.team_breadcrumb(child)
168+
169+
expect(result).to include('breadcrumb__link--home')
170+
expect(result).to include('ED…')
171+
expect(result).to include('title="Engineering Division"')
172+
expect(result).to include('PT…')
173+
expect(result).to include('title="Platform Team"')
174+
expect(result).to include('Mobile Team')
175+
end
156176
end
157177
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe InitiativeEditModalPresenter do
4+
let(:view_context) { double('view_context', initiative_path: '/initiatives/1') }
5+
6+
describe 'with nil entity' do
7+
subject(:presenter) { described_class.new(entity: nil, view_context: view_context) }
8+
9+
it 'returns empty string for name' do
10+
expect(presenter.name).to eq('')
11+
end
12+
13+
it 'returns empty string for description' do
14+
expect(presenter.description).to eq('')
15+
end
16+
17+
it 'returns empty string for point_of_contact' do
18+
expect(presenter.point_of_contact).to eq('')
19+
end
20+
21+
it 'returns false for archived?' do
22+
expect(presenter.archived?).to be false
23+
end
24+
25+
it 'returns nil for update_path' do
26+
expect(presenter.update_path).to be_nil
27+
end
28+
end
29+
30+
describe 'with valid entity' do
31+
let(:entity) do
32+
double('Initiative',
33+
name: 'Q1 Launch',
34+
description: 'Launch new product',
35+
point_of_contact: 'pm@example.com',
36+
archived?: true,
37+
id: '1'
38+
)
39+
end
40+
subject(:presenter) { described_class.new(entity: entity, view_context: view_context) }
41+
42+
it 'returns entity name' do
43+
expect(presenter.name).to eq('Q1 Launch')
44+
end
45+
46+
it 'returns entity description' do
47+
expect(presenter.description).to eq('Launch new product')
48+
end
49+
50+
it 'returns entity point_of_contact' do
51+
expect(presenter.point_of_contact).to eq('pm@example.com')
52+
end
53+
54+
it 'returns entity archived?' do
55+
expect(presenter.archived?).to be true
56+
end
57+
end
58+
end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe InitiativeHeaderPresenter do
4+
let(:view_context) { double('view_context', state_initiative_path: '/initiatives/1/state', initiative_breadcrumb: '<nav>breadcrumb</nav>') }
5+
6+
describe 'with nil entity' do
7+
subject(:presenter) { described_class.new(entity: nil, view_context: view_context) }
8+
9+
it 'returns default name' do
10+
expect(presenter.name).to eq('Initiative')
11+
end
12+
13+
it 'returns nil description' do
14+
expect(presenter.description).to be_nil
15+
end
16+
17+
it 'returns nil point_of_contact' do
18+
expect(presenter.point_of_contact).to be_nil
19+
end
20+
21+
it 'returns false for archived?' do
22+
expect(presenter.archived?).to be false
23+
end
24+
25+
it 'returns nil current_state' do
26+
expect(presenter.current_state).to be_nil
27+
end
28+
29+
it 'returns nil state_path' do
30+
expect(presenter.state_path).to be_nil
31+
end
32+
33+
it 'returns empty breadcrumb' do
34+
expect(presenter.breadcrumb).to eq([])
35+
end
36+
end
37+
38+
describe 'with valid entity' do
39+
let(:entity) do
40+
double('Initiative',
41+
name: 'Q1 Launch',
42+
description: 'Launch new product',
43+
point_of_contact: 'pm@example.com',
44+
archived?: false,
45+
current_state: :in_progress,
46+
id: '1'
47+
)
48+
end
49+
subject(:presenter) { described_class.new(entity: entity, view_context: view_context) }
50+
51+
it 'returns entity name' do
52+
expect(presenter.name).to eq('Q1 Launch')
53+
end
54+
55+
it 'returns entity description' do
56+
expect(presenter.description).to eq('Launch new product')
57+
end
58+
59+
it 'returns entity point_of_contact' do
60+
expect(presenter.point_of_contact).to eq('pm@example.com')
61+
end
62+
63+
it 'returns entity archived?' do
64+
expect(presenter.archived?).to be false
65+
end
66+
67+
it 'returns entity current_state' do
68+
expect(presenter.current_state).to eq(:in_progress)
69+
end
70+
71+
it 'returns state_path' do
72+
expect(presenter.state_path).to eq('/initiatives/1/state')
73+
end
74+
75+
it 'returns breadcrumb' do
76+
expect(presenter.breadcrumb).to eq('<nav>breadcrumb</nav>')
77+
end
78+
end
79+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe TeamEditModalPresenter do
4+
let(:view_context) { double('view_context', team_path: '/teams/1') }
5+
6+
describe 'with nil entity' do
7+
subject(:presenter) { described_class.new(entity: nil, view_context: view_context) }
8+
9+
it 'returns empty string for name' do
10+
expect(presenter.name).to eq('')
11+
end
12+
13+
it 'returns empty string for description' do
14+
expect(presenter.description).to eq('')
15+
end
16+
17+
it 'returns empty string for point_of_contact' do
18+
expect(presenter.point_of_contact).to eq('')
19+
end
20+
21+
it 'returns false for archived?' do
22+
expect(presenter.archived?).to be false
23+
end
24+
25+
it 'returns nil for update_path' do
26+
expect(presenter.update_path).to be_nil
27+
end
28+
end
29+
30+
describe 'with valid entity' do
31+
let(:entity) do
32+
double('Team',
33+
name: 'Platform',
34+
description: 'Platform team',
35+
point_of_contact: 'platform@example.com',
36+
archived?: true,
37+
id: '1'
38+
)
39+
end
40+
subject(:presenter) { described_class.new(entity: entity, view_context: view_context) }
41+
42+
it 'returns entity name' do
43+
expect(presenter.name).to eq('Platform')
44+
end
45+
46+
it 'returns entity description' do
47+
expect(presenter.description).to eq('Platform team')
48+
end
49+
50+
it 'returns entity point_of_contact' do
51+
expect(presenter.point_of_contact).to eq('platform@example.com')
52+
end
53+
54+
it 'returns entity archived?' do
55+
expect(presenter.archived?).to be true
56+
end
57+
end
58+
end

0 commit comments

Comments
 (0)