Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions internal/ui/snapshot_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ func NewSnapshotEditor(snap *snapshot.Snapshot) SnapshotEditorModel {
}
tabs[3] = editorTab{name: "Taps", icon: "🔌", items: tapItems, itemType: editorItemTap}

prefItems := make([]editorItem, len(snap.MacOSPrefs))
for i, p := range snap.MacOSPrefs {
prefItems[i] = editorItem{
var prefItems []editorItem
for _, p := range snap.MacOSPrefs {
if p.Domain == "" || p.Key == "" {
continue
}
prefItems = append(prefItems, editorItem{
name: fmt.Sprintf("%s.%s", p.Domain, p.Key),
description: fmt.Sprintf("= %s (%s)", p.Value, p.Desc),
selected: true,
itemType: editorItemMacOSPref,
}
})
}
tabs[4] = editorTab{name: "macOS Prefs", icon: "⚙️ ", items: prefItems, itemType: editorItemMacOSPref}

Expand Down
19 changes: 19 additions & 0 deletions internal/ui/snapshot_editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,25 @@ func TestNewSnapshotEditorItems(t *testing.T) {
assert.Equal(t, "homebrew/core", m.tabs[3].items[0].name)
}

func TestNewSnapshotEditorSkipsInvalidMacOSPrefs(t *testing.T) {
snap := makeTestSnapshot()
snap.MacOSPrefs = append(snap.MacOSPrefs,
snapshot.MacOSPref{Domain: "cirruslabs/cli", Key: ""}, // tap misclassified as pref
snapshot.MacOSPref{Domain: "", Key: "SomeKey"}, // empty domain
snapshot.MacOSPref{Domain: "com.apple.dock", Key: "tilesize", Value: "48"}, // valid
)
m := NewSnapshotEditor(snap)

// Only valid prefs (non-empty domain AND key) should appear in the macOS Prefs tab.
prefTab := m.tabs[4]
for _, item := range prefTab.items {
assert.NotEmpty(t, item.name, "pref item name must not be empty")
assert.Contains(t, item.name, ".", "pref item name must contain a dot separator")
}
// 2 from makeTestSnapshot + 1 valid new pref = 3
assert.Equal(t, 3, len(prefTab.items))
}

func TestNewSnapshotEditorAllItemsSelected(t *testing.T) {
snap := makeTestSnapshot()
m := NewSnapshotEditor(snap)
Expand Down
Loading