1package component
2
3import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7)
8
9func TestOmniboxFavoriteStarVisibility(t *testing.T) {
10 assert.True(t, shouldShowFavoriteStar(Suggestion{IsFavorite: true}))
11 assert.False(t, shouldShowFavoriteStar(Suggestion{IsFavorite: false}))
12}
13
14func TestShouldApplyEmptyResultsState(t *testing.T) {
15 tests := []struct {
16 name string
17 rowCount int
18 visible bool
19 want bool
20 }{
21 {name: "negative rows uses empty state", rowCount: -1, visible: false, want: true},
22 {name: "zero rows uses empty state", rowCount: 0, visible: false, want: true},
23 {name: "positive rows clears empty state", rowCount: 2, visible: true, want: false},
24 }
25
26 for _, tt := range tests {
27 t.Run(tt.name, func(t *testing.T) {
28 assert.Equal(t, tt.want, shouldApplyEmptyResultsState(tt.rowCount, tt.visible))
29 })
30 }
31}
32
33func TestResolveFavoriteRowIndicatorUpdate(t *testing.T) {
34 tests := []struct {
35 name string
36 mode ViewMode
37 index int
38 expectedURL string
39 suggestions []Suggestion
40 isFavorite bool
41 want favoriteRowIndicatorUpdate
42 }{
43 {
44 name: "matching history row keeps update and shows star",
45 mode: ViewModeHistory,
46 index: 0,
47 expectedURL: "https://example.com",
48 suggestions: []Suggestion{{URL: "https://example.com"}},
49 isFavorite: true,
50 want: favoriteRowIndicatorUpdate{Apply: true, ShowStarSlot: true},
51 },
52 {
53 name: "matching history row keeps update and hides star when removed",
54 mode: ViewModeHistory,
55 index: 0,
56 expectedURL: "https://example.com",
57 suggestions: []Suggestion{{URL: "https://example.com"}},
58 isFavorite: false,
59 want: favoriteRowIndicatorUpdate{Apply: true, ShowStarSlot: false},
60 },
61 {
62 name: "mismatched URL skips stale row update",
63 mode: ViewModeHistory,
64 index: 0,
65 expectedURL: "https://expected.example.com",
66 suggestions: []Suggestion{{URL: "https://current.example.com"}},
67 isFavorite: true,
68 want: favoriteRowIndicatorUpdate{},
69 },
70 {
71 name: "favorites mode never applies history row update",
72 mode: ViewModeFavorites,
73 index: 0,
74 expectedURL: "https://example.com",
75 suggestions: []Suggestion{{URL: "https://example.com"}},
76 isFavorite: true,
77 want: favoriteRowIndicatorUpdate{},
78 },
79 {
80 name: "out of range index skips update",
81 mode: ViewModeHistory,
82 index: 1,
83 expectedURL: "https://example.com",
84 suggestions: []Suggestion{{URL: "https://example.com"}},
85 isFavorite: true,
86 want: favoriteRowIndicatorUpdate{},
87 },
88 }
89
90 for _, tt := range tests {
91 t.Run(tt.name, func(t *testing.T) {
92 got := resolveFavoriteRowIndicatorUpdate(tt.mode, tt.index, tt.expectedURL, tt.suggestions, tt.isFavorite)
93 assert.Equal(t, tt.want, got)
94 })
95 }
96}