Skip to content

Commit d303ddd

Browse files
cpcloudcursoragent
andcommitted
chore(tests): consolidate redundant tests into table-driven patterns
Combine similar test functions into table-driven tests and remove trivially redundant tests across 6 files. Net reduction of ~120 lines while preserving all meaningful coverage. Closes #138 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4d9d5f6 commit d303ddd

File tree

6 files changed

+270
-341
lines changed

6 files changed

+270
-341
lines changed

internal/app/dashboard_rows_test.go

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,36 +171,45 @@ func TestDashExpiringRowsEmpty(t *testing.T) {
171171
// overhead
172172
// ---------------------------------------------------------------------------
173173

174-
func TestOverheadSingleSection(t *testing.T) {
175-
s := dashSection{title: "Projects", rows: make([]dashRow, 3)}
176-
assert.Equal(t, 1, s.overhead())
177-
}
178-
179-
func TestOverheadSubSections(t *testing.T) {
180-
s := dashSection{
181-
title: "Maintenance",
182-
subTitles: []string{"Overdue", "Upcoming"},
183-
subCounts: []int{3, 2},
184-
}
185-
// 2 sub-headers + 1 blank separator = 3
186-
assert.Equal(t, 3, s.overhead())
187-
}
188-
189-
func TestOverheadSubSectionsOneEmpty(t *testing.T) {
190-
s := dashSection{
191-
title: "Maintenance",
192-
subTitles: []string{"Overdue", "Upcoming"},
193-
subCounts: []int{3, 0},
174+
func TestOverhead(t *testing.T) {
175+
tests := []struct {
176+
name string
177+
s dashSection
178+
want int
179+
}{
180+
{
181+
"single section",
182+
dashSection{title: "Projects", rows: make([]dashRow, 3)},
183+
1,
184+
},
185+
{
186+
"two non-empty sub-sections",
187+
dashSection{
188+
title: "Maintenance", subTitles: []string{"Overdue", "Upcoming"},
189+
subCounts: []int{3, 2},
190+
},
191+
3, // 2 sub-headers + 1 blank separator
192+
},
193+
{
194+
"one empty sub-section",
195+
dashSection{
196+
title: "Maintenance", subTitles: []string{"Overdue", "Upcoming"},
197+
subCounts: []int{3, 0},
198+
},
199+
1,
200+
},
201+
{
202+
"all sub-sections empty",
203+
dashSection{
204+
title: "Maintenance", subTitles: []string{"Overdue", "Upcoming"},
205+
subCounts: []int{0, 0},
206+
},
207+
1,
208+
},
194209
}
195-
// Only 1 non-empty sub-section -> overhead = 1.
196-
assert.Equal(t, 1, s.overhead())
197-
}
198-
199-
func TestOverheadAllSubSectionsEmpty(t *testing.T) {
200-
s := dashSection{
201-
title: "Maintenance",
202-
subTitles: []string{"Overdue", "Upcoming"},
203-
subCounts: []int{0, 0},
210+
for _, tt := range tests {
211+
t.Run(tt.name, func(t *testing.T) {
212+
assert.Equal(t, tt.want, tt.s.overhead())
213+
})
204214
}
205-
assert.Equal(t, 1, s.overhead())
206215
}

internal/app/dashboard_test.go

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,15 @@ func TestDashboardToggle(t *testing.T) {
8585
assert.False(t, m.showDashboard)
8686
}
8787

88-
func TestDashboardDismissedByForward(t *testing.T) {
89-
m := newTestModel()
90-
m.showDashboard = true
91-
92-
sendKey(m, "f")
93-
assert.False(t, m.showDashboard)
94-
}
95-
96-
func TestDashboardDismissedByBack(t *testing.T) {
97-
m := newTestModel()
98-
m.showDashboard = true
99-
100-
sendKey(m, "b")
101-
assert.False(t, m.showDashboard)
88+
func TestDashboardDismissedByTabSwitch(t *testing.T) {
89+
for _, key := range []string{"f", "b"} {
90+
t.Run(key, func(t *testing.T) {
91+
m := newTestModel()
92+
m.showDashboard = true
93+
sendKey(m, key)
94+
assert.False(t, m.showDashboard)
95+
})
96+
}
10297
}
10398

10499
func TestDashboardNavigation(t *testing.T) {
@@ -293,18 +288,6 @@ func TestDashboardOverlay(t *testing.T) {
293288
assert.Contains(t, ov, "help")
294289
}
295290

296-
func TestDashboardOverlayComposite(t *testing.T) {
297-
m := newTestModel()
298-
m.width = 120
299-
m.height = 40
300-
m.showDashboard = true
301-
m.dashboard = dashboardData{}
302-
m.dashNav = nil
303-
304-
view := m.buildView()
305-
assert.NotEmpty(t, view)
306-
}
307-
308291
func TestDashboardOverlayFitsHeight(t *testing.T) {
309292
m := newTestModel()
310293
m.width = 80
@@ -743,12 +726,3 @@ func TestOverlayContentWidth(t *testing.T) {
743726
})
744727
}
745728
}
746-
747-
func TestDashboardDefaultOnLaunchWithHouse(t *testing.T) {
748-
m := newTestModel()
749-
m.hasHouse = true
750-
m.house = data.HouseProfile{Nickname: "Test"}
751-
m.showDashboard = true
752-
753-
assert.True(t, m.showDashboard)
754-
}

internal/app/detail_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,6 @@ func TestMaintenanceLogColumnReplacedManual(t *testing.T) {
216216
}
217217
}
218218

219-
func TestNewTestModelDetailNil(t *testing.T) {
220-
m := newTestModel()
221-
assert.Nil(t, m.detail())
222-
}
223-
224219
func TestResizeTablesIncludesDetail(t *testing.T) {
225220
m := newTestModel()
226221
m.width = 120
@@ -321,13 +316,6 @@ func TestApplianceMaintenanceColumnSpecsNoAppliance(t *testing.T) {
321316
assert.Equal(t, cellDrilldown, last.Kind)
322317
}
323318

324-
func TestApplianceMaintColumnIsDrilldown(t *testing.T) {
325-
specs := applianceColumnSpecs()
326-
last := specs[len(specs)-1]
327-
assert.Equal(t, "Maint", last.Title)
328-
assert.Equal(t, cellDrilldown, last.Kind)
329-
}
330-
331319
// ---------------------------------------------------------------------------
332320
// Drilldown stack tests
333321
// ---------------------------------------------------------------------------
@@ -514,23 +502,6 @@ func TestProjectColumnSpecsIncludeQuotes(t *testing.T) {
514502
assert.Equal(t, cellDrilldown, last.Kind)
515503
}
516504

517-
func TestVendorColumnsAreDrilldown(t *testing.T) {
518-
specs := vendorColumnSpecs()
519-
quotes := specs[6]
520-
jobs := specs[7]
521-
assert.Equal(t, "Quotes", quotes.Title)
522-
assert.Equal(t, cellDrilldown, quotes.Kind)
523-
assert.Equal(t, "Jobs", jobs.Title)
524-
assert.Equal(t, cellDrilldown, jobs.Kind)
525-
}
526-
527-
func TestApplianceMaintLogColumnIsDrilldown(t *testing.T) {
528-
specs := applianceMaintenanceColumnSpecs()
529-
last := specs[len(specs)-1]
530-
assert.Equal(t, "Log", last.Title)
531-
assert.Equal(t, cellDrilldown, last.Kind)
532-
}
533-
534505
// ---------------------------------------------------------------------------
535506
// openDetailForRow dispatch tests
536507
// ---------------------------------------------------------------------------

internal/app/handler_crud_test.go

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -563,46 +563,25 @@ func TestMaintenanceHandlerSyncFixedValues(t *testing.T) {
563563
// Handler with non-existent IDs
564564
// ---------------------------------------------------------------------------
565565

566-
func TestProjectHandlerSnapshotNonExistent(t *testing.T) {
566+
func TestHandlerSnapshotNonExistent(t *testing.T) {
567567
m := newTestModelWithStore(t)
568-
h := projectHandler{}
569-
_, ok := h.Snapshot(m.store, 99999)
570-
assert.False(t, ok)
571-
}
572-
573-
func TestQuoteHandlerSnapshotNonExistent(t *testing.T) {
574-
m := newTestModelWithStore(t)
575-
h := quoteHandler{}
576-
_, ok := h.Snapshot(m.store, 99999)
577-
assert.False(t, ok)
578-
}
579-
580-
func TestMaintenanceHandlerSnapshotNonExistent(t *testing.T) {
581-
m := newTestModelWithStore(t)
582-
h := maintenanceHandler{}
583-
_, ok := h.Snapshot(m.store, 99999)
584-
assert.False(t, ok)
585-
}
586-
587-
func TestApplianceHandlerSnapshotNonExistent(t *testing.T) {
588-
m := newTestModelWithStore(t)
589-
h := applianceHandler{}
590-
_, ok := h.Snapshot(m.store, 99999)
591-
assert.False(t, ok)
592-
}
593-
594-
func TestVendorHandlerSnapshotNonExistent(t *testing.T) {
595-
m := newTestModelWithStore(t)
596-
h := vendorHandler{}
597-
_, ok := h.Snapshot(m.store, 99999)
598-
assert.False(t, ok)
599-
}
600-
601-
func TestServiceLogHandlerSnapshotNonExistent(t *testing.T) {
602-
m := newTestModelWithStore(t)
603-
h := serviceLogHandler{maintenanceItemID: 1}
604-
_, ok := h.Snapshot(m.store, 99999)
605-
assert.False(t, ok)
568+
handlers := []struct {
569+
name string
570+
h TabHandler
571+
}{
572+
{"project", projectHandler{}},
573+
{"quote", quoteHandler{}},
574+
{"maintenance", maintenanceHandler{}},
575+
{"appliance", applianceHandler{}},
576+
{"vendor", vendorHandler{}},
577+
{"serviceLog", serviceLogHandler{maintenanceItemID: 1}},
578+
}
579+
for _, tc := range handlers {
580+
t.Run(tc.name, func(t *testing.T) {
581+
_, ok := tc.h.Snapshot(m.store, 99999)
582+
assert.False(t, ok)
583+
})
584+
}
606585
}
607586

608587
// ---------------------------------------------------------------------------

internal/app/handlers_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,11 @@ func TestHandlerForFormKind(t *testing.T) {
4242
}
4343
}
4444

45-
func TestHandlerForFormKindHouseReturnsNil(t *testing.T) {
45+
func TestHandlerForFormKindReturnsNilForNonTabKinds(t *testing.T) {
4646
m := newTestModel()
47-
assert.Nil(t, m.handlerForFormKind(formHouse))
48-
}
49-
50-
func TestHandlerForFormKindUnknownReturnsNil(t *testing.T) {
51-
m := newTestModel()
52-
assert.Nil(t, m.handlerForFormKind(formNone))
47+
for _, kind := range []FormKind{formHouse, formNone} {
48+
assert.Nilf(t, m.handlerForFormKind(kind), "expected nil handler for %v", kind)
49+
}
5350
}
5451

5552
func TestHandlerFormKindMatchesTabKind(t *testing.T) {

0 commit comments

Comments
 (0)