test: resolve the thin-test item, decline the runner merge

Item 4 of the test-suite review:

- Delete TestEmitWithNoObserversIsNoop (no assertion; ranging a nil slice
  cannot panic) and TestStoreReturnsWiredStore (a getter returning its
  own field).
- Collapse the four TestFilteredJobIndexes* tests into one table-driven
  TestFilteredJobIndexes, matching TestFilterValue above it.
- Replace the TestMainViewBuilds smoke test with
  TestMainViewRecordStartupAddsHistoryRow, which calls the recordStartup
  closure for both wordings run.go selects between and asserts the rows
  reach the History table through its own cell callbacks. Keeps the
  unique coverage the review identified and adds the !windowShown branch.

Item 5 is declined with measurements: the three RunJob tests cost 0.14 s
combined, so merging them saves ~90 ms while forcing their three
fixtures (including the only Manual trigger) into one. The runner
package's runtime is the two timeout tests, not subprocess spawns.

go vet and go test -race pass for src/app and src/ui.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-04 22:46:26 +03:00
parent 2ef18e759c
commit 28f0a0d8e2
6 changed files with 132 additions and 67 deletions
+27 -32
View File
@@ -56,48 +56,43 @@ func TestFolderOptionsAppendsUniqueFolders(t *testing.T) {
}
}
func TestFilteredJobIndexesAll(t *testing.T) {
jobs := []domain.Job{
{Folder: "Maintenance"},
{Folder: ""},
{Folder: "Reports"},
}
got := filteredJobIndexes(jobs, allFolders)
if len(got) != 3 {
t.Errorf("allFolders filter: got %d indexes, want 3", len(got))
}
}
func TestFilteredJobIndexesByNamedFolder(t *testing.T) {
func TestFilteredJobIndexes(t *testing.T) {
jobs := []domain.Job{
{Folder: "Maintenance"}, // index 0
{Folder: ""}, // index 1
{Folder: ""}, // index 1 — no folder
{Folder: "Maintenance"}, // index 2
{Folder: "Reports"}, // index 3
{Folder: " "}, // index 4 — blank reads as no folder
}
got := filteredJobIndexes(jobs, "Maintenance")
if len(got) != 2 || got[0] != 0 || got[1] != 2 {
t.Errorf("Maintenance filter: got %v, want [0 2]", got)
cases := []struct {
name string
jobs []domain.Job
filter string
want []int
}{
{"all folders", jobs, allFolders, []int{0, 1, 2, 3, 4}},
{"named folder", jobs, "Maintenance", []int{0, 2}},
{"no folder", jobs, noFolder, []int{1, 4}},
{"empty job list", nil, allFolders, nil},
}
for _, tc := range cases {
got := filteredJobIndexes(tc.jobs, tc.filter)
if !sameIndexes(got, tc.want) {
t.Errorf("%s: filteredJobIndexes(_, %q) = %v, want %v", tc.name, tc.filter, got, tc.want)
}
}
}
func TestFilteredJobIndexesNoFolder(t *testing.T) {
jobs := []domain.Job{
{Folder: "Maintenance"}, // index 0 — excluded
{Folder: ""}, // index 1 — no folder → included
{Folder: " "}, // index 2 — blank → included
func sameIndexes(got, want []int) bool {
if len(got) != len(want) {
return false
}
got := filteredJobIndexes(jobs, noFolder)
if len(got) != 2 || got[0] != 1 || got[1] != 2 {
t.Errorf("noFolder filter: got %v, want [1 2]", got)
}
}
func TestFilteredJobIndexesEmptySlice(t *testing.T) {
got := filteredJobIndexes(nil, allFolders)
if len(got) != 0 {
t.Errorf("empty job list should return empty indexes, got %v", got)
for i := range got {
if got[i] != want[i] {
return false
}
}
return true
}
func TestNextJobListViewFlipsBothWays(t *testing.T) {
+67 -5
View File
@@ -3,12 +3,16 @@ package ui
import (
"path/filepath"
"testing"
"time"
"gitea.mixdep.ru/mix/gosentry/src/app"
"gitea.mixdep.ru/mix/gosentry/src/domain"
"gitea.mixdep.ru/mix/gosentry/src/storage"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/test"
"fyne.io/fyne/v2/widget"
)
// newTestStore builds a Store rooted in a temp directory. It is separate from
@@ -69,7 +73,35 @@ func TestMainViewFitsTheDefaultWindowSize(t *testing.T) {
}
}
func TestMainViewBuilds(t *testing.T) {
// historyTable returns the History tab's table. It is the only widget.Table the
// main view builds, so the search does not need to know the tab order.
func historyTable(t *testing.T, content fyne.CanvasObject) *widget.Table {
t.Helper()
tabs, ok := content.(*container.AppTabs)
if !ok {
t.Fatal("main view is not the expected AppTabs container")
}
for _, item := range tabs.Items {
found := findFirst(item.Content, func(o fyne.CanvasObject) bool {
_, ok := o.(*widget.Table)
return ok
})
if found != nil {
return found.(*widget.Table)
}
}
t.Fatal("main view has no history table")
return nil
}
// TestMainViewRecordStartupAddsHistoryRow covers the second return value of
// newMainView. run.go calls it once per launch with a different windowShown
// flag depending on whether the app started into the tray, and that call is the
// only thing that puts the startup receipt into History — so both the wording
// and the fact that the table is redrawn are worth pinning. Building the full
// tab set and setting it as the window content is a side benefit: no other test
// assembles all three tabs together.
func TestMainViewRecordStartupAddsHistoryRow(t *testing.T) {
testApp := test.NewApp()
defer testApp.Quit()
@@ -80,9 +112,39 @@ func TestMainViewBuilds(t *testing.T) {
defer svc.Stop()
content, recordStartup := newMainView(w, svc)
if content == nil {
t.Fatal("newMainView returned nil content")
}
w.SetContent(content)
recordStartup(0, true)
table := historyTable(t, content)
if rows, _ := table.Length(); rows != 0 {
t.Fatalf("history rows before startup = %d, want 0", rows)
}
recordStartup(1500*time.Millisecond, true)
recordStartup(20*time.Millisecond, false)
rows, _ := table.Length()
if rows != 2 {
t.Fatalf("history rows after two startup records = %d, want 2", rows)
}
// Read the rows back through the table's own cell callbacks, which is what
// the redraw does; a value only in the events slice would not prove the
// table was refreshed with it.
cell := table.CreateCell()
cellText := func(row, col int) string {
table.UpdateCell(widget.TableCellID{Row: row, Col: col}, cell)
return cell.(*widget.Label).Text
}
if got := cellText(0, 2); got != "Application" {
t.Errorf("startup row job = %q, want %q", got, "Application")
}
if got := cellText(0, 3); got != "Started" {
t.Errorf("startup row state = %q, want %q", got, "Started")
}
if got := cellText(0, 4); got != "Window shown in 1.5s" {
t.Errorf("windowed startup detail = %q, want %q", got, "Window shown in 1.5s")
}
if got := cellText(1, 4); got != "Started in tray in 20ms" {
t.Errorf("tray startup detail = %q, want %q", got, "Started in tray in 20ms")
}
}